Known limits

What cuqml does not do, at a glance. docs/api.md and docs/cuqml-beside-cudaq.md say why, and what to write instead.

  • No noisy simulation. A noise model is refused on both targets.

  • No state from your own amplitudes. Circuits start from |0...0> and get there by gates.

  • One GPU. Nothing is split over several GPUs or run on the CPU, and nothing spills to host memory: what does not fit runs in slices where the engine can slice it, and is refused otherwise.

  • On cuqml-tensornet: currently no slicing and no approximation. A contraction is exact and is not cut to fit. There is also no whole state, no mid-circuit collapse or reset, and at most 63 measured qubits in sample_batch.

  • A second derivative only by reverse mode on cuqml-tensornet. The state vector refuses one, and neither target has forward-mode AD.

  • Batched calls vary list[float] and float arguments per row; an argument of another type is one value for every row, a circuit per value. Those fixed arguments are int, bool, list[int], list[bool], cudaq.pauli_word, list[cudaq.pauli_word], complex and list[complex]; any other type, a kernel passed as an argument among them, is refused by name. TorchLayer’s kernel takes exactly one list[float], beside fixed arguments in args=. A branch, a loop bound or a qubit index that follows the value of a list[float] or float argument is refused, and an angle may be computed from the arguments only by arithmetic that can be lifted into torch. A kernel that computes an angle calls no other kernel. Where CUDA-Q hands a simulator other gates than the kernel writes, a kernel whose angles have to be lined up with them is refused by name for what the item on rotations of one gate that meet on a qubit says.

  • Beside an angle the kernel computes, a branch that a fixed argument or a captured value takes is refused. It stays a branch through CUDA-Q’s passes, so its gates have no single order. One that a bool, an int or a list’s length does not take, with no else, folds away, and the kernel is answered; one on a list’s element or a complex, which are not written in, is refused whether it is taken or not. So is one on a loop’s counter or an argument’s length that is taken.

  • Of a fixed argument, a bool, an int and a list’s length are written into the IR an angle is read from, and nothing else. Arithmetic on a list’s element or on a complex is refused by name, as on a captured value of the same kind, and so is a word of a list[cudaq.pauli_word] where rotations are lined up. A cudaq.pauli_word argument’s word is read from its value.

  • A read outside a list is refused where it is told from the IR, and answered as CUDA-Q answers it elsewhere. A kernel’s own read of a list[float] argument, a fixed list or a list it captured from Python — the outer list, where it captured a list of lists — at an element outside the list the call hands it, is refused by name where the read runs whenever the kernel does, at an index that is a number once CUDA-Q’s passes have run, as in a loop of fewer than 50 passes, which they unroll; or, in a loop of 50 or more passes whose start, bound and step are numbers, at the loop’s count times a number plus a number. Not judged: a read in a kernel it calls; in a branch no number decides, as if i < 5: on the count of a loop of 50 or more passes; in a loop CUDA-Q cannot count, or one that holds a break, a continue or a return, or after a return a branch takes; in a loop whose start or bound moves with the count of a loop of 50 or more passes, as for j in range(i + 1) inside for i in range(60); at an index computed from a loop’s count otherwise than as a multiple of it plus a number, as theta[i % 7], or from the counts of two loops of 50 or more passes, as theta[50 * l + i], or theta[j] for j in range(i, i + 50), which CUDA-Q counts from 0 and adds to i; at an index read from a list; and in an inner list of a captured list of lists, as LL[1][2]. There CUDA-Q reads whatever lies in memory outside the list, about 0 more often than not, and cuqml is handed it at capture: such a kernel is answered as if the missing elements were about 0, as CUDA-Q itself mostly answers it, and refused where what lies there moves between capture’s probes.

  • Under explicit_measurements=True, gates written after the last measurement can get a kernel refused. CUDA-Q draws no shot from them. sample_batch refuses a kernel by name for what is written there on a gate and qubit with a rotation before the draw, as docs/api.md lists.

  • An expectation refuses a measurement in a called kernel wherever it runs. cudaq.observe’s check reads the kernel it is handed alone, and cudaq.observe answers such a kernel, collapsing call by call. observe_batch and TorchLayer with observables refuse it by name, even where the measurement changes nothing cudaq.observe returns: a qubit certain to read one outcome, a fresh qubit the called kernel takes, a qubit in a product state with the ones observed. Where cudaq.get_state returns one state for such a kernel, its gradient and its cuqml-tensornet state are refused too.

  • Rotations of one gate that meet on a qubit. CUDA-Q hands rotations that meet to a simulator as one, at the sum of their angles, made in float64 from the last written to the first, and leaves out gates that cancel. Where a kernel’s angles are read from its IR, cuqml lines the two up qubit by qubit and builds each merged angle as CUDA-Q sums it, from the rotations that stand together on the qubit: at fp64 it is CUDA-Q’s number to the last bit at capture’s probes, its terms computed as the C library CUDA-Q’s kernel calls computes them. Where CUDA-Q may hand over something else, the kernel is refused by name: where what it hands over on a qubit a rotation acts on is not what is written there — gates that cancel, two h or two x in a row, left out, or rotations handed over across a gate they commute with, the qubit a controlled x’s target or a control on an rz’s qubit; where constants come to whole turns of their gate, 4π for rx, ry and rz and 2π for r1, to within 1e-12, or to nothing, however many stand together, or a rotation and its adjoint at one angle stand with nothing but rotations of their gate between them, which CUDA-Q drops or sums in, in an order of its own; where a term that is nothing at the probes stands last before a gate the rotations commute with, so that it reads on either side of it; and at fp64 where a merged angle has a term computed through a function other than +, -, *, /, sqrt, a sign, a magnitude, the larger or the smaller of two and a rounding to single precision, which torch computes otherwise than that library. Where every angle reads as an argument, one negated or a constant, the kernel is run as read. On a line — one gate’s rotations on one qubit under the same controls — that holds a rotation at an argument’s angle, the rotations written are counted against those CUDA-Q hands over, read through the kernels it calls, its scopes, the branches CUDA-Q decides before it runs and the loops CUDA-Q counts. Where it hands over fewer, the kernel is refused by name if the line holds constants that come to whole turns or nothing, a row of any length in order on the line whatever stands between them, or a rotation and its adjoint at one angle, or a rotation at a number that is not read to the bit, such as one a called kernel returns or the sine of a number, which the C library computes; and where the line cannot be counted: a loop CUDA-Q cannot count, a branch on what is not known before the kernel runs or on what cuqml does not evaluate, or a number stored in one. Where it hands over as many, the count says nothing was summed only if the line read is CUDA-Q’s, and that rests on what was measured of CUDA-Q 0.16: that it numbers the registers a kernel allocates at its top level first, in order, where each has a size written in it, and any other qubit when it reaches it; that cudaq.control puts its controls on the called kernel’s rotations, and NVQIR on an exp_pauli’s rz alone. So each rotation handed over there has to be the one written there, in order, at both probes, and a line read otherwise is refused by name where the two differ there, as where integer arithmetic past 64 bits decides a branch in the kernel called. Where the reading leaves out just the constants CUDA-Q sums to nothing into a rotation at an argument’s angle, the two do not differ, and the next item says where that answers a kernel wrong. A qubit cuqml gives no number — one a called kernel, a loop or a branch allocates, or a top-level one after such a qubit beside a register sized at run time — is counted only with the others of its gate on such qubits, and where CUDA-Q hands over fewer of those, on which qubit is not told, and the kernel is refused by name. These refusals do not depend on where the probes fall, and kernels CUDA-Q answers are refused with them: a re-uploading layer round a controlled x’s target, a QAOA layer whose rz stands before and after its qubit controls an x, constants that come to whole turns or nothing on the line of a rotation at an argument’s angle where CUDA-Q sums or drops any of the line’s rotations — dropped by CUDA-Q before a list element read at its gate, 96 of them or 17, as well as summed into one, and wherever on the line they stand: after the argument’s rotation, as a row CUDA-Q only drops, across a gate CUDA-Q merges nothing across, such as a cz pair, a controlled h or a doubly controlled x, or across whole turns of another gate — a rotation and its adjoint CUDA-Q only drops, a choice stored on either side of a branch on a number a called kernel returns, and rotations of a gate on an ancilla a called kernel allocates where CUDA-Q merges any of them beside one at an argument’s angle on such a qubit, as ry(π/2) and ry(π/4) that prepare it before ry at an argument; a branch on two booleans of a captured value put in order, which cuqml decides otherwise than CUDA-Q, true below false; a branch on an integer power past its type or to a negative exponent, or on int() of a float that lands outside its type; in a kernel where cuqml computes a number otherwise than CUDA-Q, as the next item says, a loop that changes a value carried beside its count or steps the count in its body, a branch on a float’s truth, int() of a float or an integer power, and an exp_pauli by a word from a list; two h on a qubit a rotation acts on though nothing crosses them, a term that is nothing at the probes before a gate its rotations commute with, and ry(BIAS, q) with a captured BIAS = 0.0 beside rotations that meet. Each constant written before a rotation at an argument’s angle that meets it costs one addition at every call, and a kernel that writes one rotation gate both at an argument’s angle and at a number, or plain and .adj at one, is read on its first call, through the kernels it calls — a loop CUDA-Q leaves whole read once for all its passes, where nothing in it moves with its count but the column of an argument it picks, and once for each pass where an angle it holds on a held line moves otherwise; a kernel that calls others with nothing but its arguments’ values is not read.

  • A known wrong answer: a called kernel’s branch, loop count or qubit decided by a parameter CUDA-Q folds otherwise than cuqml reads it. A kernel calls another — directly, through cudaq.adjoint or through cudaq.control — and hands one of its int or bool parameters a number CUDA-Q fixes when it compiles the call: a literal, or the count of a loop it unrolls. The called kernel decides by that parameter whether rotations run, how many times, or on which qubit, through two booleans put in order — <, <=, > or >= between two comparisons — which CUDA-Q folds as signed one-bit integers, true below false, or through integer arithmetic past 64 bits, which CUDA-Q wraps and cuqml computes in Python’s integers. cuqml reads the other side. Where the side CUDA-Q takes holds constants it sums to nothing into a rotation of the same gate at an argument’s angle, on the same qubit under the same controls, the line cuqml reads holds just the rotations CUDA-Q hands over, each the one written there at capture’s probes, so neither the count nor the check of each rotation sees the sum, and the kernel is answered with the argument’s angle where CUDA-Q runs its float64 sum with the constants. Measured on CUDA-Q 0.16 with 99 constants of about 1e-11 beside an argument near 1e5: 1.2e-10, under cudaq.control, to 4.1e-10, beside an angle written .adj, from CUDA-Q’s answer at fp64, the worst of a kernel’s rows, on cuqml and cuqml-tensornet, in batched calls and in a TorchLayer; at fp32 the answers stay inside its bar. The same decision in the kernel called is read as CUDA-Q runs it, or refused by name; and a kernel where cuqml computes such a number is read without what cuqml reads only where it computes none — the loops, branches and words the item above lists — so that none of them is decided by it.

  • A computed angle is computed by torch. Arithmetic on the arguments runs in torch, on the GPU, whose sin, exp, arctan and the like can differ from the C library CUDA-Q’s compiled kernel calls in the last bit. Arithmetic that amplifies such a difference carries it into the answer: near b = 1, rx(1.0 / (np.exp(b) - np.e), q) was measured 3.2e-6 from CUDA-Q’s answer and rx(1.0 / (np.sin(b) - np.sin(1.0)), q) 6.9e-7. This predates the lining-up of angles. A rounding to single precision would carry such a difference into a whole single-precision step, and the C library’s own single-precision functions differ from torch’s rounded results at as many as one row in sixteen, measured: at fp64, an angle rounded from a value computed through a function other than +, -, *, /, sqrt, a sign, a magnitude, the larger or the smaller of two is refused by name, and answered at fp32.

  • State vector (cuqml): rx, ry, rz, r1 and u3 take an angle from an argument under at most 4 controls. Under 5 or more a batched call refuses the kernel by name, and cuqml-tensornet runs it. Custom operations run on 1 or 2 targets under up to 4 controls, or on 3 or 4 targets uncontrolled, and on nothing else.

  • No batched cudaq.run, and no gradient of samples or of a shot estimate.

  • A kernel built with cudaq.make_kernel is not yet supported by the batched calls. They take @cudaq.kernel kernels. CUDA-Q’s own calls run a built kernel on both targets.

  • For sampling on the state vector, cuqml, at 25 qubits or more, use option="fp64". At fp32, the default, sampled frequencies drift from the exact ones as the state grows; at fp64 they do not.

  • A CUDA-Q installation that this user cannot write, without password-free sudo, cannot take the targets. CUDA-Q reads targets only from its own tree, so import cuqml installs them there; where it cannot, the import fails naming the tree, and the command its owner runs after each install or upgrade of cuqml or CUDA-Q to install them.

  • A process can go on with the targets it read before a rebuild, unrefused. CUDA-Q reads its targets once, when cudaq is imported, so a process that imported cudaq before cuqml is refused where its own import of cuqml finds the targets stale, and at every import after that. Two cases are not caught. A process that imported cudaq, or loaded the plugin, before another process rebuilt the targets goes on with what CUDA-Q read: its imports of cuqml after the rebuild find the targets current, and any part of cuqml it imports after an upgrade is the upgraded one. And a program compiled with nvq++ has no cudaq module, so where its plugin was stale, the import of cuqml it makes rebuilds the targets and is not refused, while the program runs the plugin it loaded. Start such a process again after upgrading cuqml or CUDA-Q.