RFC3: Move Delay value storage to a typed arena#16242
Draft
ihincks wants to merge 4 commits into
Draft
Conversation
3 tasks
The previous commit's diff modified `lib.rs` to reference a new `delay_arena` module but the file itself was never staged, breaking every CI job that builds the workspace. Also brings `test/c/test_circuit.c` in line with the project's `clang-format` configuration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`qk_circuit_delay_dt` and `qk_circuit_get_delay` are exported from the C header but were missing from `cext-vtable`'s export list, which the binding-vs-slot lint flagged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`CircuitInstruction.params` (the Python property) was returning an empty list for delays after the arena refactor moved the duration off the Rust params list. The Python data model still expects a one-element list, so materialize it on demand from the `DelayHandle` here — same "lie at the boundary" pattern already used by `StandardInstruction::create_py_op`. Caught by `test_can_transpile_circuits_with_assigning_parameters_inbetween`, which reads `circ.data[1].params[0]` directly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Coverage Report for CI Build 26299637026Coverage decreased (-0.03%) to 87.461%Details
Uncovered Changes
Coverage Regressions17 previously-covered lines in 7 files lost coverage.
Coverage Stats
💛 - Coveralls |
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.
This PR is one of three RFCs solving the same problem: dt-unit delays panic in
qk_circuit_get_instructionbecause their integer duration is stored asParam::Obj(PyAny).This branch takes the most surgical fix. Delay durations leave the
Paramlist entirely and move into a typed global arena (crates/circuit/src/delay_arena.rs). The arena holds aDelayDurationenum (Int,Float,Expr,PyObj) inside refcountedSlots, andStandardInstruction::Delay(DelayHandle)replacesStandardInstruction::Delay(DelayUnit). Standard gates and other instructions are untouched — only the Delay variant knows about durations now.The C API gets
qk_circuit_delay_dt(qubit, i64)andqk_circuit_get_delay(idx, *unit, *kind, *vi, *vf)with aCDelayDurationKindenum that distinguishes integer, float, and expression durations. QPY format is unchanged — the writer synthesizes a durationParamfrom the handle when it serializes a Delay, and the reader builds a fresh handle fromparam[0]on read.The trade-off is implementation complexity.
StandardInstructionlosesCopyand gets a manualPartialEq.PackedOperation::cloneanddropspecial-case the Delay case to bump and release the refcount. TheBox<Slot>indirection in the arena is load-bearing —with()snapshots a*const Slotthen drops the read guard. There's a newParameterUse::DelayDurationvariant for symbolic durations that the parameter table needs to track separately.The other two RFCs are #16226 (a minimal
int → floatcoercion patch) and #16241 (a uniformParam::Intvariant that touches every match overParam).Partially addresses #16121.
AI/LLM disclosure