QCDL operations: add reset and sxdg, and validate qubit arguments - #72
Open
qci-amos wants to merge 5 commits into
Open
QCDL operations: add reset and sxdg, and validate qubit arguments#72qci-amos wants to merge 5 commits into
qci-amos wants to merge 5 commits into
Conversation
reset(q0) is the operation form of the q0.reset() statement, which was only reachable through __getattr__ and so had no signature, docstring, or importable name. Unlike initialize(), it acts on one qubit and has a deterministic duration, so it is usable inside a conditional branch. The user guide now uses it. sxdg is the adjoint of sx, which was missing from the gate set. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Passing something that is not a qubit surfaced much later as an AttributeError naming an internal attribute, and a two-qubit gate given the same qubit twice built cleanly and was rejected only by the service. _validate_qubit_args wraps every operation and derives the rule from the signature: each named QCDLModule parameter is a separate role, so two of them may not be the same module, whereas a *qubits parameter is a set of qubits where a repeat is harmless. The wrapper keeps the signature and docstring, and defers to python for arity errors. Also adds __all__, so `from ... import *` brings in the operations rather than this module's own imports. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
+ Coverage 90.18% 90.53% +0.35%
==========================================
Files 31 31
Lines 5317 5514 +197
==========================================
+ Hits 4795 4992 +197
Misses 522 522 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JoelPasvolsky
approved these changes
Aug 19, 2026
|
|
||
| from dwave.gate.qcdl import qcdl | ||
| from dwave.gate.qcdl.operations import initialize | ||
| from dwave.gate.qcdl.operations import reset |
Collaborator
There was a problem hiding this comment.
Good catch, thanks!
| @qcdl(1) | ||
| def detect_erasure_example(q): | ||
| erased = q.Register(name="erased") | ||
| def detect_erasure_example(q0): |
Co-authored-by: Joel Pasvolsky <34041130+JoelPasvolsky@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of splitting #71 into reviewable pieces. This one is the
operationsmodule; the other four PRs are independent of it and of each other.
Two commits, reviewable separately.
1. Add
resetandsxdgoperationsresetalready existed asq0.reset(), but only through__getattr__, so ithad no signature, no docstring, and no importable name — the user guide reached
for it in a way nothing else in the guide does. This adds the operation form.
It is an alias for the same statement, not a variant (there is a test asserting
the two produce identical programs).
Unlike
initialize, which loops until every qubit in the program is reset,resetacts on one qubit and has a deterministic duration, so it can be usedinside a conditional branch. The guide's erasure-detection example now uses it.
sxdgis the adjoint ofsxand was simply missing from the gate set.2. Validate the qubit arguments of every operation
Two failure modes were unpleasant:
AttributeError: 'int' object has no attribute 'procedure', naming aninternal attribute rather than the argument at fault.
cx(q0, q0)— built cleanlyand was rejected only once the program reached the service.
_validate_qubit_argswraps every operation and derives the rule from thesignature rather than from a hand-maintained list:
QCDLModuleparameter is a separate role in the operation, sotwo of them may not be the same module;
*qubitsparameter is a set of qubits to act on, where a repeat isharmless (
barrier,initialize).A test asserts those two categories stay disjoint and cover every multi-qubit
operation, so a new operation lands in one of them rather than escaping the
check. Another asserts every operation is actually wrapped.
The wrapper preserves
__name__,__doc__,__module__and the signature, soautodoc is unaffected, and it defers to Python for arity errors so
cx(q0)still reports against the real signature.Also adds
__all__, sofrom dwave.gate.qcdl.operations import *brings in theoperations rather than this module's own imports (
np,inspect,implementations, ...).Compatibility
Code that passed a non-qubit, or the same qubit twice to a two-qubit gate, now
raises
QCDLUserErrorat build time instead of failing later or being rejectedby the service. Nothing that built a valid program changes.
Testing
pytest tests/passes. New tests are parameterized over every operationdiscovered by introspection, so they cover gates added later too.
🤖 Generated with Claude Code