Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Qiskit reference semantics

A reference description of Qiskit circuit objects and the distinction between mathematical state analysis and execution results.

Also called Qiskit

Edition released Coverage: Overview · Technical
On this page

Definition and significance

Qiskit is a quantum software ecosystem whose circuit abstractions describe operations on labeled quantum and classical registers. An encyclopedia entry should explain stable concepts first and identify exact software versions for executable examples. Current APIs and result containers evolve; no untested version is claimed here.

A circuit object is a program description. A statevector calculation, a finite-shot local sampler and a remote hardware result have different meanings and uncertainty. The website should show fully explained reference examples without asking readers to execute them.

Mechanism and mathematical treatment

In a conventional Qiskit circuit, qc.h(0) applies H to qubit zero and qc.cx(0,1) uses zero as control and one as target. Statevector indices conventionally treat qubit zero as the least significant bit. Thus the state created by qc.x(0) on two zero qubits is indexed as |01> in q1q0 string order.

A conceptual reference fragment is: from qiskit import QuantumCircuit; qc=QuantumCircuit(2); qc.h(0); qc.cx(0,1). It describes Bell preparation. Any actual published code should be formatted as separate statements, pinned to a verified SDK version and accompanied by its predicted ideal output.

Fully worked reference example

The Bell fragment prepares amplitudes [1/sqrt(2),0,0,1/sqrt(2)] in the usual two-qubit statevector ordering. Computational measurement has probabilities 1/2 for 00 and 11. With N independent ideal shots, the count of 00 is binomial with mean N/2 and standard deviation sqrt(N)/2; it is not guaranteed to be exactly N/2.

For N=1024, the expected count is 512 and standard deviation is 16. A displayed result such as 505 and 519 is a possible sample, not a change in the ideal state. No random sample is asserted to have been executed for this manual.

Limitations and common misconceptions

Avoid copying a documentation example's output as a newly measured result. Classical-register naming and result-container endianness must be checked against the pinned version. Exact amplitudes from simulation are not directly accessible from hardware in one run.

Scientific relationships

Statevector indices and displayed strings require explicit mapping.

An asymmetric parameterized reference contract

Consider the conceptual circuit: prepare two zero qubits; apply R_Y(theta) to q0; apply CNOT q0->q1; apply R_Z(phi) to q1; apply X to q1. Before any measurement, its encyclopedia-order state is cos(theta/2)exp(-i phi/2)|01>+sin(theta/2)exp(i phi/2)|10>. The asymmetry makes this a better ordering reference than a Bell state.

At theta=pi/3 and phi=pi/2, the amplitudes are sqrt(3)exp(-i pi/4)/2 on physical label q0q1=01 and exp(i pi/4)/2 on 10. The probabilities are 3/4 and 1/4. In a conventional Qiskit statevector array using q0 as the least significant factor, these occupy indices 2 and 1, respectively. The array is therefore [0,exp(i pi/4)/2,sqrt(3)exp(-i pi/4)/2,0].

The complete NumPy reference below binds the parameters, constructs the gate matrices, and verifies the predicted amplitudes and observables. Its execution contract is Python 3.12.16 with NumPy 2.3.5. The official ordering documentation supplies the conventional index interpretation; the executed array calculation independently checks that interpretation without invoking a quantum SDK.

Observables must follow the same basis convention

For the reference state, <Z_q0>=cos(theta) and <Z_q1>=-cos(theta). At the chosen angle they are +1/2 and -1/2. In encyclopedia order, Z_q0 has diagonal [1,1,-1,-1]. In the conventional least-significant-q0 array order it has diagonal [1,-1,1,-1]. Applying the first diagonal to the second array would return the other qubit's expectation and reverse the sign.

The joint ZZ expectation is -1 for every theta and phi because the state has exactly one excitation. That invariant is useful but cannot expose the single-qubit ordering error: ZZ is symmetric under exchange. A sound reference includes both the invariant joint observable and an asymmetric local observable. The phase phi can be checked through an appropriate off-diagonal correlation rather than through computational probabilities alone.

Direct calculation gives <X0X1>=sin(theta)cos(phi) and <X0Y1>=-sin(theta)sin(phi) for this state, with the stated qubit order. At phi=pi/2, these are zero and -sqrt(3)/2. The sign of the second correlation is another sensitive check of the order of R_Z and X and of the Y-measurement convention.

Binding, sampling and result interpretation

A parameterized circuit represents a family of states until every required parameter has a value. Parameter names and positional array order should not be treated as interchangeable without an explicit binding map. For this two-parameter example, a map assigning theta=pi/3 and phi=pi/2 is unambiguous. Swapping those values changes both populations and correlations, even if the program remains syntactically valid.

With measurements q0->c0 and q1->c1, a conventional c1c0 string representation yields 10 with probability 3/4 and 01 with probability 1/4. If 1000 independent ideal shots were taken, the expected count of 10 would be 750 and its standard deviation would be sqrt(1000 times 3/4 times 1/4), approximately 13.693. These are predicted sampling statistics; no particular observed count is fabricated.

Current result containers can have their own ordering controls and field structure. The meaning of a returned array or count dictionary should be established from that specific interface, not inferred solely from the statevector convention. The official documentation accessed for this extension explicitly distinguishes several object-level conventions. This is why a reproducible example should identify the actual result object and its decoding contract.

Reproducibility without an untested execution claim

The reference program records the complete circuit construction, parameter bindings, tensor order, observable matrices, and array permutation. Its deterministic calculation uses no sampling seed, shots, transpilation, device layout, or remote backend. The resulting probabilities and expectations are locally verified mathematical outputs. A finite-shot or physical execution is a different experiment and requires its own configuration and observed data.

An ideal statevector evaluator can return all four amplitudes directly. A sampler returns finite measurement data, and a hardware run additionally includes device behavior. They answer different questions. A remote job identifier or a copied documentation output would not substitute for a verified run of this original circuit. Conversely, the absence of an SDK run does not weaken the exact gate-matrix derivation, which can be checked with ordinary linear algebra.

Executed reference: asymmetric state and array ordering

The complete program below computes the circuit using complex double-precision arrays. The first probability row is [0, 0.75, 0.25, 0] in encyclopedia order q0,q1. Reshaping, transposing the two tensor indices, and flattening gives [0, 0.25, 0.75, 0] in the conventional array order where q0 is least significant. This permutation changes the representation, not the physical state. The printed observable row is [0.5, -0.5, -1, 0, -0.86602540] for Z0, Z1, ZZ, XX, XY. It detects the phase and qubit-label errors that a symmetric Bell-state example can hide.

The controlled-X matrix exchanges the final two coordinates, so its left tensor factor is the control. Matrix products act on the state from right to left. The permutation is applied only after the physical calculation; observable matrices must be permuted as well if subsequent calculations use the reordered vector. The assertions check both representations against exact probabilities. This code was executed with Python 3.12.16 and NumPy 2.3.5. It is a usable independent reference for Qiskit ordering semantics, with no Qiskit installation or backend execution asserted.

python · Python 3.12.16; NumPy 2.3.5 · Executed locally as an ideal mathematical reference; no quantum SDK or device used.

import numpy as np
np.set_printoptions(precision=8, suppress=True)
I = np.eye(2, dtype=complex)
X = np.array([[0, 1], [1, 0]], dtype=complex)
Y = np.array([[0, -1j], [1j, 0]], dtype=complex)
Z = np.diag([1, -1])
def rotation(P, angle):
    return np.cos(angle / 2) * I - 1j * np.sin(angle / 2) * P
CX = np.array([[1, 0, 0, 0], [0, 1, 0, 0],
               [0, 0, 0, 1], [0, 0, 1, 0]], dtype=complex)
state = np.array([1, 0, 0, 0], dtype=complex)
state = np.kron(rotation(Y, np.pi / 3), I) @ state
state = CX @ state
state = np.kron(I, rotation(Z, np.pi / 2)) @ state
state = np.kron(I, X) @ state
reordered = state.reshape(2, 2).T.reshape(4)
operators = [np.kron(Z, I), np.kron(I, Z), np.kron(Z, Z),
             np.kron(X, X), np.kron(X, Y)]
means = np.array([np.vdot(state, op @ state).real for op in operators])
print(np.abs(state) ** 2)
print(np.abs(reordered) ** 2)
print(means)
assert np.allclose(np.abs(state) ** 2, [0, .75, .25, 0])
assert np.allclose(np.abs(reordered) ** 2, [0, .25, .75, 0])
assert np.allclose(means, [.5, -.5, -1, 0, -np.sqrt(3) / 2])

Sources

  • IBM Quantum · Documentation · quantum.cloud.ibm.com
    Verification scope

    Recorded source check ·

    Full ordering guide retrieved; statevector/integer/string conventions and explicit object-level result distinctions inspected.

    Conceptual reference semantics only. No code execution or universal backend support claim.