liveBook · Manning

QuantumCircuit

As explained in Quantum Programming in Depth

QuantumCircuit is a Qiskit class representing a quantum circuit and exposing operations for constructing or executing it.

QuantumCircuit is Qiskit's Python representation of a quantum circuit: a sequence of gates and measurements applied to a defined collection of qubits and classical bits. Initialize it with qubit and optional classical-bit counts, then append operations through methods such as ry, append, and measure. section 2.1.2 section 4.1.2

Use QuantumCircuit to:

  • Prepare a single-qubit state by computing a rotation angle and applying circ.ry(theta, 0). section 2.1.2
  • Save and inspect a simulated statevector with save_statevector, AerSimulator, run, and get_statevector. section 2.2.1
  • Package reusable circuit logic as custom gates with to_gate, then append controlled or controlled-on-zero variants. section 2.3.3
  • Add measurements, execute repeated shots, and retrieve aggregated bitstring counts with get_counts. section 4.1.2

Preparing and checking a state

For alpha = 0.6 and beta = 0.8, create QuantumCircuit(1), apply ry(2 * atan2(beta, alpha), 0), save the statevector, and run it on AerSimulator(method='statevector'). The resulting vector is [0.6, 0.8]. For measurement-oriented circuits, allocate matching classical bits, measure corresponding qubits, run 100 shots, and inspect the returned counts. section 2.1.2 section 2.2.1 section 4.1.2

Listing 2.1 Qiskit code to prepare a single-qubit state
from math import atan2
from qiskit import QuantumCircuit

alpha, beta = 0.6, 0.8

circ = QuantumCircuit(1)     #1
theta = 2 * atan2(beta, alpha)   #2
circ.ry(theta, 0)            #3

Inspect the compact Qiskit listing that constructs a one-qubit QuantumCircuit and applies the calculated rotation. section 2.1.2

How Quantum Programming in Depth covers it

How deep it goes
Descends from initialization and gate calls to custom controlled gates, simulation, transpilation, measurement, and validation tests.
Examples
Demonstrates single- and two-qubit state preparation, controlled gates, statevector inspection, measurement counts, and randomized readout validation.
What it assumes
Assumes Python project basics and brief familiarity with qubits, gates, measurements, and quantum-state notation.
What you can do after
Build it from scratch by constructing, simulating, transpiling, measuring, inspecting, and testing Qiskit circuits.
How it connects
Connects quantum gates, qubits, classical bits, measurements, statevectors, simulators, transpilation, and custom gates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.