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
