Skip to Content
Qiskit Pocket Guide
book

Qiskit Pocket Guide

by James L. Weaver, Frank J. Harkins
June 2022
Intermediate to advanced content levelIntermediate to advanced
218 pages
4h 4m
English
O'Reilly Media, Inc.
Content preview from Qiskit Pocket Guide

Chapter 1. Quantum Circuits and Operations

In Qiskit, quantum programs are normally expressed with quantum circuits that contain quantum operations. Quantum circuits are represented by the QuantumCircuit class, and quantum operations are represented by subclasses of the class Instruction.

Constructing Quantum Circuits

A quantum circuit may be created by supplying an argument that indicates the number of desired quantum wires (qubits) for that circuit. This is often supplied as an integer:

from qiskit import QuantumCircuit
QuantumCircuit(2)

Optionally, the number of desired classical wires (bits) may also be specified. The first argument refers to the number of quantum wires, and the second argument the number of classical wires:

QuantumCircuit(2, 2)

The number of desired quantum and classical wires may also be expressed by supplying instances of QuantumRegister and ClassicalRegister as arguments to QuantumCircuit. These classes are addressed in “Using the QuantumRegister Class” and “Using the ClassicalRegister Class”.

Using the QuantumCircuit Class

The QuantumCircuit class contains a large number of methods and attributes. The purpose of many of its methods is to apply quantum operations to a quantum circuit. Most of its other methods and attributes either manipulate or report information about a quantum circuit.

Commonly used gates

Table 1-1 contains some commonly used single-qubit gates and code examples. The variable qc refers to an instance of QuantumCircuit that contains ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Design of Everyday Things

The Design of Everyday Things

Donald A. Norman
The Kaggle Book

The Kaggle Book

Konrad Banachewicz, Luca Massaron
Storytelling with You

Storytelling with You

Cole Nussbaumer Knaflic
The Goal

The Goal

Eliyahu M. Goldratt, Jeff Cox

Publisher Resources

ISBN: 9781098112462Errata PageSupplemental Content