Qiskit is a Python library for constructing quantum circuits: fixed collections of qubits, gates, and optional classical bits for measurements. A circuit is a QuantumCircuit instance, and built-in gate methods such as ry, x, h, z, cx, and measure append operations to it. Qiskit code lives in ordinary Python projects and can be run as Python scripts. section 1.5 section 2.1.2
A typical workflow builds a circuit, runs it on a backend, and analyzes the returned data in Python. AerSimulator can expose a saved statevector for amplitude-level inspection; measured runs instead return shot counts keyed by classical bit strings. Classical post-processing happens after circuit execution rather than as arbitrary decision-making inside the circuit. section 2.2.1 section 4.1.2 section 5.1.2
Compose and inspect circuits by:
- Allocating qubits and classical bits up front, then appending gates or reusable subcircuits to specified qubit indices. section 2.1.2 section 6.5.2
- Turning circuits into gates, controlling them, taking inverses, and raising them to powers to assemble larger operations. section 2.5.2 section 7.2.3
- Transpiling for a simulator, executing repeated shots, and checking statevectors, matrices, counts, or classical outputs. section 2.4.1 section 3.5.3 section 7.2.3
Prepare and verify a one-qubit state
For amplitudes 0.6 and 0.8, compute theta as 2 * atan2(beta, alpha), create QuantumCircuit(1), and apply ry(theta, 0). Saving and retrieving the simulator statevector yields amplitudes for |0⟩ and |1⟩, which can be compared with the intended values in a Python test. section 2.1.2 section 2.2.1 section 2.4.1
Qiskit supports implementations ranging from state preparation and unitary construction to measurement, reversible Boolean evaluation, phase estimation, and Grover search. Circuit layout matters: qubit order affects displayed states, matrix indices, measurements, and how subcircuits are appended. Auxiliary qubits remain part of the full circuit, even when later reused. section 6.2.2 section 7.1.2 section 7.2.3
Listing 7.3 Qiskit code for Grover’s search algorithm
def grovers_search(n_bits, marking_oracle, prepare_mean, n_iterations):
iter = QuantumCircuit(n_bits + 1) #1
phase_or = phase_oracle(n_bits, marking_oracle) #2
iter.append(phase_or, range(n_bits + 1)) #3
iter.append(prepare_mean.inverse(), range(n_bits))
iter.x(range(n_bits))
iter.append(ZGate().control(n_bits - 1),
range(n_bits))
iter.x(range(n_bits))
iter.append(prepare_mean, range(n_bits)) #4
circ = QuantumCircuit(n_bits + 1, n_bits) #5
circ.append(prepare_mean, range(n_bits)) #6
circ.append(iter.to_gate().power(n_iterations), #7
range(n_bits + 1))
circ.measure(range(n_bits), range(n_bits)) #8
return circ
Inspect a complete hand-built Grover circuit that combines a marking oracle, phase kickback, reflection about the mean, repeated iterations, and final measurement. section 7.2.3

