Developing cuqml
Mostly read-only. This file is not edited in passing. A change to it is agreed with the repository’s authors first.
For anyone, person or agent, who is about to change this repository. This file says what is expected of a change and when. How to verify and how to benchmark is in procedure.md.
CLAUDE.md/AGENTS.md are one text under two names, and
equal. They hold the design methodology: the project’s spirit, its position beside CUDA-Q
and its strategy. This file is how that methodology is applied to a change. It follows them
and replaces nothing: where it and CLAUDE.md/AGENTS.md differ, they govern.
1. Before you start
Read status.md: the baseline to branch from, what is implemented and what is verified, and what is open.
Read known-limits.md, so that a known limit is neither reported as a defect nor built by accident.
Work on a new branch on top of the baseline that
status.mdnames.
2. Code map
Where each responsibility lives. The last column is where the repository describes it; this table restates none of it.
Part |
Responsibility |
Described in |
|---|---|---|
|
The four public names, and the import-order guard |
api.md › The whole public surface and Import order |
|
The four public calls: checks the arguments, captures a kernel into a program, runs it on the engine the target names |
how-it-works.md › From a CUDA-Q kernel to a differentiable program |
|
Reads a kernel’s IR: what follows an argument’s value, and angle arithmetic lifted into torch |
the same section |
|
The Python side of the two CUDA-Q targets: takes the gates the plugin buffers, owns the state |
its module docstring |
|
The NVQIR plugin CUDA-Q loads. Holds no state: buffers gates and calls |
its header comment |
|
The target build and the two target files: at |
its module docstring |
|
The circuit builder, the gate matrices, the batched state vector |
their module docstrings |
|
Fuses and schedules a circuit into kernel operations, and applies them: the state vector’s forward pass |
how-it-works.md › The kernels |
|
State vector: expectation values, the adjoint sweep, parameter shift |
how-it-works.md › The gradient |
|
The tensor-network engine behind |
how-it-works.md › The tensor network |
|
What a call needs of GPU memory, and whether it fits |
its module docstring |
|
Drawing shots from a state |
its module docstring |
|
Dispatch from an operation’s name to its kernel |
its module docstrings |
|
Finds the toolchain, builds and loads the kernels, wraps each one |
|
|
The CUDA kernels |
how-it-works.md › The kernels |
|
The checks |
procedure.md, part A |
|
The sweeps, their CSV files and figures |
procedure.md, part B |
|
The API reference, how the engine works and these records; the generated page and, under |
|
|
The guide to using cuqml |
its |
Dependencies point one way. _torch.py uses _ir.py, _bridge.py, core/ and
cute/ops.py; _bridge.py uses core/ and cute/ops.py; core/ uses cute/ops.py. No
Python module under core/ or cute/ imports _torch.py or _bridge.py. The plugin,
cute/nvqir_cuqml.cpp, reaches Python only through _bridge.py.
Three contracts cross a boundary, and a change on one side of one has to be made on the other:
Plugin to bridge.
nvqir_cuqml.cppcalls functions of_bridge.pyby name, with plain Python types in and out. Both files describe it at their top.Surface to engine.
_torch.pyhands each engine the circuit of a captured program, aCompiledCircuitor aNetwork;_Programin that file says what a program holds beside it.Wrappers to kernels. A kernel source that binds symbols does so through a
register_*hook, called from the one module definition incsrc/cute_kernels.cu.ops.pyfails the build if a source defines a hook that is not called there. A source with no hook is not checked: the primitives are bound bycsrc/bindings.cu.
3. Making a change
Put it where it belongs. The engine goes under
cuqml/, kernels undercuqml/cute/, checks underverify/, measurements underbenchmarks/. A new folder is never added quietly: whoever proposes one, agent or human, restates the rule (CLAUDE.md/AGENTS.md§1), says why the existing shape cannot hold the work, and adds it only after the human confirms (section 4).An addition leaves everything that exists as it was. A new backend, target, precision, API or option changes nothing for code that does not use it: every existing call takes the same arguments, returns the same results, refuses the same things and runs no slower (
CLAUDE.md/AGENTS.md§7). This is shown, not assumed. The wholeverify/set passes on the commit, not only the script written for the change. Where the change touches a path that existing calls run through, such as capture, the compiler, a shared kernel or memory sizing, the sweeps that cover that path are measured again as procedure.md part B says. A change that helps its own case and slows or alters another is not finished. Where existing behaviour does have to change, that is the human’s decision, taken before the work (section 4).New work arrives with new checks. Add a new file under
verify/, or new checks to the script that already covers that surface, written as procedure.md part A says. New work without a check is not finished. New checks are aligned against more of CUDA-Q’s and PyTorch’s official APIs, so the verified surface grows with the code instead of lagging behind it.No check is deleted (
CLAUDE.md/AGENTS.md§6). A removed check is a result that quietly stops being verified, and nothing in the repo will say so. One believed wrong is fixed in place, with the reason beside it.A claim about speed brings a sweep, measured as procedure.md part B says.
A clean-up is proposed, not waited for. Nothing triggers one on its own, so raise it: an agent proposes a clean-up from time to time, after a run of merges or when a directory has visibly accumulated, rather than waiting to be asked. Where files overlap in what they do, propose collapsing them into one. Each removal and each collapse is the human’s decision (section 4). Afterwards the whole of procedure.md part A is run again, and the result is held to the bar of any addition: every check passes and the generic case costs no performance (
CLAUDE.md/AGENTS.md§9).A change to what a public call accepts, returns or refuses updates that call’s section of api.md in the same change, and known-limits.md if a limit appears or goes. A change to how the engine works updates how-it-works.md.
Before renaming or removing a heading of
README.md, look indocs/src/template.md: the generated page cites README headings by name, and at its next run the generator refuses one that is missing.The generated page is not edited by hand.
docs/cuqml-beside-cudaq.mdis regenerated asdocs/src/CONTRACT.mdsays.Neither
CLAUDE.md/AGENTS.mdnor this file is edited in passing. A change to the rules is the human’s, made to both files so that they stay identical. A change to this file is agreed with the repository’s authors first.
4. Decisions
Some choices are the human’s to make, not an agent’s. CLAUDE.md/AGENTS.md §10 lists them:
changing
scope, choosing between designs, adding to the public surface, adding a top-level folder,
building what no actual need calls for, removing or deprecating a capability, and anything
destructive or irreversible. Add to that list any exception to verification: skipping a
script, or changing a bar.
Ask before the work that depends on the answer. Say what needs deciding, what you found, the options with what each costs, and which you recommend. Carry on with whatever does not depend on it.
Record the answer where the next developer will find it: in the commit message of the change it governs, and in status.md when it changes the state or the open items.
A proposal stays marked as a proposal until it is answered. No answer is not a yes.
5. Verify and review
Three words are kept apart:
Implemented: the change is made.
Verified: the checks were run on that commit, and the result is recorded in status.md.
Accepted: the human has approved it.
A commit message that says the checks pass is a claim. It becomes a record when the run is in
status.md.
The author of a change does not verify it. Hand verification to a freshly started agent, or to another person, that is given procedure.md and the commit and nothing else: not the conversation, and not the author’s reasoning. Its context is then its own. It runs part A in full and writes the report.
Someone other than the author reviews the change with its checks against what was asked: cases left out, and checks that only repeat what the code assumes.
A bar is never loosened and a check never removed to get a pass.
6. Handoff
Before you stop, whether a session is ending, the work is being handed over or it has landed, bring status.md up to date:
the baseline, if it moved;
what changed, under its branch;
the verification run, as a row of its table, or a plain statement that none was made;
the open items: add what you found or left unfinished, remove what you closed;
the next action.
Whatever the next developer needs in order to continue belongs in that file, not only in a conversation.