CUDA-Q reference semantics
A programming environment for expressing quantum kernels and connecting them to classical computation and execution targets.
Also called CUDA-Q
On this page
Definition and significance
CUDA-Q organizes quantum operations in kernels and provides interfaces for sampling outcomes and estimating observables. It can target classical simulation or supported quantum execution services. A GPU-accelerated quantum simulator remains classical computation; its speedup over another simulator is not quantum advantage.
Mechanism and mathematical treatment
Sampling asks for a distribution of measured outcomes. Observable estimation asks for an expectation such as <psi|H|psi>. Execution target and shot settings determine whether the result is calculated analytically by a simulator or estimated from finite samples. The exact APIs and defaults should be pinned to a version before publishing runnable reference code.
Fully worked reference example
For a kernel preparing |+> and observable Z, the analytic expectation is zero. With N=400 independent ideal shots, the signed sample mean has variance 1/400 and standard deviation 0.05. A measured estimate 0.03 is compatible with sampling noise; it does not indicate a different ideal state.
For observable X on the same state, every ideal outcome is +1 and the ideal sampling variance is zero. The number of shots alone therefore does not determine uncertainty; the state and observable matter.
Limitations and common misconceptions
Simulation throughput comparisons must state target hardware, precision, circuit and output task. Backend support and defaults evolve. No fabricated benchmark or executed output is supplied here.
Scientific relationships
Observable interfaces can estimate Pauli-sum expectations.
One kernel, several scientifically different outputs
Consider a conceptual kernel preparing cos(theta/2)|000>+sin(theta/2)|111>. It can be built from R_Y(theta) on q0 followed by CNOTs from q0 to q1 and q2. A computational-basis sampling task returns only 000 or 111, with probabilities cos^2(theta/2) and sin^2(theta/2). An observable task can instead request phase-sensitive quantities such as XXX, whose expectation is sin(theta).
At theta=pi/6, the two computational probabilities are (2+sqrt(3))/4 and (2-sqrt(3))/4. The XXX expectation is 1/2, while Z0Z1 is always+1 and Z0 has expectation sqrt(3)/2. These outputs describe the same state but require different access or measurement choices. Computational samples alone do not determine XXX without additional assumptions about the state preparation.
The official CUDA-Q execution documentation distinguishes sampled distributions, individual kernel return values and observable expectations. This extension uses those categories to define a reference contract, while all numerical predictions are derived from the displayed state. It does not claim an executed kernel, a backend benchmark or a particular default shot count.
An observable ledger with explicit measurement settings
Take H=(3/5)Z0Z1+(4/5)XXX-(1/5)Z0. At theta=pi/6, its expectation is 3/5+2/5-sqrt(3)/10=1-sqrt(3)/10, approximately 0.826795. The two Z terms can be measured in one computational-basis setting. The XXX term requires X-basis measurements on all three qubits under a simple Pauli strategy.
For the Z group, Z0Z1 is deterministic, so the group's variance comes only from -(1/5)Z0. It is (1/25)(1-3/4)=1/100 per shot. For the X group, the variance is (16/25)(1-1/4)=12/25. With 400 independent shots per group, the total estimator variance is (1/100+12/25)/400=0.001225, and its standard deviation is 0.035. The total state-preparation count is 800 under this hardware-style sampling model.
An analytic simulator could calculate the same expectation directly from its state representation, without those measurement shots. A reported observation value should identify which route produced it. Comparing the analytic calculation time with a finite-shot hardware estimate without matching the requested uncertainty would compare different tasks.
Individual return values preserve a different statistic
Suppose the kernel measures all three qubits and returns their Hamming weight K rather than the bit string. Here K is zero or three. Its mean is 3(2-sqrt(3))/4, and its variance is 9/16. A list of individual K values supports estimators of that return distribution. Aggregating them into a histogram preserves the frequencies but may discard execution-order information useful for diagnosing drift.
For this particular two-outcome state, K uniquely identifies the bit string, so no outcome information is lost by returning the Hamming weight. For a general three-qubit state, several bit strings share the same weight, and the mapping would discard information. A result interface should therefore be evaluated against the intended statistic rather than described as universally equivalent to full bit-string sampling.
Returning K also does not return the quantum amplitude of a basis state. It is a classical value computed from measured outcomes. A simulator's optional state access is a separate capability with a different interpretation. The distinction remains necessary even when all three output types are available through one programming environment.
Parameter batches and simulator resource claims
Evaluating theta values in a batch produces several separate circuit instances. It may reduce host overhead or exploit parallel classical resources, but it does not make them one coherent quantum evaluation. If each instance needs 800 preparations under the measurement plan above, a batch of twenty instances needs 16000 preparations unless an explicitly different estimator or reuse scheme is introduced.
A GPU statevector simulator accelerates classical arithmetic on stored amplitudes. Its raw memory still grows exponentially for generic pure states. For n qubits in complex128, the amplitude array uses 16 times 2^n bytes before buffers. Distributing that array across devices introduces communication costs when gates couple data partitions. A speedup over another simulator is a classical implementation comparison and should state precision, circuit structure, output task and machine configuration.
No such throughput measurement is supplied here. The reference kernel is small enough for direct analytic verification. The complete reference below executes the state and observable calculations with Python 3.12.16 and NumPy 2.3.5. Its output identifies exact expectations and predicted sampling uncertainty separately. No CUDA-Q target, accelerated kernel, or sampled hardware record is asserted.
Executed reference: observables and grouped statistical cost
The state has nonzero probabilities 0.93301270 and 0.06698730 on 000 and 111. The program prints [0.5, 1, 0.86602540] for XXX, ZZI, ZII and energy 0.82679492 for the specified Hamiltonian. It also prints group variances 0.01 and 0.48. The first follows because the jointly measured Z contribution is 0.6 minus 0.2 times ZII, with ZZI fixed at one. The second is 0.8 squared times the variance of XXX. At 400 independent samples per group, their estimator variances add to 0.001225, giving standard deviation 0.035.
The exact moments and the finite-shot standard deviation are different outputs: the program computes the former and predicts the latter from the Born distribution. It does not fabricate 800 observed measurement records. The calculation is a locally executed reference for the kernel's scientific meaning, independent of CUDA-Q, GPU acceleration, target selection, or hardware execution. None of those runtime capabilities is required by, or inferred from, this eight-amplitude calculation.
import numpy as np
np.set_printoptions(precision=8, suppress=True)
I = np.eye(2)
X = np.array([[0, 1], [1, 0]])
Z = np.diag([1, -1])
def kron3(a, b, c):
return np.kron(np.kron(a, b), c)
v = np.zeros(8)
v[0], v[7] = np.cos(np.pi / 12), np.sin(np.pi / 12)
XXX, ZZI, ZII = kron3(X, X, X), kron3(Z, Z, I), kron3(Z, I, I)
mean = lambda op: float(np.vdot(v, op @ v).real)
zgroup, xgroup = .6 * ZZI - .2 * ZII, .8 * XXX
variance = lambda op: mean(op @ op) - mean(op) ** 2
variances = np.array([variance(zgroup), variance(xgroup)])
energy = mean(zgroup + xgroup)
standard_error = np.sqrt(variances.sum() / 400)
print(v * v)
print([mean(XXX), mean(ZZI), mean(ZII)])
print(round(energy, 8))
print(variances)
print(round(float(standard_error), 8))
assert np.isclose(energy, 1 - np.sqrt(3) / 10)
assert np.allclose(variances, [.01, .48])
assert np.isclose(standard_error, .035)
Sources
Verification scope
Recorded source check ·
Official execution guide retrieved, 516 lines; sample, run and observe distinctions inspected.
Formal or reference-semantic source anchor only; no SDK execution, hardware run, or empirical advantage is asserted. Original worked examples are independent mathematical constructions.