Benchmarks

Summary

Three sweeps, each isolating one thing cuqml does that CUDA-Q does not, a fourth timing a whole hybrid training step through TorchLayer, a fifth handing cuqml kernels the way CUDA-Q writes them, and two measuring cuqml-tensornet: against CUDA-Q’s tensornet, and against cuTensorNet itself. The sections below have the commands that produce every number, the figures, the code each side runs, and the mechanism behind each; this is the summary. The tables here are fp32 on both sides, medians of 5 trials, each from one clean run of its sweep on an RTX 5090 with CUDA-Q 0.16.0, as Reading the numbers says. Every sweep compares results as well as timings and refuses to report a speedup for numbers that disagree. In the tables here, bold marks a row’s largest cell; where the spreads cannot tell a neighbour from it, the text quotes both.

At fp64. The first four sweeps also take --precision fp64, which runs both targets at fp64. Against nvidia’s own fp64, on an RTX 5090, the adjoint gradient at one parameter vector is 5.8x-25.3x faster and the batched QML gradient 24.9x-599.9x. Some circuits run gate by gate there, as Precision says; the tables, including where it loses, are in fp64.

The forward pass runs close to cudaq::nvidia’s, at 0.65–1.04x of its time across n=6…22 on a single-parameter-vector QAOA expectation and 0.83–1.29x on a VQE one, slower only at n=6 on both, within the spread there, and at VQE’s n=22. A forward at one parameter vector has no batch and no gradient in it — nothing for cuqml to add — and the sweep keeps that column so the suite is not read as a selection of its own best cases.

QSVM — batching over data. The B×B quantum kernel matrix: one batched state preparation and a single matmul, against B separate cudaq.get_state calls. Sweeping the batch at n=16:

batch

1

2

4

8

16

32

64

128

cudaq::cuqml ms

0.36

0.37

0.38

0.39

0.41

0.68

0.77

1.41

cudaq::nvidia ms

1.24

2.58

5.15

11.11

21.60

44.36

87.96

173.52

speedup

3.5x

6.9x

13.7x

28.2x

53.1x

65.1x

114.9x

123.5x

At batch=1 there is nothing to batch, and cuqml still leads by 3.5x. The gain grows with B — one launch per gate covers the whole batch, while CUDA-Q runs B circuits and B host transfers — to 124x at batch=128, the widest measured, and is still climbing there.

QAOA and VQE — the gradient, three ways. No batch axis at all: d<H>/dtheta for every parameter at one parameter vector. Comparing cuqml’s adjoint against cudaq.gradients.ParameterShift changes the algorithm and the implementation at once, so the sweep runs cuqml’s own batched parameter shift too — same rule as CUDA-Q’s, same engine as the adjoint — and the two claims come apart:

QAOA — ring circuit, Ising H

6

10

14

18

20

22

cudaq::cuqml ms, adjoint

2.19

2.79

3.08

4.00

5.00

8.96

cudaq::cuqml ms, parameter shift

1.20

1.44

1.83

15.48

50.29

231.30

cudaq::nvidia ms, ParameterShift

17.05

47.76

93.02

169.41

215.34

322.51

adjoint vs cudaq::nvidia

7.8x

17.1x

30.2x

42.3x

43.0x

36.0x

parameter shift vs cudaq::nvidia

14.2x

33.1x

51.0x

10.9x

4.3x

1.4x

Read the last row first — it is the like-for-like one. Same shift rule, same work, differing only in that cuqml folds the 2 * n_params shifted evaluations into one batched execution. That wins by 14.2-51.0x to n=14 and narrows from n=18 — 10.9x, 4.3x, then 1.4x — as amplitude traffic takes over from the per-execution overhead the batching removes: by n=22 one row of the batch costs 0.80 of a forward.

The row above it is two effects at once — a different algorithm and a different implementation. Against cuqml’s own parameter shift the algorithm is isolated: the adjoint is slower up to n=14 (2.19 ms against 1.20 ms at n=6, where its per-gate dispatch dominates) and pulls away above it, because one sweep is one pass over the state however many parameters there are.

A second scenario, where both halves are harder. A QAOA ring against an Ising Hamiltonian is the easiest shape the circuit and the observable can have. So the same sweep runs a VQE one: a hardware-efficient ansatz against a random 4-local Pauli Hamiltonian, where almost no term is a Z string. Same parameter count, so cudaq::nvidia does the same number of circuit evaluations in each:

VQE — hardware-efficient ansatz, 4-local Pauli H

6

10

14

18

20

22

cudaq::cuqml ms, adjoint

1.65

2.31

3.33

3.49

5.33

10.74

cudaq::cuqml ms, parameter shift

1.07

1.39

1.96

18.79

85.51

409.14

cudaq::nvidia ms, ParameterShift

12.49

37.46

74.62

135.50

181.32

281.78

adjoint vs cudaq::nvidia

7.6x

16.2x

22.4x

38.8x

34.0x

26.2x

parameter shift vs cudaq::nvidia

11.7x

27.0x

38.1x

7.2x

2.1x

0.7x

The shape holds: the adjoint peaks at 38.8x rather than 42.3–43.0x; the batched shift narrows the same way and at n=22 loses, 0.7x; and the forward gives back more — 0.83–1.29x of cudaq::nvidia’s time against 0.65–1.04x. So the advantage is a property of the method rather than of a convenient circuit or a convenient observable, which is the only reason the second table is worth printing.

The result also arrives in params.grad as a torch tensor. CUDA-Q’s is a list of floats with no autograd edge, so torch.optim cannot consume it at all — that part is not a speedup but a capability.

QML — both at once. One HEA gradient over 32 data samples, each with its own angles:

n

6

10

14

18

20

cudaq::cuqml ms

2.05

3.12

4.01

31.87

298.31

cudaq::nvidia ms

1159.49

3523.00

7812.30

13817.59

18934.67

speedup

565.7x

1128.6x

1949.7x

433.5x

63.5x

That is a different algorithm, not a faster kernel: one adjoint sweep replaces 2 * n_params * batch circuit evaluations. State-vector simulation is memory-bound, so what cuqml amortises is fixed per-execution overhead — the advantage grows while that overhead dominates, from 566x at n=6 to 1,950x at n=14, and narrows as the state vector grows past it, to 64x at n=20.

Sweeping the batch instead, at n=18, shows where that ceiling sits:

batch

1

2

4

8

16

32

64

128

speedup

76.1x

145.8x

286.2x

419.6x

431.5x

435.0x

205.5x

200.2x

At batch=1 the 76.1x is the adjoint method alone, with no batching in it — the same order as the QAOA table’s 42.3x at n=18, which has half as many parameters. Batching adds the rest, to 431.5x at batch=16 and 435.0x at 32, level within their spreads, and then it erodes: from batch=64 a row costs twice what it did at 32, 2.106 ms against 0.995, though the same checkpointed sweep ran at both in a probe of 2026-11-04, and its 20 states — 5.4 GB at batch=128 — sit well inside VRAM.

Hybrid — TorchLayer end to end. One training step of Linear -> circuit -> Linear, where the backward has to reach the Linear in front of the circuit. Without a batched adjoint that costs 2 * n_params circuit evaluations per row, because the inputs are circuit parameters too: against the layer a CUDA-Q user writes today it is 257.8–710.3x faster at batch 32 from n=6 to 18. Against a framework that broadcasts the batch and backpropagates, the margin at n=6 is 2.7x — read that comparison before quoting the first.

Kernels as CUDA-Q writes them. Separate arguments and angles computed inside the kernel run unchanged. The sweep times them against the same circuit rewritten by hand into one vector, so the gap is what reading the arithmetic out of the IR costs: 0.021–0.052 ms per forward, under 1% of it at batch 256 from n=16 on. The table is in kernel_form_sweep.py.

The tensor network. cuqml-tensornet against CUDA-Q’s tensornet at the same precision, fp32 and batch 32 on an RTX 5090: the forward is 4,025–13,210x faster one layer deep to 100 qubits, 10,152–17,569x four layers deep and 30,919–65,639x on QAOA, and the gradient, against tensornet’s ParameterShift, 95,410–1,601,939x, 1,007,477–5,081,938x and 380,640–1,601,274x. A single ⟨H⟩ evaluated once loses on the ansatz, since a first call captures the kernel and plans every term. Against cuTensorNet itself, given the same networks along the same paths — though not the same scheduling: cuTensorNet is handed each term on one stream, cuqml-tensornet spreads its steps over 32 — it is 1.5–16.4x faster forward and 1.8–9.4x with the gradient, in every cell. Timed on one stream as well, as cuTensorNet is driven, one layer at batch 32 leads by 1.42–1.57x forward and 1.15–1.31x with the gradient, against 3.29–7.29x and 2.77–6.57x on 32 streams; four layers deep, from 32 rows to 4,096, by 1.16–1.66x and 1.11–1.79x. The tables, shots and fp64 among them, are in tensornet_sweep.py.

The sweeps

Seven sweeps. Three isolate exactly one thing cuqml does that CUDA-Q does not; the fourth puts them inside a torch model, the fifth hands cuqml kernels the way CUDA-Q writes them, the sixth takes the batch and the gradient to widths no state vector holds, on cuqml-tensornet against CUDA-Q’s tensornet, and the seventh hands cuTensorNet itself — the library CUDA-Q ships — the networks the sixth contracts. The first four also run at fp64, against CUDA-Q’s own fp64 — see fp64 — and the last two at both precisions. Every claim points at the file it comes from.

forward only

with gradient

batch over data

qsvm_sweep.py

qml_sweep.py

no batch

(the forward column of vqa_sweep.py)

vqa_sweep.py

Each of those moves exactly one variable from its neighbour: QSVM → QML adds differentiation, QML → VQA removes the batch. hybrid_sweep.py changes the axis entirely — same effects, now measured through nn.Sequential, where the gradient has to come back out of the circuit into a classical layer.

The API each one exercises, and what it is measured against:

sweep

cuqml

CUDA-Q

qsvm_sweep.py

cuqml.get_state_batch(kernel, X)

cudaq.get_state(kernel, x) × B

vqa_sweep.py

cuqml.observe_batch(...).backward(), twice: a QAOA and a VQE scenario

cudaq.gradients.ParameterShift().compute(...)

qml_sweep.py

cuqml.observe_batch(...).sum().backward()

cudaq.gradients.ParameterShift().compute(...) × B

hybrid_sweep.py

cuqml.TorchLayer(...) in nn.Sequential

the same layer written by hand, parameter-shifted over inputs and weights

kernel_form_sweep.py

cuqml.observe_batch(kernel, h, gammas, betas).sum().backward() on the kernel as CUDA-Q writes it, and on a rewrite

cudaq.gradients.CentralDifference().compute(...) × B

tensornet_sweep.py

cuqml.observe_batch(...).sum().backward(), and with --shots cuqml.sample_batch(...), on cuqml-tensornet

cudaq.observe(...) and cudaq.gradients.ParameterShift().compute(...) × B, and cudaq.sample(...) × B, on tensornet

cutensornet_sweep.py

cuqml.observe_batch(...).sum().backward() on cuqml-tensornet, replayed

cuTensorNet’s own cutensornetNetworkContract and cutensornetNetworkComputeGradientsBackward on the same networks, replayed — the library CUDA-Q’s tensornet runs on

observe_batch, get_state_batch, sample_batch and TorchLayer are cuqml’s entire public surface; everything else in each snippet below is ordinary CUDA-Q and ordinary torch. Nothing is compared against a hand-written expectation — the baseline is always CUDA-Q’s own simulator, or in the seventh the cuTensorNet library CUDA-Q ships, checked against CUDA-Q’s simulator in turn — and every sweep checks the results agree before it reports a speedup.

cd benchmarks        # --csv and --png resolve against the working directory

python3 qsvm_sweep.py   --ns 6,10,14,16,18 --batch 32 --iters 3 \
  --csv qsvm_qubit_sweep.csv   --png figures/qsvm-qubits.png
python3 qsvm_sweep.py   --n 16 --batches 1,2,4,8,16,32,64,128 --iters 3 \
  --csv qsvm_batch_sweep.csv   --png figures/qsvm-batch.png
python3 vqa_sweep.py    --ns 6,10,14,18,20,22 --iters 3 \
  --csv vqa_sweep.csv          --png figures/vqa.png
python3 qml_sweep.py    --ns 6,10,14,18,20 --batch 32 --iters 3 \
  --csv qml_qubit_sweep.csv    --png figures/qml-qubits.png
python3 qml_sweep.py    --n 18 --batches 1,2,4,8,16,32,64,128 --iters 3 \
  --csv qml_batch_sweep.csv    --png figures/qml-batch.png
python3 hybrid_sweep.py --ns 6,10,14,18 --batch 32 --iters 3 \
  --csv hybrid_qubit_sweep.csv --png figures/hybrid-qubits.png
python3 hybrid_sweep.py --n 10 --batches 1,2,4,8,16,32 --iters 3 \
  --csv hybrid_batch_sweep.csv --png figures/hybrid-batch.png
python3 kernel_form_sweep.py --ns 8,12,16,20 --batches 1,256 --reps 2 --iters 10 \
  --csv kernel_form_sweep.csv

# The same sweeps with both targets at fp64
python3 qsvm_sweep.py   --ns 6,10,14,16,18 --batch 32 --iters 3 --precision fp64 \
  --csv qsvm_qubit_sweep_fp64.csv
python3 qsvm_sweep.py   --n 16 --batches 1,2,4,8,16,32,64,128 --iters 3 --precision fp64 \
  --csv qsvm_batch_sweep_fp64.csv
python3 vqa_sweep.py    --ns 6,10,14,18,20,22 --iters 3 --precision fp64 \
  --csv vqa_sweep_fp64.csv
python3 qml_sweep.py    --ns 6,10,14,18,20 --batch 32 --iters 3 --precision fp64 \
  --csv qml_qubit_sweep_fp64.csv
python3 qml_sweep.py    --n 18 --batches 1,2,4,8,16,32,64,128 --iters 3 --precision fp64 \
  --csv qml_batch_sweep_fp64.csv
python3 hybrid_sweep.py --ns 6,10,14,18 --batch 32 --iters 3 --precision fp64 \
  --csv hybrid_qubit_sweep_fp64.csv
python3 hybrid_sweep.py --n 10 --batches 1,2,4,8,16,32 --iters 3 --precision fp64 \
  --csv hybrid_batch_sweep_fp64.csv

# The tensor network against CUDA-Q's tensornet, at each precision
python3 tensornet_sweep.py --scenarios hea --ns 20,40,60,80,100 --batch 32 --iters 3 \
  --csv tensornet_hea_qubit_sweep.csv  --png figures/tensornet-qubits.png
python3 tensornet_sweep.py --scenarios hea --n 60 --batches 1,4,16,64,256 --iters 3 \
  --csv tensornet_hea_batch_sweep.csv  --png figures/tensornet-batch.png
python3 tensornet_sweep.py --scenarios hea --ns 20,40,60 --reps 4 --batch 32 --iters 3 \
  --csv tensornet_hea_deep_sweep.csv   --png figures/tensornet-deep.png
python3 tensornet_sweep.py --scenarios qaoa --ns 12,20,28,36 --batch 32 --iters 3 \
  --csv tensornet_qaoa_qubit_sweep.csv --png figures/tensornet-qubits.png
python3 tensornet_sweep.py --scenarios hea --ns 20,40,60,80,100 --batch 32 --iters 3 \
  --precision fp64 --csv tensornet_hea_qubit_sweep_fp64.csv
python3 tensornet_sweep.py --scenarios hea --n 60 --batches 1,4,16,64,256 --iters 3 \
  --precision fp64 --csv tensornet_hea_batch_sweep_fp64.csv
python3 tensornet_sweep.py --scenarios hea --ns 20,40,60 --reps 4 --batch 32 --iters 3 \
  --precision fp64 --csv tensornet_hea_deep_sweep_fp64.csv
python3 tensornet_sweep.py --scenarios qaoa --ns 12,20,28,36 --batch 32 --iters 3 \
  --precision fp64 --csv tensornet_qaoa_qubit_sweep_fp64.csv

# Its shots, at each precision
python3 tensornet_sweep.py --scenarios hea --ns 20,30,40,50,60 --batch 32 --shots 100 \
  --iters 3 --csv tensornet_hea_shots_sweep.csv       --png figures/tensornet-shots.png
python3 tensornet_sweep.py --scenarios hea --ns 20,30,40,50,60 --batch 1 --shots 100 \
  --iters 3 --csv tensornet_hea_shots_row_sweep.csv   --png figures/tensornet-shots-row.png
python3 tensornet_sweep.py --scenarios hea --n 40 --batches 1,4,16,64,256 --shots 100 \
  --iters 3 --csv tensornet_hea_shots_batch_sweep.csv --png figures/tensornet-shots-batch.png
python3 tensornet_sweep.py --scenarios hea --ns 20,30,40,50,60 --batch 32 --shots 100 \
  --iters 3 --precision fp64 --csv tensornet_hea_shots_sweep_fp64.csv
python3 tensornet_sweep.py --scenarios hea --ns 20,30,40,50,60 --batch 1 --shots 100 \
  --iters 3 --precision fp64 --csv tensornet_hea_shots_row_sweep_fp64.csv
python3 tensornet_sweep.py --scenarios hea --n 40 --batches 1,4,16,64,256 --shots 100 \
  --iters 3 --precision fp64 --csv tensornet_hea_shots_batch_sweep_fp64.csv

# The tensor network against cuTensorNet itself, along its own plans
python3 cutensornet_sweep.py --scenarios hea --ns 20,40,60,80,100 --batch 32 --iters 3 \
  --csv cutensornet_hea_qubit_sweep.csv      --png figures/cutensornet-qubits.png
python3 cutensornet_sweep.py --scenarios hea --n 60 --batches 1,4,16,64,256 --iters 3 \
  --csv cutensornet_hea_batch_sweep.csv      --png figures/cutensornet-batch.png
python3 cutensornet_sweep.py --scenarios hea --ns 20,40,60 --reps 4 --batch 32 --iters 3 \
  --csv cutensornet_hea_deep_sweep.csv       --png figures/cutensornet-deep.png
python3 cutensornet_sweep.py --scenarios hea --n 40 --reps 4 --batches 32,256,1024 --iters 3 \
  --csv cutensornet_hea_deep_batch_sweep.csv --png figures/cutensornet-deep-batch.png
python3 cutensornet_sweep.py --scenarios qaoa --ns 12,20,28,36 --batch 32 --iters 3 \
  --csv cutensornet_qaoa_qubit_sweep.csv     --png figures/cutensornet-qubits.png

The commands above produce every CSV and figure here, together with the cuTensorNet sweep’s other fifteen: the same five with --precision fp64 and --csv ending _fp64.csv; with --path ours and _ours.csv, the four-layer batch sweep then out to --batches 32,256,1024,4096; and with both and _fp64_ours.csv — the fifteen without --png. Each scenario is its own invocation, because the two reach different widths, and --png figures/tensornet-qubits.png writes tensornet-qubits-hea.png from one and tensornet-qubits-qaoa.png from the other. Every table and figure here, and every timing the Summary quotes, comes from one clean run of its sweep, as Reading the numbers says.

Add --batches 1,2,4,8,16,32,64,128 (with --n) to sweep the batch axis instead of the qubit count, --csv out.csv to save the table, --png out.png to draw it, and --precision fp64 to run both targets at fp64. qsvm_sweep.py and qml_sweep.py use the same 1-128 ladder, so their figures are read side by side; hybrid_sweep.py stops at 32. vqa_sweep.py draws two, one per scenario, from the one run — --png figures/vqa.png writes vqa-qaoa.png and vqa-vqe.png; kernel_form_sweep.py draws none, and refuses --png rather than ignore it. The figure is rendered by the sweep itself from the values it just measured — never re-read from the CSV — so a chart and the table beside it cannot drift apart. Drawing needs matplotlib: pip install -e '.[plot]'.

Every figure plots wall time for both backends on a log axis; the speedup is the vertical gap between a pair of curves, and the table beside the figure carries the exact number.


qsvm_sweep.py — batching over data

A quantum SVM trains on the Gram matrix K[i,j] = |<psi(x_i)|psi(x_j)>|^2: encode each of B samples into a state, then take every pairwise overlap. The batch axis is the dataset, so it belongs to the workload rather than to the benchmark.

# cuqml — one batched state preparation, then one matmul
psi = cuqml.get_state_batch(feature_map, X)     # (B, 2**n) complex, stays on the GPU
K   = (psi @ psi.conj().T).abs() ** 2          # the B x B Gram, one kernel launch

# cudaq::nvidia — no batch axis: one execution and one host transfer per sample
psi = np.stack([np.asarray(cudaq.get_state(feature_map, x)) for x in X])
K   = np.abs(psi @ psi.conj().T) ** 2          # the same Gram, on the CPU

The method. Encoding is a circuit, so a Gram matrix is B state preparations followed by B²/2 inner products. The inner products are cheap; the state preparations are not, and how you loop over them is the whole cost.

What CUDA-Q does. cudaq.get_state is defined over one parameter vector. B samples are therefore B independent circuit executions — B kernel-launch sequences, B allocations, and B device-to-host transfers of a 2**n state — after which the Gram is assembled in NumPy on the CPU.

What cuqml optimises. The batch is a tensor dimension, not a loop: one launch per gate moves every sample’s amplitudes, so the per-gate launch overhead, the parameter upload and the allocator traffic are paid once for the batch rather than once per sample, and fusion cuts the launches before that — see docs/how-it-works.md, The batch and The kernels.

The result is a (B, 2**n) complex tensor that never leaves the GPU, so the Gram is one complex matmul on device. B host transfers become none.

What it costs. The per-sample arithmetic is identical — the same gates touch the same number of amplitudes. This is amortisation of fixed overhead, not a faster kernel, which is exactly why the advantage is largest when 2**n is small enough that overhead dominates — level from n=6 to n=10 — and shrinks as the state grows. Against the batch axis cuqml’s time grows 4x across a 128-fold batch, 0.36 ms to 1.41 ms, while CUDA-Q’s grows 140x: the widening gap between them is the per-execution cost cuqml does not pay.

QSVM Gram matrix wall time, cudaq::cuqml vs cudaq::nvidia, against batch size

Against qubit count at a fixed batch, the gap holds to n=10 and then narrows as amplitude traffic grows past the fixed overhead it removes:

QSVM Gram matrix wall time, cudaq::cuqml vs cudaq::nvidia, against qubit count

vqa_sweep.py — the gradient algorithm, isolated from its implementation

Deliberately no batch axis: a variational step evaluates <H> at exactly one parameter vector, so a batch here would be an axis the workload does not have. This isolates the gradient algorithm and the torch integration on their own.

# cuqml — one adjoint sweep gives every parameter's gradient, as a torch tensor
params = torch.tensor(angles, device="cuda", requires_grad=True)
cuqml.observe_batch(kernel, hamiltonian, params).backward()
params.grad                                    # (n_params,) — torch.optim can step on it

# cuqml — the SAME shift rule CUDA-Q runs, with the shifted evaluations batched
cuqml.observe_batch(kernel, hamiltonian, params, diff_method="parameter-shift").backward()

# cudaq::nvidia — 2 * n_params circuit re-evaluations, returning plain floats
cost = lambda x: cudaq.observe(kernel, hamiltonian, list(x)).expectation()
grad = cudaq.gradients.ParameterShift().compute(angles, cost, cost(angles))

Why three curves and not two. The adjoint against cudaq.gradients.ParameterShift is a different algorithm and a different implementation, so a single ratio cannot say which one earned the win. cuqml’s own parameter shift is the control: against cudaq::nvidia it holds the algorithm fixed and measures only the batching, and against cuqml’s adjoint it holds the implementation fixed and measures only the algorithm. Both directions are in the table, and the batched shift’s lead narrows at the widest cells, where a row of its batch comes to cost what a forward does: to 1.4x on QAOA at n=22, and on VQE it loses there, 0.7x.

Why two scenarios. A QAOA ring against an Ising Hamiltonian is the easiest shape both halves of the problem can have — every observable term diagonal or weight one, and a circuit built from commuting diagonal layers. A benchmark could lean on that without saying so. So every cell runs twice, and the second scenario changes both halves: a hardware-efficient ansatz, which is what a VQE is actually optimised over, against a random 4-local Pauli Hamiltonian of the same term count, seeded so it reproduces. Both carry 2 * n * reps parameters, so cudaq::nvidia does the same number of circuit evaluations in each and the two figures can be read side by side.

CUDA-Q ships its own ansatz as cudaq.kernels.hwe, and this sweep does not use it. It is reachable only through cudaq.make_kernel, which costs 0.49 ms per cudaq.observe call against 0.25 ms for the same gates written as a @cudaq.kernel at n=6, and 1.53 against 1.23 ms at n=22, on this sweep’s VQE observable — measured by a probe on 2026-11-04, not by this sweep. That tax falls on the baseline and not on cuqml, which captures the kernel once, so it would have inflated the headline number — by 1.9x at n=6 and 1.2x at n=22 — for a reason that has nothing to do with the gradient.

The method: reverse-mode (adjoint) differentiation. One backward pass yields every parameter’s gradient, so the cost is proportional to the number of gates, not to the number of parameters. How, and what makes it cheap, is docs/how-it-works.md, The gradient.

What CUDA-Q does. cudaq.observe returns a plain number, so a gradient has to be assembled from re-evaluations of the whole circuit. ParameterShift evaluates the circuit at two shifted angles per parameter — 2 * n_params full simulations — and CentralDifference costs the same count while being only an approximation. The benchmark uses parameter shift precisely because it is exact, like the adjoint sweep, so the two curves are two ways of computing the same number rather than an exact result measured against an approximation.

What cuqml optimises. Beyond the algorithm, the gradient and the adjoint propagation for a gate are fused into a single kernel: the amplitudes that both steps need are read once, not twice. Diagonal layers get a stronger version of the same idea — because those gates commute, every edge’s gradient falls out of one pass over the layer’s output with no per-gate replay. Per-block partial sums are reduced with a deterministic tree rather than atomics, so a gradient is bit-reproducible run to run, which matters once an optimiser is consuming it.

The observable gets the same treatment: <P> and the adjoint it seeds are each one pass over the state whatever the Pauli string’s weight, and terms that flip the same bits share the pass — see The kernels. That is what makes the VQE scenario above cost what it does; term by term against a state clone it would cost 25 to 64 passes.

Why it wins. 2 * n_params circuit evaluations against one backward pass, so the gap widens with the parameter count — from 7.8x to 42.3x on QAOA and from 7.6x to 38.8x on VQE between n=6 and n=18, visible below as the two solid curves separating — and then narrows, on VQE from n=20 and on QAOA after a level n=20, to 36.0x and 26.2x at n=22. Colour is the backend, dash is the measure.

QAOA forward and gradient wall time, cudaq::cuqml vs cudaq::nvidia, against qubit count

VQE forward and gradient wall time, cudaq::cuqml vs cudaq::nvidia, against qubit count

The part that is not a speedup. The result lands in params.grad as an ordinary torch tensor, so torch.optim can step on it and a classical layer can sit either side of the circuit. CUDA-Q’s gradient is a list of floats with no autograd edge — there is no faster-or-slower comparison to make, because it cannot be done at all.

The forward curve is kept on purpose: at one parameter vector there is no batch and no gradient for cuqml to add, and the two run close — cuqml at 0.65x to 1.29x of cudaq::nvidia’s time, slower only at n=6 on both, within the spread there, and at VQE’s n=22 — and a suite that only showed its own best cases would not be worth reading. The dotted curve is kept for the same reason — cuqml’s parameter shift narrows towards cudaq::nvidia’s at the widest cells and on VQE crosses it at n=22: a row of its batch costs at most 0.08 of a forward to n=14, and 0.80–1.14 of one at n=22, where amplitude traffic has left the batch no overhead to remove.

Read against the solid blue curve rather than the green one, it also says something the adjoint’s own numbers cannot: up to n=14 the adjoint is the slower of cuqml’s two gradients (2.19 ms against 1.20 ms at n=6), because a sweep pays per-gate dispatch that a single batched forward does not. Its advantage is a large-n property, not a general one.

qml_sweep.py — both at once

B data samples, each with its own angles, and training needs all B gradients.

# cuqml — B rows, one sweep, every sample's gradient at once
params = torch.tensor(rows, device="cuda", requires_grad=True)   # (B, n_params)
cuqml.observe_batch(kernel, hamiltonian, params).sum().backward()
params.grad                                    # (B, n_params) — row b is sample b's

# cudaq::nvidia — no batch axis, so B independent parameter-shift gradients
[cudaq.gradients.ParameterShift().compute(r, cost, cost(r)) for r in rows]

The method. The same adjoint sweep as above, with the batch dimension carried through the backward pass. Each sample has its own encoded angles, so each needs its own gradient; one sweep produces all of them as a (B, n_params) tensor, and the rows are independent — sample b’s gradient depends only on sample b.

What CUDA-Q does. No batch axis and no autograd edge, so this is B independent parameter-shift gradients: 2 * n_params * B full circuit evaluations. (The sweep times one vector’s gradient and multiplies by B, since running all of them at large B would dominate the benchmark and they are genuinely independent.)

What cuqml optimises. The two effects compose. The adjoint method turns 2 * n_params evaluations into one pass, and the batch dimension turns B passes into one — so the work goes from O(n_gates * n_params * B) to O(n_gates) launches. Concretely, the gradient kernel accumulates per-block partial sums shaped (batch, blocks), so a single launch produces every sample’s contribution for the gate it is visiting.

What bounds it. Memory. A gradient holds the state, the adjoint and its checkpoints as split real/imaginary arrays, and the checkpoints dominate. There is no fixed multiplier: autograd._strategy_states counts the full states the chosen backward strategy keeps alive, plus three working copies, and core/memory.py sizes the batch from that. In a probe of 2026-11-04 this sweep’s circuit compiled to 72 ops, so sqrt-checkpointing held 20 states — 5.4 GB at n=18, batch=128, against 0.27 GB for the bare (B, 2**n) state itself. It is the ceiling on B, though not one this sweep reaches on this card: its largest cells fall back for another reason, below.

QML gradient wall time, cudaq::cuqml vs cudaq::nvidia, against qubit count

Against the batch axis at a fixed width, the gain climbs to batch 16 and 32 — 431.5x and 435.0x, level within their spreads — and then erodes: from batch 64 a row costs twice what it did at 32, 2.106 ms against 0.995, though a probe of 2026-11-04 ran the same checkpointed sweep at both, with its states well inside VRAM:

QML gradient wall time, cudaq::cuqml vs cudaq::nvidia, against batch size

hybrid_sweep.py — the circuit as a layer

One training step of Linear -> circuit -> Linear: forward, loss, and a backward that has to reach both Linears.

# cuqml — the kernel is a layer, and nn.Sequential does the rest
model = torch.nn.Sequential(
    torch.nn.Linear(n, n),
    cuqml.TorchLayer(kernel, (reps, n), [cudaq.spin.z(i) for i in range(n)]),
    torch.nn.Linear(n, 1),
).cuda()
((model(x) - target) ** 2).mean().backward()      # every layer's grad is filled

# cudaq::nvidia — no torch layer exists, so this is the one a user writes
class CudaqLayer(torch.nn.Module):                # forward: cudaq.observe per row
    ...                                           # backward: parameter shift per slot

Why the baseline is expensive, and honestly so. A circuit in the middle of a model must return a gradient with respect to its inputs, not only its weights — otherwise nothing in front of it trains. Inputs are just more circuit parameters, so 2 * n_params circuit evaluations per row becomes the price of a single step, and n_params now counts the encoding angles too. That is not a handicap the benchmark adds; it is what the API costs. The baseline is given every advantage available to it: one cudaq.observe call per row carries the whole operator list, so the state is prepared once per row rather than once per observable.

What cuqml does instead. One adjoint sweep for the whole batch and every observable at once — the engine’s measurement path already returns (batch, n_obs) from a single forward and seeds one adjoint from all their cotangents, so a wider output costs nothing extra. The gradient with respect to the inputs falls out of the same sweep as the weights’, because to the engine they are one parameter vector.

The third curve, measured twice. PennyLane’s qml.qnn.TorchLayer runs the same circuit and observables on both configurations this machine can build. lightning.gpu with diff_method="adjoint" is the algorithm cuqml runs, on the hardware cuqml runs it on — the like-for-like reading — but qml.qnn.TorchLayer executes it one sample at a time. default.qubit with backprop is a different algorithm, and the only one of the two that broadcasts the batch. Where both ran, default.qubit is the faster; at n=18 the sweep declined its tape — >RAM, judged on the host’s free memory, page cache aside, as Reading the numbers says — and only lightning.gpu has a time there. Reporting one and not the other would pick the winner before measuring. PennyLane is not a dependency of this repo and nothing outside hybrid_sweep.py and this section refers to it; install it only for this sweep:

pip install pennylane==0.45.1 pennylane-lightning-gpu==0.45.0

Those are the versions measured here (pulling pennylane-lightning 0.45.0 and custatevec-cu12 1.15.1).

Without it the column reports - and the sweep still measures cuqml against CUDA-Q. Its model is driven with CPU tensors, so the two Linears and one host transfer of (B, n) floats sit on the host while the simulation runs wherever the device puts it.

Two conventions specific to this sweep. The nvidia column is timed at one row and multiplied by the batch — parameter shift makes rows independent, the same argument _bench.cudaq_gradient_ms makes, and running all B would dominate the sweep. And agreement is checked twice, both across the whole batch, against exact parameter shift: the layer’s (batch, n_obs) output, and the gradient of the batch’s loss — every row has its own target, so a backward that mixed rows up could not cancel out of it. The reported |d| is the worse of the two.

What it measured. Against qubit count at batch = 32:

n

6

10

14

18

cudaq::cuqml ms

1.60

2.02

2.83

12.21

cudaq::nvidia ms

446.75

1040.63

2007.20

3146.73

PennyLane lightning.gpu ms

210.15

425.17

714.40

1378.45

PennyLane default.qubit ms

4.25

18.06

214.83

>RAM

vs cudaq::nvidia

278.6x

515.0x

710.3x

257.8x

vs PennyLane’s better one

2.7x

8.9x

76.0x

112.9x

Hybrid training step, cudaq::cuqml vs cudaq::nvidia and PennyLane, against qubit count

Read the 2.7x first. Against a backend that broadcasts the batch and backpropagates, cuqml at n=6 leads by 2.7x — 1.60 ms against 4.25 ms for default.qubit — in a cell whose trials spread 1.45x. The 278.6x in the row above is a statement about parameter shift, not about cuqml. What changes with n is that backprop keeps an autograd graph over a (B, 2**n) state: cuqml is 8.9x ahead of it by n=10 and 76.0x by n=14, and at n=18 the sweep declined default.qubit (>RAM), so PennyLane’s one measured there is the adjoint, lightning.gpu at 1,378 ms, 112.9x behind cuqml.

And read cuqml’s own jump. 2.83 ms at n=14 becomes 12.21 ms at n=18, and the margin against cudaq::nvidia falls from 710.3x to 257.8x. This is the bandwidth wall: 2^18 is sixteen times the amplitudes of 2^14, while below it the cost was fixed overhead rather than traffic — which is why cuqml’s time grows only 1.8x from n=6 to n=14, across 256 times the amplitudes. cuqml’s advantage on this workload is largest where per-execution overhead dominates and narrows once amplitude traffic does — the same shape the other state-vector sweeps show against qubit count.

Against the batch at n = 10, which is where a hybrid model’s cost actually lives:

batch

1

2

4

8

16

32

cudaq::cuqml ms

2.15

2.18

2.24

2.03

2.21

2.20

cudaq::nvidia ms

32.64

65.38

131.51

261.95

525.22

1088.12

PennyLane lightning.gpu ms

15.01

28.62

55.11

108.58

215.65

433.87

PennyLane default.qubit ms

6.29

6.87

6.97

7.99

11.79

17.74

vs cudaq::nvidia

15.2x

30.0x

58.7x

129.2x

237.2x

494.8x

vs PennyLane’s better one

2.9x

3.2x

3.1x

3.9x

5.3x

8.1x

Hybrid training step, cudaq::cuqml vs cudaq::nvidia and PennyLane, against batch size

cuqml’s row is flat — 2.15 ms at one sample, 2.20 ms at thirty-two, thirty-two times the work for the same wall time — which is the batch axis doing its job, and the clearest single picture of what this layer buys. The two per-sample backends climb linearly beside it.

And default.qubit is the closest. That backend batches too — 6.29 ms at one sample, 17.74 ms at thirty-two — and cuqml leads it 2.9x to 3.9x through batch 8, in cells whose spreads run 1.06x to 1.30x; above that its autograd graph over the batched state starts to cost, and cuqml reaches 8.1x by batch 32. Against a backend that batches, in other words, cuqml’s margin grows with the batch rather than arriving all at once.

Each table comes from one run of its own sweep, and the spread column runs 1.00x to 1.45x across both. Read the ratios rather than the absolute milliseconds, which move with the card. What does not move is the agreement: the seeds are fixed, so every |d| here is reproducible between sessions, and every cell in both tables matches CUDA-Q’s exact parameter shift to between 2.4e-07 and 6.0e-07 — against the 1e-4 at which the sweep would have printed MISMATCH instead of a speedup.

kernel_form_sweep.py — kernels as CUDA-Q writes them

Every other sweep hands cuqml a kernel shaped for it: one list[float], each angle a bare element of it. This one hands it the kernel a CUDA-Q user already has — separate arguments, angles computed inside — and asks what accepting it costs.

# cuqml — the kernel as CUDA-Q writes it, unchanged
@cudaq.kernel
def qaoa(gammas: list[float], betas: list[float]):
    ...
            rz(2.0 * gammas[layer], q[(w + 1) % n])
cuqml.observe_batch(qaoa, hamiltonian, gammas, betas).sum().backward()

# cuqml — the same circuit rewritten by hand: one vector, the arithmetic moved into torch
cuqml.observe_batch(qaoa_rewritten, hamiltonian, torch.cat([2 * gammas, 2 * betas], 1))

# cudaq::nvidia — one point at a time
cudaq.gradients.CentralDifference().compute(x, cost, cost(x))

What cuqml does. The arguments are laid side by side into one block at the boundary, and the angle arithmetic is read out of the kernel’s own IR and run in torch over the whole batch, a level of the expression at a time — From a CUDA-Q kernel to a differentiable program has the detail. The circuit itself is untouched, so the rewritten column — the same circuit on the same engine, its arithmetic done in torch by hand — is the control: the gap between it and as written is what the lift costs, and nothing else.

Two scenarios, because that cost depends on the shape of the arithmetic. shared is QAOA against an Ising ring: 2.0 * gammas[l] is the angle of every gate in a layer, so 2p values feed 2np gates and each is computed once. distinct is data re-uploading against a 4-local Pauli Hamiltonian: ry(xs[i] * ws[l*n + i]) is a different product at every gate, so nothing is shared and every angle is arithmetic of its own. p = 2, and every row of a batch is its own point.

Why CentralDifference, not ParameterShift. cudaq.gradients.ParameterShift shifts the kernel’s argument by π/2, which is the parameter-shift rule only when the angle is the argument. Through 2.0 * gamma it becomes a shift of π, where the cost repeats, and it returns 0.0 for every parameter of the QAOA kernel; through xs[i] * ws[k] it becomes a shift that depends on the data. CentralDifference costs the same two evaluations per parameter, so the choice moves the number and not the time. The gradient checked against is taken in fp64, and agreement is normwise: the largest difference over the largest magnitude compared. Wherever a quantity is O(1) that is the other sweeps’ absolute 1e-4; it scales only where these gradients grow with the Hamiltonian’s term count.

What it measured:

n

scenario

batch

fwd as written

fwd rewritten

fwd cudaq::nvidia

grad as written

grad rewritten

grad cudaq::nvidia

speedup

8

shared

1

0.487

0.435

0.465

2.420

2.262

4.275

1.8x

8

shared

256

0.487

0.441

119.063

2.558

2.396

1076.857

420.9x

8

distinct

1

0.418

0.386

0.328

1.648

1.577

15.945

9.7x

8

distinct

256

0.419

0.391

83.943

2.009

1.557

4088.453

2035.1x

12

shared

1

0.602

0.557

0.676

3.329

3.153

6.144

1.8x

12

shared

256

0.639

0.592

171.202

4.000

3.815

1548.547

387.2x

12

distinct

1

0.588

0.559

0.493

2.646

2.498

35.595

13.5x

12

distinct

256

0.594

0.562

123.338

2.689

2.545

9081.057

3377.3x

16

shared

1

0.743

0.694

0.959

4.431

4.295

8.585

1.9x

16

shared

256

5.632

5.598

244.202

43.697

43.216

2209.684

50.6x

16

distinct

1

0.751

0.718

0.673

3.493

3.057

65.671

18.8x

16

distinct

256

7.121

7.100

173.489

48.474

48.394

16790.113

346.4x

20

shared

1

0.911

0.866

1.299

5.501

5.397

11.708

2.1x

20

shared

256

78.050

78.016

345.128

784.178

784.002

3089.971

3.9x

20

distinct

1

0.939

0.910

1.043

4.932

4.853

126.479

25.6x

20

distinct

256

131.777

131.754

265.925

1036.766

1036.522

32181.786

31.0x

Every cell agrees to between 7.5e-09 and 2.7e-06, against the 1e-4 at which the sweep prints MISMATCH, and spreads run 1.00x to 1.64x.

Read the forward column first. At batch 1 cuqml’s forward is the slower in four of eight cells, by more than their spreads: distinct at n=8, 12 and 16 — 0.418 ms against 0.328 ms at n=8 — and shared at n=8, 0.487 ms against 0.465. It is ahead in the other four, by most at n=20 shared, 0.911 ms against 1.299 ms. The gradient at batch 1 is the adjoint’s win, not the batch’s: 1.8x on QAOA’s four parameters at n=8, but 25.6x on re-uploading’s sixty at n=20, because a central difference runs two circuits per parameter and the adjoint one pass whatever the count. Above batch 1 the batch axis compounds it, until amplitude traffic takes over at n=20.

And the lift’s own cost. As written costs 0.021–0.052 ms more than rewritten per forward, and between +0.071 and +0.481 ms more per gradient. The widest relative cost is n=8 distinct at batch 256, 2.009 ms against 1.557 ms per gradient, 29%. At batch 256 from n=16 on, the two are within 1.2% of each other.

tensornet_sweep.py — the tensor network, at widths no state vector holds

The same batch and the same gradient, on cuqml-tensornet, against CUDA-Q’s own tensor network at the same precision, up to widths no state vector, cuqml’s or CUDA-Q’s, holds.

# cuqml-tensornet — B rows in one call, every row's gradient from one backward pass
cudaq.set_target("cuqml-tensornet")
params = torch.tensor(rows, device="cuda", requires_grad=True)   # (B, n_params)
cuqml.observe_batch(kernel, hamiltonian, params).sum().backward()

# tensornet — one contraction per row, and 2 * n_params + 1 of them per row's gradient
cudaq.set_target("tensornet")
[cudaq.observe(kernel, hamiltonian, r) for r in rows]
[cudaq.gradients.ParameterShift().compute(r, cost, cost(r)) for r in rows]

The method. Each Pauli term is its own network, ⟨0|U_P† P U_P|0⟩, built from the gates in its backward light cone alone: every other gate meets its own adjoint and cancels. The batch is an index on the parametric gates’ tensors, so one contraction answers every row, and the gradient is reverse mode through the contractions — one backward pass for every parameter and every row. The contraction order is planned once per term and kept. Each pairwise step is one kernel, the steps holding no parameter are contracted once and kept, and a call made a second time with the same shapes is recorded as CUDA graphs and replayed from then on, its steps spread over 32 streams so that independent subtrees and terms run at once. How each piece works is The tensor network.

What CUDA-Q does. tensornet contracts the circuit through cuTensorNet, one parameter vector per call, and has no batch axis; its gradient is ParameterShift, 2 * n_params + 1 calls per row. The sweep times one row’s forward and runs one row’s gradient once, and multiplies each by B, as qml_sweep.py does — the rows genuinely are independent calls.

What cuqml optimises. Four things. The light cone: a term costs what the part of the circuit that reaches it costs, not the whole circuit. The batch: one call answers every row, so at n = 60 the forward takes 0.10 ms for 256 rows against 0.09 for one, and the gradient 0.35 ms against 0.28. The gradient: one backward pass, where parameter shift re-runs the circuit twice per parameter. And what a call repeats: a call made again replays its recording, so its time is the GPU’s alone. One row is faster too — 0.09 ms against 20.9 ms at n = 60 and batch 1, 239.6x — though how much of that is the light cone, and how much the rest of the two pipelines, this sweep does not separate.

What bounds it. Once a call replays, a fixed cost per call and the GPU’s work. The fixed cost is what the ansatz one layer deep shows: its forward takes 0.07–0.10 ms from 20 qubits to 100 and from 1 row to 256 — under 2x across both, while the qubits grow fivefold and the rows 256-fold. Where the network is bigger the GPU’s work shows instead: four layers deep the forward takes 0.17–0.25 ms, and fp64 takes 2.2–3.2x its fp32 time there, against 1.1–1.6x one layer deep. A gradient takes 3–6x the forward’s time: its replay computes the forward again and then runs every step backward, two contractions a step, and sums each gate’s gradient over the copies of it. Past that, the contraction’s own size: cuqml does not slice a contraction to fit, so a circuit deep enough that its largest intermediate outgrows the GPU is refused by name before anything is allocated, where cuTensorNet slices it and runs.

Where it loses. A single evaluation, done once. The first call captures the kernel, plans every term’s contraction and runs it unrecorded — the first call cuqml column — and, since every cell’s cuqml-tensornet side runs before its tensornet side, it is the first call the kernel meets on either target. At n = 60 and batch 1 that is 232 ms, against 20.9 ms for one tensornet call, and on the ansatz every cell that plans its contractions loses a one-off evaluation the same way — the batch sweep’s later cells reuse their first cell’s plan, at 1 ms: for one ⟨H⟩ at one point, CUDA-Q’s tensornet is the right tool. QAOA’s 2n-term Hamiltonians cost tensornet enough that cuqml’s first call is the faster from n=20 on, 170–446 ms against 361–1,101 ms for one call, and loses at n=12, 235 ms against 153. The second call records the call — the second call cuqml column, 7–133 ms, once — and the gradient’s first call records its own graph the same way, inside the warm-up; every call after those replays. The first cell of each run also pays the process’s own warm-up, which is why the one-layer table’s n = 20 reads higher than its n = 40; in a fresh environment the very first call also compiles cuqml’s CUDA extension, once. The other loss is a circuit deep or connected enough that its contraction does not fit, as above: refused, where cuTensorNet slices it and runs.

What it measured, on an RTX 5090, fp32 on both sides. Every row’s ⟨H⟩ — from the first call and from a replayed one — and row 0’s whole gradient agree with tensornet’s to 1.3e-05 in ⟨H⟩, on QAOA’s 36-qubit Hamiltonian, whose coefficients sum to 54, and 1.4e-06 in the gradient; at fp64, to 2.5e-14 and 4.0e-15. Spreads run 1.00–1.13x.

At batch 32 the forward is 4,025–13,210x faster one layer deep, from 20 qubits to 100, 10,152–17,569x four layers deep, and 30,919–65,639x on QAOA; with the gradient, 95,410–1,601,939x, 1,007,477–5,081,938x and 380,640–1,601,274x. Against the batch at 60 qubits cuqml’s forward barely moves, 0.09–0.10 ms from 1 row to 256, and its gradient stays within 0.28–0.35 ms, while tensornet’s grows with every row: at 256 rows its forward takes 5.6 s and its gradient 24 minutes. That is where the largest ratios come from, and a ratio that large measures CUDA-Q’s missing batch axis as much as either engine. At fp64 cuqml takes 1.1–3.2x its fp32 forward time, and tensornet 0.98–1.03x.

The ansatz one layer deep, batch 32, against qubit count:

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

20

32

40

2

189

7

0.07

277.5

4024.8x

0.23

22375

95410x

7.2e-07

1.3e-07

1.13x

hea

40

32

80

2

60

7

0.08

474.1

5878.9x

0.27

77172

288051x

6.0e-07

1.8e-07

1.08x

hea

60

32

120

2

79

9

0.10

690.5

7078.3x

0.31

166635

543308x

7.7e-07

3.6e-07

1.04x

hea

80

32

160

2

99

11

0.10

1080.3

10947.6x

0.32

346960

1076670x

1.4e-06

3.4e-07

1.03x

hea

100

32

200

2

120

13

0.10

1325.9

13210.3x

0.33

533953

1601939x

1.3e-06

1.8e-07

1.08x

Four layers deep, batch 32:

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

20

32

160

2

251

16

0.17

1770.8

10152.4x

0.58

586694

1007477x

8.9e-07

1.6e-07

1.02x

hea

40

32

320

2

178

21

0.21

2915.6

13601.0x

0.74

1923529

2613753x

7.2e-07

2.8e-07

1.02x

hea

60

32

480

2

378

29

0.25

4336.7

17569.0x

0.91

4626395

5081938x

8.0e-07

2.2e-07

1.01x

One layer at n = 60, against the batch:

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

60

1

120

2

232

12

0.09

20.9

239.6x

0.28

5124

18600x

4.8e-07

1.2e-07

1.07x

hea

60

4

120

2

1

9

0.09

85.4

927.0x

0.29

20575

71417x

1.8e-07

1.0e-07

1.03x

hea

60

16

120

2

1

9

0.10

343.2

3518.1x

0.31

82630

268118x

8.3e-07

1.9e-07

1.04x

hea

60

64

120

2

1

9

0.10

1375.3

13992.6x

0.32

338849

1064114x

7.7e-07

2.1e-07

1.03x

hea

60

256

120

2

1

10

0.10

5580.7

54130.1x

0.35

1454823

4195965x

1.2e-06

1.3e-07

1.02x

QAOA at p = 1 with the ring’s Ising Hamiltonian, batch 32:

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

qaoa

12

32

24

24

235

23

0.16

4896.4

30919.0x

0.62

237660

380640x

1.9e-06

6.0e-07

1.03x

qaoa

20

32

40

40

170

46

0.26

11561.8

45243.8x

1.02

929544

915264x

4.8e-06

1.2e-06

1.01x

qaoa

28

32

56

56

412

85

0.38

21119.6

54901.5x

1.90

2410537

1267475x

1.0e-05

1.2e-06

1.01x

qaoa

36

32

72

72

446

133

0.54

35220.2

65639.0x

3.15

5041464

1601274x

1.3e-05

1.4e-06

1.01x

At fp64, the same four, in the same order:

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

20

32

40

2

185

6

0.08

282.6

3436.1x

0.28

22767

81937x

5.6e-16

2.8e-16

1.07x

hea

40

32

80

2

61

7

0.10

484.6

4896.4x

0.33

77540

232524x

1.6e-15

2.3e-16

1.04x

hea

60

32

120

2

77

9

0.13

676.1

5254.0x

0.40

163226

406970x

1.4e-15

1.7e-16

1.02x

hea

80

32

160

2

98

11

0.13

1060.2

8302.6x

0.41

350427

846563x

1.3e-15

2.3e-16

1.04x

hea

100

32

200

2

121

13

0.13

1356.5

10487.2x

0.43

537263

1260122x

2.0e-15

3.3e-16

1.03x

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

20

32

160

2

251

17

0.38

1765.8

4665.1x

1.35

570078

423458x

8.9e-16

5.6e-16

1.01x

hea

40

32

320

2

175

21

0.56

2895.6

5131.9x

2.08

1897701

911389x

8.3e-16

6.7e-16

1.01x

hea

60

32

480

2

379

30

0.80

4383.5

5502.2x

3.09

4700086

1522998x

1.2e-15

7.8e-16

1.01x

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

hea

60

1

120

2

225

11

0.10

21.0

210.9x

0.31

5063

16093x

4.4e-16

2.8e-16

1.05x

hea

60

4

120

2

1

9

0.11

84.3

785.9x

0.33

20278

60611x

8.9e-16

2.2e-16

1.03x

hea

60

16

120

2

1

9

0.12

336.1

2812.7x

0.37

81407

219844x

1.6e-15

2.2e-16

1.03x

hea

60

64

120

2

1

9

0.13

1353.3

10191.1x

0.43

338266

782743x

1.6e-15

2.2e-16

1.03x

hea

60

256

120

2

1

10

0.16

5628.7

35928.8x

0.54

1448868

2693808x

1.8e-15

2.5e-16

1.02x

scenario

n

batch

params

terms

first call cuqml

second call cuqml

fwd cuqml

fwd tensornet

fwd speedup

grad cuqml

grad tensornet

grad speedup

max |dE|

max |dg|

spread

qaoa

12

32

24

24

233

23

0.19

4935.5

25633.3x

0.77

243627

315143x

3.6e-15

4.4e-16

1.02x

qaoa

20

32

40

40

169

48

0.32

11874.8

37426.0x

1.38

948165

686611x

8.0e-15

2.7e-15

1.01x

qaoa

28

32

56

56

413

85

0.49

21694.0

44326.1x

2.71

2437443

899474x

2.0e-14

2.3e-15

1.00x

qaoa

36

32

72

72

446

135

0.95

35437.9

37492.1x

3.89

5119851

1315296x

2.5e-14

4.0e-15

1.01x

Each figure plots wall time for the whole batch, cuqml-tensornet in blue and tensornet in green, solid the gradient and dashed the forward pass:

Tensor network, hardware-efficient ansatz, against qubit count

Tensor network, hardware-efficient ansatz four layers deep, against qubit count

Tensor network, hardware-efficient ansatz at 60 qubits, against batch size

Tensor network, QAOA ring with its Ising Hamiltonian, against qubit count

Shots

# cuqml-tensornet — every row's shots in one call
cudaq.set_target("cuqml-tensornet")
cuqml.sample_batch(kernel, params, shots_count=100)       # (B, 100) packed outcomes

# tensornet — one call per row
cudaq.set_target("tensornet")
[cudaq.sample(kernel, r, shots_count=100) for r in rows]

The method. One qubit at a time, from conditional marginals: the chance the next qubit reads 1, given what a shot has drawn, is one contraction, and every distinct (row, prefix) is one batch row of it, so the whole batch’s shots are one sequence of contractions — see The tensor network. Sampling is not recorded: each contraction has a row per distinct prefix, a count that changes from call to call, so every call runs unrecorded, as a first one does, a wave of independent steps at a time, its fixed part already made. --shots 100 times this over the ansatz one layer deep, at batch 32 and at one row against the width, and at 40 qubits against the batch.

What CUDA-Q does. tensornet samples one row per call, and its time climbs steeply with width up to 50 qubits: 20 ms a row at 20 qubits, 261 ms at 40, 10.4 s at 50, and 10.3 s at 60. Where one call takes longer than two seconds the sweep times it once, after a warm-up call, rather than twenty times, and the tensornet timed column says which.

The check. Shots cannot be compared draw for draw, so every row’s are checked against tensornet’s exact expectations of the same circuit: ⟨Z⟩ at each end and the middle of the chain, and ⟨Z Z⟩ with each one’s neighbour. A moment near ±1 is far from normal at a hundred shots, so the test is exact — a two-sided binomial p-value per moment — and min p is the smallest, times the number of moments the cell tests: the chance that any of them sits that far out by luck. Under 0.001 the cell would print MISMATCH.

Where it loses. A single sample, drawn once. A call’s first run captures the kernel and plans its networks — the first call cuqml column — and for one row it is slower than one tensornet call in 4 of the 12 one-row cells: 363 ms against 20 at 20 qubits at fp32, 353 against 21 at 20 at fp64, and the batch sweep’s one row, 520 against 262 and 522 against 319. Planned, no cell here loses; the closest is a single row at 20 qubits, at both precisions: 16.4 ms against tensornet’s 20 ms at fp32 (1.2x), and 16.7 ms against 21 ms at fp64 (1.2x). There every contraction is cheap, and cuqml’s sequence of them, one per measured qubit, is the whole cost.

What it measured, on an RTX 5090. No cell prints MISMATCH: min p runs from 0.031 to 1. At batch 32 cuqml is 30.0–3,437.3x faster at fp32, and 31.7–4,647.5x at fp64; for one row, 5.1–137.7x and 6.1–180.3x from 30 qubits up. Against the batch at 40 qubits cuqml’s time grows from 51.7 ms at 1 row to 73.6 ms at 256, 1.4x for 256 times the rows, while tensornet’s grows with every row, to 72.7 s at 256.

The ansatz one layer deep, 100 shots, batch 32, against qubit count:

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

20

32

100

305

21.7

652

median

30.0x

1

1.00x

hea

30

32

100

173

41.4

7164

median

173.0x

1

1.00x

hea

40

32

100

266

65.8

8651

median

131.5x

1

1.01x

hea

50

32

100

463

96.1

330235

once

3437.3x

1

1.01x

hea

60

32

100

519

130.1

336680

once

2587.4x

0.95

1.01x

One row:

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

20

1

100

363

16.4

20

median

1.2x

0.39

1.00x

hea

30

1

100

160

31.5

219

median

6.9x

1

1.00x

hea

40

1

100

249

51.3

261

median

5.1x

0.29

1.00x

hea

50

1

100

488

75.3

10372

once

137.7x

1

1.01x

hea

60

1

100

485

103.4

10318

once

99.7x

0.29

1.01x

At 40 qubits, against the batch:

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

40

1

100

520

51.7

262

median

5.1x

0.16

1.00x

hea

40

4

100

58

57.7

1055

median

18.3x

1

1.00x

hea

40

16

100

64

62.9

4224

median

67.2x

1

1.00x

hea

40

64

100

68

66.7

17353

median

260.1x

0.23

1.00x

hea

40

256

100

76

73.6

72679

median

988.0x

0.18

1.00x

At fp64, the same three, in the same order:

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

20

32

100

300

21.8

692

median

31.7x

0.096

1.00x

hea

30

32

100

174

41.6

8881

median

213.6x

1

1.01x

hea

40

32

100

266

66.1

10507

median

159.1x

1

1.01x

hea

50

32

100

465

96.5

448358

once

4647.5x

1

1.01x

hea

60

32

100

522

131.2

451082

once

3438.1x

1

1.01x

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

20

1

100

353

16.7

21

median

1.2x

1

1.01x

hea

30

1

100

163

32.1

273

median

8.5x

1

1.01x

hea

40

1

100

251

52.4

321

median

6.1x

1

1.01x

hea

50

1

100

445

76.9

13869

once

180.3x

0.2

1.01x

hea

60

1

100

492

105.8

13943

once

131.8x

0.44

1.02x

scenario

n

batch

shots

first call cuqml

sample cuqml

sample tensornet

tensornet timed

speedup

min p

spread

hea

40

1

100

522

51.8

319

median

6.2x

0.91

1.01x

hea

40

4

100

58

59.0

1278

median

21.7x

1

1.00x

hea

40

16

100

65

64.0

5169

median

80.8x

0.46

1.00x

hea

40

64

100

69

67.9

21121

median

310.8x

0.51

1.00x

hea

40

256

100

93

91.5

86909

median

949.5x

0.031

1.00x

Tensor network shots, one row, against qubit count

Tensor network shots, batch 32, against qubit count

Tensor network shots at 40 qubits, against batch size

cutensornet_sweep.py — the same networks, on cuTensorNet itself

tensornet_sweep.py measures cuqml-tensornet against cuTensorNet as CUDA-Q drives it: one network per row, the gradient by parameter shift. This one hands cuTensorNet itself — the library CUDA-Q ships, libcutensornet.so.2 in its cuquantum package, driven through its C API by _cutensornet.py — the networks cuqml-tensornet contracts, and gives it everything it offers for a call made again and again.

# cuqml-tensornet — B rows in one call, every row's gradient from one backward pass
cudaq.set_target("cuqml-tensornet")
cuqml.observe_batch(kernel, hamiltonian, params).sum().backward()

# cuTensorNet — the same networks, one per term, the batch one mode shared by every
# tensor that holds a row
cutensornetNetworkContract(handle, network, 0, workspace, None, stream)
cutensornetNetworkComputeGradientsBackward(handle, network, 0, workspace, None, stream)

What both are given. The same networks — every Pauli term’s light cone, its tensors and mode labels — and the same gates, built by cuqml’s own code from the same angles into the buffers cuTensorNet reads. cuTensorNet gets everything it offers a repeated call: its own optimizer, seeded so that a network is planned the same way each run — or, with --path ours, cuqml-tensornet’s path, so that the path is held equal; every tensor that never changes marked constant, and what is made of those alone kept in a cache workspace; its own backward pass, each copy of a gate’s gradient written to a slot of its own and each kind’s slots summed once, as cuqml-tensornet sums them; and the whole call — gates, every term, the coefficients, the backward — replayed from one CUDA graph, as cuqml-tensornet replays a repeated call. Each side has the GPU to itself in its turn. What differs is the contraction — its plan, its execution and its differentiation — and how its work reaches the GPU: cuTensorNet is handed every term’s contraction and backward on one stream, in turn, where cuqml-tensornet’s recordings spread their steps over 32 streams, so a gap measures the executor and that scheduling together.

What it measured, on an RTX 5090. Every row’s ⟨H⟩ and gradient agree between the two, and row 0’s ⟨H⟩ with CUDA-Q’s tensornet: to 6.7e-06 and 1.3e-06 at fp32, 1.8e-14 and 3.6e-15 at fp64. Along cuqml-tensornet’s paths — the same contractions, run and scheduled two ways — it is 1.5–16.4x faster than cuTensorNet forward and 1.8–9.4x with the gradient at fp32, in every cell, and 1.64–46.01x and 7.3–36.6x at fp64. Along cuTensorNet’s own plans the forward’s gap is as wide or wider in every cell, 3.5–3427.0x at fp32, and the gradient’s runs 1.96–136.86x: its optimizer takes 0.01 s to 59.1 s to plan a cell’s networks, and on some batched ones chooses a path whose cost explodes — at 100 qubits and batch 32 its forward takes 338 ms against 0.10 ms. A ratio that large measures that plan, not either executor; the --path ours rows are the ones that hold the path equal.

Where it loses. No cell, along either path, at either precision, on one stream or on 32. The narrowest lead on 32 streams is the ansatz four layers deep at 40 qubits and 4,096 rows, along cuqml-tensornet’s path at fp32, where cuTensorNet takes 6.824 ms against 4.463 ms forward (1.53x) and 20.622 ms against 11.505 ms with the gradient (1.79x). The lead shrinks as the rows grow — 6.33x at 32, 2.64x at 256, 2.11x at 1,024, 1.53x at 4,096 — as the steps grow from many small ones, which a launch dominates and the one-kernel step is built for, into large ones, which their arithmetic dominates. At fp64 the same cell favours cuqml-tensornet 1.64x and 15.83x.

What cuTensorNet refuses. cuTensorNet 2.13.0 could not prepare a backward along some of its own plans: INTERNAL_ERROR for one term of the four-layer network at 40 qubits and 256 rows, at either precision, and at the widest and deepest cells a cache workspace 22–187 GiB more than is free. Such a term’s backward takes the other path, and the note column says which term and why: 7 of 82 cells have one, every one along cuTensorNet’s own plans, and none lost its gradient — but in those the gradient columns do not compare one path on both sides. Where one cuTensorNet call takes longer than two seconds — its own plans, one cell, at fp64 — it is timed once more after that call, and the cuTN timed column says so.

Its fp64. On this card — a GeForce, whose fp64 rate is a small fraction of its fp32 — cuTensorNet’s forward takes 2.1–8.6x its fp32 time along the same paths, and cuqml-tensornet’s 1.1–8.3x: 1.1–1.5x on the ansatz one layer deep, and 8.3x and 8.0x four layers deep at 1,024 and 4,096 rows, where cuTensorNet’s own is 7.9x and 8.6x. The fp64 ratios are this card’s.

The ansatz one layer deep, batch 32, against qubit count:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

20

32

40

2

own

148

180

0.069

0.240

3.49x

0.232

0.604

2.60x

0.158

1.52x

0.561

1.08x

median

4.8e-07

1.2e-07

1.08x

-

hea

40

32

80

2

own

853

61

0.081

0.391

4.86x

0.268

1.048

3.92x

0.236

1.66x

0.843

1.24x

median

1.2e-07

1.2e-07

1.08x

-

hea

60

32

120

2

own

931

79

0.098

0.508

5.18x

0.306

1.386

4.52x

0.310

1.64x

1.107

1.25x

median

3.6e-07

2.1e-07

1.06x

-

hea

80

32

160

2

own

1917

100

0.099

4.089

41.48x

0.319

12.788

40.07x

0.388

10.55x

1.394

9.17x

median

6.6e-07

5.8e-07

1.04x

-

hea

100

32

200

2

own

5748

122

0.099

338.014

3426.98x

0.338

2.195

6.50x

0.464

727.83x

1.665

1.32x

median

4.8e-07

1.2e-07

1.02x

term 1’s backward on the other path (91.37 GiB more than is free)

hea

20

32

40

2

ours

given

182

0.068

0.225

3.29x

0.233

0.644

2.77x

0.158

1.42x

0.561

1.15x

median

4.8e-07

6.0e-08

1.13x

-

hea

40

32

80

2

ours

given

61

0.079

0.354

4.45x

0.266

1.023

3.84x

0.236

1.50x

0.838

1.22x

median

1.2e-07

1.2e-07

1.15x

-

hea

60

32

120

2

ours

given

79

0.098

0.471

4.80x

0.305

1.401

4.59x

0.310

1.52x

1.105

1.27x

median

3.6e-07

7.5e-08

1.08x

-

hea

80

32

160

2

ours

given

101

0.098

0.600

6.11x

0.320

1.779

5.56x

0.388

1.55x

1.384

1.29x

median

6.6e-07

6.0e-08

1.07x

-

hea

100

32

200

2

ours

given

121

0.100

0.727

7.29x

0.330

2.171

6.57x

0.464

1.57x

1.657

1.31x

median

4.8e-07

6.0e-08

1.03x

-

One layer at n = 60, against the batch:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

60

1

120

2

own

11

223

0.086

0.495

5.73x

0.275

1.367

4.96x

0.296

1.67x

1.051

1.30x

median

4.8e-07

6.0e-08

1.05x

-

hea

60

4

120

2

own

1040

1

0.090

0.503

5.59x

0.286

1.380

4.83x

0.299

1.68x

1.070

1.29x

median

6.0e-08

1.2e-07

1.10x

-

hea

60

16

120

2

own

922

1

0.100

0.501

5.03x

0.309

1.370

4.44x

0.311

1.61x

1.102

1.24x

median

3.6e-07

1.5e-07

1.10x

-

hea

60

64

120

2

own

836

1

0.099

0.528

5.35x

0.319

1.472

4.61x

0.317

1.67x

1.128

1.31x

median

2.4e-07

2.1e-07

1.05x

-

hea

60

256

120

2

own

2433

1

0.104

0.581

5.59x

0.343

1.781

5.19x

0.327

1.78x

1.183

1.50x

median

2.4e-07

3.0e-07

1.03x

-

hea

60

1

120

2

ours

given

222

0.088

0.405

4.62x

0.275

1.200

4.36x

0.292

1.39x

1.053

1.14x

median

4.8e-07

3.0e-08

1.03x

-

hea

60

4

120

2

ours

given

1

0.091

0.430

4.72x

0.284

1.335

4.71x

0.301

1.43x

1.072

1.25x

median

0.0e+00

3.0e-08

1.12x

-

hea

60

16

120

2

ours

given

1

0.098

0.444

4.51x

0.305

1.362

4.46x

0.309

1.44x

1.098

1.24x

median

3.6e-07

6.0e-08

1.11x

-

hea

60

64

120

2

ours

given

1

0.099

0.485

4.90x

0.315

1.484

4.71x

0.316

1.54x

1.133

1.31x

median

6.0e-08

1.2e-07

1.10x

-

hea

60

256

120

2

ours

given

1

0.103

0.503

4.88x

0.343

1.504

4.39x

0.327

1.54x

1.179

1.28x

median

2.4e-07

1.2e-07

1.10x

-

Four layers deep, batch 32:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

20

32

160

2

own

19140

236

0.174

0.919

5.27x

0.581

2.767

4.76x

0.529

1.74x

2.032

1.36x

median

3.0e-07

4.2e-07

1.01x

-

hea

40

32

320

2

own

58598

177

0.213

1.951

9.18x

0.732

6.444

8.81x

0.813

2.40x

3.108

2.07x

median

4.2e-07

1.8e-07

1.02x

-

hea

60

32

480

2

own

57491

337

0.246

31.741

129.15x

0.905

123.799

136.86x

1.079

29.43x

4.162

29.75x

median

9.8e-07

5.5e-07

1.03x

-

hea

20

32

160

2

ours

given

236

0.174

0.855

4.92x

0.582

2.844

4.89x

0.529

1.62x

2.037

1.40x

median

1.2e-07

1.3e-07

1.02x

-

hea

40

32

320

2

ours

given

177

0.213

1.351

6.33x

0.734

4.407

6.00x

0.814

1.66x

3.119

1.41x

median

4.2e-07

1.2e-07

1.01x

-

hea

60

32

480

2

ours

given

337

0.245

1.809

7.37x

0.907

6.060

6.68x

1.082

1.67x

4.176

1.45x

median

1.5e-07

1.5e-07

1.01x

-

Four layers at n = 40, against the batch — along cuqml-tensornet’s paths out to 4,096 rows; along cuTensorNet’s own to 1,024, where its forward already takes 1,471 ms:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

40

32

320

2

own

57099

316

0.213

1.952

9.17x

0.735

6.456

8.78x

0.814

2.40x

3.122

2.07x

median

3.0e-07

2.1e-07

1.01x

-

hea

40

256

320

2

own

54027

3

0.565

11.455

20.29x

1.971

5.618

2.85x

1.296

8.84x

5.151

1.09x

median

3.6e-07

3.6e-07

1.00x

term 1’s backward on the other path (status 14 (INTERNAL_ERROR))

hea

40

1024

320

2

own

56816

5

1.133

1470.593

1298.46x

4.141

8.108

1.96x

1.853

793.44x

7.533

1.08x

median

4.2e-07

4.2e-07

1.00x

term 1’s backward on the other path (57.60 GiB more than is free)

hea

40

32

320

2

ours

given

312

0.213

1.350

6.33x

0.735

4.404

5.99x

0.815

1.66x

3.124

1.41x

median

3.0e-07

1.2e-07

1.02x

-

hea

40

256

320

2

ours

given

4

0.567

1.498

2.64x

1.990

5.638

2.83x

1.297

1.16x

4.745

1.19x

median

2.4e-07

2.1e-07

1.03x

-

hea

40

1024

320

2

ours

given

4

1.136

2.399

2.11x

4.147

8.174

1.97x

1.861

1.29x

7.375

1.11x

median

3.0e-07

3.0e-07

1.00x

-

hea

40

4096

320

2

ours

given

7

4.463

6.824

1.53x

11.505

20.622

1.79x

4.460

1.53x

11.503

1.79x

median

3.0e-07

2.5e-07

1.00x

-

QAOA at p = 1 with the ring’s Ising Hamiltonian, batch 32:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

qaoa

12

32

24

24

own

793

223

0.160

1.474

9.22x

0.626

4.041

6.46x

0.762

1.93x

2.863

1.41x

median

1.4e-06

6.0e-07

1.03x

-

qaoa

20

32

40

40

own

5327

171

0.255

3.514

13.78x

1.021

9.661

9.46x

1.732

2.03x

6.575

1.47x

median

4.8e-06

9.5e-07

1.01x

-

qaoa

28

32

56

56

own

8911

290

0.384

6.233

16.23x

1.855

17.259

9.31x

3.094

2.01x

12.454

1.39x

median

5.7e-06

1.3e-06

1.00x

-

qaoa

36

32

72

72

own

24528

448

0.537

11.830

22.05x

3.157

32.160

10.19x

4.835

2.45x

22.441

1.43x

median

6.7e-06

1.2e-06

1.00x

-

qaoa

12

32

24

24

ours

given

220

0.159

1.347

8.45x

0.623

3.904

6.26x

0.763

1.77x

2.861

1.36x

median

9.5e-07

4.2e-07

1.03x

-

qaoa

20

32

40

40

ours

given

172

0.255

3.141

12.34x

1.016

9.242

9.10x

1.733

1.81x

6.582

1.40x

median

1.9e-06

4.8e-07

1.01x

-

qaoa

28

32

56

56

ours

given

292

0.386

5.640

14.60x

1.927

17.235

8.94x

3.088

1.83x

13.304

1.30x

median

0.0e+00

4.8e-07

1.00x

-

qaoa

36

32

72

72

ours

given

449

0.541

8.873

16.40x

3.157

29.732

9.42x

4.833

1.84x

22.413

1.33x

median

4.8e-06

7.2e-07

1.00x

-

At fp64, the same five, in the same order:

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

20

32

40

2

own

147

178

0.083

0.593

7.18x

0.278

1.535

5.53x

0.194

3.07x

0.696

2.21x

median

4.4e-16

2.8e-16

1.05x

-

hea

40

32

80

2

own

847

61

0.099

1.335

13.43x

0.333

3.354

10.07x

0.296

4.52x

1.066

3.15x

median

4.4e-16

2.2e-16

1.03x

-

hea

60

32

120

2

own

925

80

0.131

1.746

13.36x

0.402

4.500

11.18x

0.394

4.43x

1.422

3.16x

median

3.3e-16

2.8e-16

1.02x

-

hea

80

32

160

2

own

1907

101

0.128

19.858

155.56x

0.415

755.730

1822.66x

0.488

40.68x

1.775

425.77x

median

7.8e-16

3.9e-16

1.02x

-

hea

100

32

200

2

own

5665

124

0.129

1918.082

14867.14x

0.425

15.741

37.01x

0.585

3280.30x

2.127

7.40x

median

4.4e-16

2.2e-16

1.02x

term 1’s backward on the other path (182.69 GiB more than is free)

hea

20

32

40

2

ours

given

179

0.084

0.593

7.09x

0.279

3.280

11.77x

0.193

3.07x

0.697

4.70x

median

2.2e-16

2.2e-16

1.06x

-

hea

40

32

80

2

ours

given

61

0.100

1.003

10.03x

0.333

5.978

17.96x

0.296

3.39x

1.065

5.61x

median

4.4e-16

2.2e-16

1.10x

-

hea

60

32

120

2

ours

given

78

0.129

1.405

10.89x

0.403

9.483

23.55x

0.393

3.57x

1.421

6.67x

median

1.1e-16

1.7e-16

1.03x

-

hea

80

32

160

2

ours

given

98

0.128

1.808

14.13x

0.415

12.173

29.36x

0.490

3.69x

1.780

6.84x

median

7.8e-16

2.2e-16

1.03x

-

hea

100

32

200

2

ours

given

122

0.129

2.208

17.11x

0.428

15.674

36.58x

0.585

3.77x

2.128

7.37x

median

4.4e-16

1.1e-16

1.02x

-

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

60

1

120

2

own

11

218

0.100

0.976

9.73x

0.315

2.514

7.97x

0.354

2.76x

1.284

1.96x

median

4.4e-16

5.6e-17

1.02x

-

hea

60

4

120

2

own

1063

1

0.109

1.022

9.38x

0.336

2.626

7.82x

0.365

2.80x

1.324

1.98x

median

3.3e-16

1.1e-16

1.04x

-

hea

60

16

120

2

own

943

1

0.119

1.403

11.77x

0.372

3.500

9.42x

0.381

3.68x

1.383

2.53x

median

5.6e-16

2.8e-16

1.05x

-

hea

60

64

120

2

own

936

1

0.133

2.261

16.98x

0.431

6.321

14.67x

0.422

5.35x

1.516

4.17x

median

4.4e-16

2.2e-16

1.03x

-

hea

60

256

120

2

own

2529

1

0.157

3.416

21.81x

0.539

12.229

22.70x

0.470

7.27x

1.710

7.15x

median

6.7e-16

5.6e-16

1.01x

-

hea

60

1

120

2

ours

given

215

0.100

0.844

8.46x

0.314

2.297

7.31x

0.352

2.40x

1.282

1.79x

median

4.4e-16

2.8e-17

1.07x

-

hea

60

4

120

2

ours

given

1

0.109

0.991

9.10x

0.337

8.413

24.97x

0.365

2.71x

1.326

6.35x

median

1.1e-16

1.1e-16

1.03x

-

hea

60

16

120

2

ours

given

1

0.120

1.169

9.73x

0.371

8.833

23.81x

0.382

3.06x

1.383

6.39x

median

5.6e-16

1.1e-16

1.02x

-

hea

60

64

120

2

ours

given

1

0.133

1.826

13.72x

0.433

6.053

13.98x

0.419

4.35x

1.513

4.00x

median

1.1e-16

2.2e-16

1.06x

-

hea

60

256

120

2

ours

given

1

0.157

2.010

12.78x

0.540

6.804

12.61x

0.468

4.30x

1.704

3.99x

median

2.2e-16

2.8e-16

1.02x

-

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

20

32

160

2

own

18775

242

0.380

3.668

9.64x

1.345

18.586

13.82x

0.830

4.42x

3.244

5.73x

median

6.1e-16

3.3e-16

1.01x

-

hea

40

32

320

2

own

58701

175

0.569

10.574

18.57x

2.050

145.760

71.09x

1.342

7.88x

5.587

26.09x

median

7.8e-16

6.7e-16

1.01x

-

hea

60

32

480

2

own

57684

337

0.801

608.165

759.51x

3.112

45.553

14.64x

1.860

326.93x

7.940

5.74x

median

8.9e-16

4.4e-16

1.01x

term 1’s backward on the other path (22.25 GiB more than is free)

hea

20

32

160

2

ours

given

237

0.378

3.275

8.66x

1.351

16.785

12.42x

0.831

3.94x

3.246

5.17x

median

6.1e-16

3.3e-16

1.01x

-

hea

40

32

320

2

ours

given

178

0.568

5.106

8.99x

2.050

29.740

14.51x

1.344

3.80x

5.204

5.71x

median

3.3e-16

3.9e-16

1.01x

-

hea

60

32

480

2

ours

given

336

0.801

6.726

8.40x

3.109

45.602

14.67x

1.860

3.62x

7.930

5.75x

median

4.4e-16

2.5e-16

1.00x

-

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

hea

40

32

320

2

own

59089

314

0.570

10.570

18.54x

2.090

145.714

69.72x

1.344

7.87x

5.076

28.71x

median

6.7e-16

6.7e-16

1.01x

-

hea

40

256

320

2

own

55094

5

2.911

60.230

20.69x

10.123

123.675

12.22x

4.052

14.87x

15.255

8.11x

median

8.3e-16

4.4e-16

1.00x

term 1’s backward on the other path (status 14 (INTERNAL_ERROR))

hea

40

1024

320

2

own

57575

22

9.404

8818.714

937.81x

32.842

433.501

13.20x

10.979

803.24x

40.840

10.61x

fwd once

9.4e-16

7.8e-16

1.00x

term 1’s backward on the other path (187.43 GiB more than is free)

hea

40

32

320

2

ours

given

319

0.567

5.106

9.01x

2.090

29.742

14.23x

1.344

3.80x

5.079

5.86x

median

3.3e-16

2.8e-16

1.00x

-

hea

40

256

320

2

ours

given

5

2.905

8.794

3.03x

10.136

123.987

12.23x

4.050

2.17x

15.024

8.25x

median

5.6e-16

4.4e-16

1.00x

-

hea

40

1024

320

2

ours

given

12

9.415

18.918

2.01x

32.833

434.294

13.23x

10.983

1.72x

40.838

10.63x

median

5.6e-16

4.4e-16

1.00x

-

hea

40

4096

320

2

ours

given

39

35.901

58.979

1.64x

93.951

1487.252

15.83x

36.031

1.64x

93.891

15.84x

median

1.1e-15

5.6e-16

1.00x

-

scenario

n

batch

params

terms

path

plan cuTN

first call cuqml

fwd cuqml

fwd cuTN

fwd speedup

grad cuqml

grad cuTN

grad speedup

fwd cuqml 1 stream

fwd speedup 1 stream

grad cuqml 1 stream

grad speedup 1 stream

cuTN timed

max |dE|

max |dg|

spread

note

qaoa

12

32

24

24

own

790

232

0.193

5.128

26.52x

0.771

12.739

16.51x

0.999

5.13x

3.849

3.31x

median

3.6e-15

1.1e-15

1.03x

-

qaoa

20

32

40

40

own

5336

170

0.317

12.260

38.67x

1.309

30.308

23.16x

2.278

5.38x

8.983

3.37x

median

7.1e-15

2.0e-15

1.01x

-

qaoa

28

32

56

56

own

8960

291

0.489

23.038

47.07x

2.709

56.574

20.88x

4.180

5.51x

18.368

3.08x

median

1.1e-14

2.0e-15

1.01x

-

qaoa

36

32

72

72

own

24591

446

0.949

50.453

53.19x

3.892

145.964

37.50x

7.254

6.96x

29.553

4.94x

median

1.8e-14

3.6e-15

1.02x

-

qaoa

12

32

24

24

ours

given

228

0.195

5.275

27.12x

0.773

16.285

21.06x

0.999

5.28x

3.848

4.23x

median

8.9e-16

6.7e-16

1.03x

-

qaoa

20

32

40

40

ours

given

174

0.318

12.776

40.20x

1.350

37.488

27.78x

2.281

5.60x

9.008

4.16x

median

1.8e-15

8.9e-16

1.01x

-

qaoa

28

32

56

56

ours

given

297

0.510

23.458

46.01x

2.708

68.774

25.39x

4.107

5.71x

17.665

3.89x

median

5.3e-15

1.8e-15

1.01x

-

qaoa

36

32

72

72

ours

given

454

0.946

37.323

39.43x

3.895

107.768

27.67x

7.260

5.14x

29.573

3.64x

median

7.1e-15

2.2e-15

1.02x

-

Each figure plots wall time for the whole batch along cuTensorNet’s own plans, fp32, cuqml-tensornet in blue and cuTensorNet in green, solid the gradient and dashed the forward pass; a note under the legend names the cells where a term’s backward took the other path:

Tensor network against cuTensorNet, the ansatz one layer deep, against qubit count

Tensor network against cuTensorNet, the ansatz at 60 qubits, against batch size

Tensor network against cuTensorNet, the ansatz four layers deep, against qubit count

Tensor network against cuTensorNet, the ansatz four layers deep at 40 qubits, against batch size

Tensor network against cuTensorNet, QAOA ring with its Ising Hamiltonian, against qubit count

One stream against 32

--path ours holds the path equal, not the scheduling: cuTensorNet is handed every term’s contraction and backward on one stream, where cuqml-tensornet’s recordings spread their steps over 32. So the sweep also times cuqml-tensornet with its recordings on one stream — the 1 stream columns of every table above — and what the streams contribute is measured rather than left inside the speedup.

What the streams buy. At batch 32, one layer, 20 to 100 qubits, along cuqml-tensornet’s paths at fp32, the lead over cuTensorNet is 3.29–7.29x forward and 2.77–6.57x with the gradient on 32 streams, and 1.42–1.57x and 1.15–1.31x on one: most of it there is the streams, and the executor alone is still ahead. Four layers deep at 40 qubits, from 32 rows to 4,096, one stream leads by 1.16–1.66x forward and 1.11–1.79x with the gradient. No cell of either path, at either precision, is behind on one stream. At 4,096 rows the call is too large to record, so it runs unrecorded either way and the stream count does not reach it: 4.463 ms against 4.460 forward, 11.505 against 11.503 with the gradient.

fp64 — the same sweeps at double precision

--precision fp64 runs a sweep with both targets at fp64, each selected the way CUDA-Q selects a simulator’s precision — cudaq.set_target("cuqml", option="fp64") against cudaq.set_target("nvidia", option="fp64") — and every tensor at float64. The agreement bar moves with it, from the fp32 accumulation floor to 1e-10: a bar no fp32 arithmetic meets, so a path that quietly narrowed would print MISMATCH instead of a speedup. kernel_form_sweep.py measures the angle lift, which runs in float64 at either precision, so it does not take the flag, and refuses it rather than ignore it.

What changes at fp64. Two of cuqml’s fp32 kernels have no fp64 build — see docs/api.md’s Precision — so at fp64 those circuits take the per-gate paths, a pass per gate over a state twice the size: cuqml gives up more than the doubled bandwidth, and most where a layer is wide and the state large.

What it measured, on an RTX 5090, fp64 on both sides. Every cell agrees with cudaq::nvidia to between 4.2e-17 and 4.6e-14, and spreads run 1.00x to 1.26x.

QSVM, batch 32 against qubit count, then n = 16 against the batch:

n

batch

features

cudaq::cuqml ms

cudaq::nvidia ms

speedup

max |dK|

spread

6

32

24

0.26

16.07

62.6x

4.0e-15

1.11x

10

32

40

0.41

20.47

49.9x

6.2e-15

1.01x

14

32

56

1.51

30.14

20.0x

8.2e-15

1.00x

16

32

64

4.80

47.19

9.8x

8.2e-15

1.00x

18

32

72

20.50

111.53

5.4x

1.0e-14

1.00x

n

batch

features

cudaq::cuqml ms

cudaq::nvidia ms

speedup

max |dK|

spread

16

1

64

0.53

1.46

2.7x

7.8e-15

1.04x

16

2

64

1.12

2.28

2.0x

7.8e-15

1.01x

16

4

64

1.49

5.23

3.5x

6.7e-15

1.02x

16

8

64

2.03

10.20

5.0x

8.0e-15

1.00x

16

16

64

2.97

21.34

7.2x

9.1e-15

1.00x

16

32

64

4.83

43.79

9.1x

8.9e-15

1.01x

16

64

64

9.70

89.94

9.3x

1.0e-14

1.00x

16

128

64

22.41

173.69

7.8x

1.2e-14

1.00x

62.6x at n=6 falls to 5.4x at n=18, where the feature map’s layers are per-gate passes over a (32, 2**18) complex128 block. Against the batch the gain is 2.7x at batch 1 and 2.0x at 2, and builds to 9.3x at 64 before easing to 7.8x at 128.

VQA — one parameter vector, the gradient three ways:

n

scenario

params

fwd cudaq::cuqml

fwd cudaq::nvidia

fwd slower

grad cudaq::cuqml

grad cudaq::cuqml (shift)

grad cudaq::nvidia

grad speedup

shift speedup

max |dE|

max |dg|

spread

6

qaoa

24

0.384

0.277

1.39x

2.19

1.21

12.71

5.8x

10.5x

3.1e-15

1.2e-15

1.03x

6

vqe

24

0.353

0.236

1.50x

1.67

1.04

10.91

6.5x

10.5x

1.7e-16

7.8e-16

1.24x

10

qaoa

40

0.526

0.466

1.13x

3.03

1.50

36.30

12.0x

24.3x

6.2e-15

1.7e-15

1.12x

10

vqe

40

0.582

0.402

1.45x

3.31

1.60

31.65

9.6x

19.7x

1.9e-16

2.8e-16

1.13x

14

qaoa

56

0.656

0.673

0.98x

3.48

3.66

73.62

21.2x

20.1x

1.4e-14

2.2e-15

1.13x

14

vqe

56

0.787

0.616

1.28x

4.00

7.06

65.02

16.3x

9.2x

4.2e-17

9.7e-17

1.07x

18

qaoa

72

0.943

1.067

0.88x

5.62

52.02

142.33

25.3x

2.7x

3.2e-14

3.3e-15

1.01x

18

vqe

72

1.752

1.047

1.67x

6.68

126.31

134.10

20.1x

1.1x

1.8e-16

2.4e-16

1.00x

20

qaoa

80

2.001

1.849

1.08x

11.20

238.69

281.14

25.1x

1.2x

3.9e-14

4.7e-15

1.00x

20

vqe

80

4.538

1.518

2.99x

18.55

553.63

226.16

12.2x

0.4x

4.2e-17

1.1e-16

1.00x

22

qaoa

88

6.474

5.374

1.20x

38.20

1134.12

940.68

24.6x

0.8x

4.6e-14

5.0e-15

1.00x

22

vqe

88

15.602

3.763

4.15x

72.91

2544.57

649.92

8.9x

0.3x

1.0e-16

1.1e-16

1.00x

The adjoint is 5.8x to 25.3x faster than nvidia’s ParameterShift, rising with n and then narrowing as at fp32 — on VQE from n=20, on QAOA at n=22. The forward is the slower in most cells, and most at the large end — 4.15x on VQE at n=22, where each rotation layer of the ansatz is 22 passes over the state rather than a few — and level on QAOA at n=14, 0.98x, and faster at n=18, 0.88x. cuqml’s own parameter shift loses on VQE from n=20 — 0.4x, 0.3x — and on QAOA at n=22, 0.8x, where a row of its batch costs 0.76–1.00 of a forward and the forward is the slower.

QML, batch 32 against qubit count, then n = 18 against the batch:

n

batch

params

cudaq::cuqml ms

cudaq::nvidia ms

speedup

max |dE|

max |dg|

spread

6

32

48

3.10

979.30

315.7x

3.8e-15

3.0e-15

1.09x

10

32

80

5.00

2999.32

599.9x

4.0e-15

2.7e-15

1.01x

14

32

112

14.73

6542.59

444.2x

3.1e-15

4.4e-15

1.00x

18

32

144

215.95

13760.41

63.7x

4.9e-15

2.7e-15

1.00x

20

32

160

1080.97

26905.40

24.9x

3.6e-15

2.6e-15

1.00x

n

batch

params

cudaq::cuqml ms

cudaq::nvidia ms

speedup

max |dE|

max |dg|

spread

18

1

144

10.79

390.22

36.2x

2.0e-15

1.8e-15

1.02x

18

2

144

18.86

804.26

42.6x

6.7e-16

1.1e-15

1.00x

18

4

144

30.47

1633.58

53.6x

1.3e-15

1.8e-15

1.00x

18

8

144

54.15

3339.18

61.7x

3.6e-15

2.4e-15

1.00x

18

16

144

107.43

6817.43

63.5x

5.6e-15

5.1e-15

1.00x

18

32

144

216.04

13732.75

63.6x

4.4e-15

3.1e-15

1.00x

18

64

144

432.83

27670.11

63.9x

3.6e-15

3.1e-15

1.00x

18

128

144

979.35

55843.83

57.0x

4.2e-15

4.4e-15

1.00x

315.7x to 599.9x up to n=14, then 63.7x and 24.9x. Against the batch cuqml’s time grows nearly in proportion — 10.79 ms at batch 1, 979.35 ms at 128 — because without the fused sweep each gate’s gradient is a pass of its own: the batch amortises launches, not bandwidth, and the gain climbs from 36.2x at batch 1 to 61.7x at 8, then by under 4% to its largest, 63.9x at 64, before easing to 57.0x at 128.

Hybrid, batch 32 against qubit count, then n = 10 against the batch:

n

batch

params

cudaq::cuqml ms

cudaq::nvidia ms

lightning.gpu ms

default.qubit ms

vs cudaq::nvidia

vs pennylane

cudaq::cuqml |d|

pl |d|

spread

6

32

18

2.13

404.72

211.78

4.40

190.3x

MISMATCH

7.8e-16

3.0e-08

1.03x

10

32

30

2.78

928.89

428.36

17.46

334.4x

MISMATCH

4.4e-16

2.7e-08

1.01x

14

32

42

6.17

1864.24

719.15

182.34

302.2x

MISMATCH

7.8e-16

2.9e-08

1.00x

18

32

54

85.78

3372.57

1373.35

>RAM

39.3x

MISMATCH

1.2e-15

3.0e-08

1.00x

n

batch

params

cudaq::cuqml ms

cudaq::nvidia ms

lightning.gpu ms

default.qubit ms

vs cudaq::nvidia

vs pennylane

cudaq::cuqml |d|

pl |d|

spread

10

1

30

2.80

29.16

15.06

6.27

10.4x

MISMATCH

4.4e-16

2.5e-08

1.05x

10

2

30

3.05

59.14

28.41

6.57

19.4x

MISMATCH

4.4e-16

2.8e-08

1.16x

10

4

30

3.06

118.57

55.19

7.03

38.8x

MISMATCH

2.2e-16

1.9e-08

1.19x

10

8

30

3.02

239.05

108.77

7.97

79.0x

MISMATCH

3.3e-16

2.8e-08

1.17x

10

16

30

3.03

476.07

216.19

11.22

157.3x

MISMATCH

7.8e-16

2.9e-08

1.15x

10

32

30

3.30

988.20

433.30

17.35

299.6x

MISMATCH

5.0e-16

3.0e-08

1.26x

Against the hand-written CUDA-Q layer, 190.3x to 334.4x up to n=14, 39.3x at n=18, and from 10.4x at batch 1 to 299.6x at 32. Against PennyLane the sweep reports no speedup at all: pl |d| is 1.9e-08 to 3.0e-08, over the 1e-10 bar, so every cell prints MISMATCH — the check doing its job. The disagreement is lightning.gpu’s own: run alone at complex128, its forward already differs from CUDA-Q’s fp64 by that order, while default.qubit, through the same harness, agrees to the fp64 floor. The timings stand in the table.


Reading the numbers

How a sweep is measured, and what to record when one is run again, is in docs/procedure.md, part B.

The published tables and figures come from one machine, an RTX 5090 with an AMD Ryzen 9 9950X3D host, with CUDA-Q 0.16.0 and its cuTensorNet 2.13.0 on both sides of every comparison, fp32 unless a section says fp64. Every table was measured on 2026-12-02. Each table comes from one run of its own sweep, started only once the GPU had held no other process for five minutes and kept only if none appeared while it ran. Speedups are hardware-specific — what cuqml amortises is fixed per-execution overhead, so a card with different launch cost and bandwidth moves every cell, and so does a host, which drives every call either side makes. _bench.header() prints the device it actually ran on, so a sweep you run yourself labels itself with its own hardware.

Every timed number is a median of 5 trials, with the ratio of slowest to fastest in the spread column, but where a column or a cell says otherwise: a first or second call, tensornet’s gradient, and a call slower than two seconds are each timed once. A single shot on this class of GPU varies enough that one number would be a claim the hardware cannot support — check spread before quoting a cell.

max |dK| / max |dE| / max |dg| is how far cuqml and CUDA-Q disagree on the same quantity — the kernel matrix, the forward value, the gradient — not a tolerance the benchmark grants itself. Over a batch it is the worst row: QML compares every row’s value and gradient, and hybrid the whole batch’s. If it exceeds the script’s threshold the speedup column prints MISMATCH instead of a number, so a fast wrong answer can never be reported as a win. In practice it sits around 1e-06, which is the fp32 accumulation floor — and around 1e-15 at fp64. Shots cannot be compared that way, so tensornet_sweep.py --shots reports min p instead, the chance its worst moment is that far out by luck, and prints MISMATCH under 0.001.

>VRAM means the cell was refused before it ran. An oversized cell thrashes the allocator for minutes rather than raising, so fits_in_vram declines it up front. In tensornet_sweep.py the refusal is the contraction’s own sizing, which cuqml makes before it allocates anything, and the cell reads refused: >VRAM. >RAM is a refusal of the same kind for host memory: hybrid_sweep.py declines a default.qubit tape that needs half or more of the memory the host reports free (SC_AVPHYS_PAGES). That count leaves out the page cache, so a declined tape may have fitted after all, and whether one is declined depends on what the host has cached.

Speedups are not a single headline number. They depend on n, on the batch, and on which effect is in play — that is the reason this is seven sweeps and not one. A number quoted without its cell is not meaningful.

Layout

file

what it is

_bench.py

timing — medians, a first call, a call slow enough to time once, a gradient — the VRAM guard, the command-line options, the tolerance and the speedup-or-MISMATCH cell, table/CSV output, figures, and the shared cudaq_gradient baseline

_circuits.py

circuit families generated per size — hea, qaoa, feature_map, hybrid — the observables ising, mixed, probe, and scale, the sum of an observable’s coefficients

_cutensornet.py

cuTensorNet’s network API through ctypes, from the library CUDA-Q ships, for cutensornet_sweep.py

qsvm_sweep.py vqa_sweep.py qml_sweep.py hybrid_sweep.py kernel_form_sweep.py tensornet_sweep.py cutensornet_sweep.py

the seven sweeps

*.csv figures/

the published numbers — *_fp64.csv at fp64, *_ours.csv along cuqml-tensornet’s paths — and the charts each run drew

@cudaq.kernel recovers its own source with inspect, so a kernel cannot be built by closure. _circuits.py generates the source text and registers it with linecache, which is what lets one definition serve every size in a sweep without writing a file per cell.