Skip to content

feat(circuit): add instruction payload accessors and Python ClassicalDataOp - #54

Merged
jianjian01 merged 4 commits into
cq-lib:release/2.0from
jianjian01:release/2.0
Sep 30, 2026
Merged

jianjian01 merged 4 commits into
cq-lib:release/2.0from
jianjian01:release/2.0

Conversation

@jianjian01

Copy link
Copy Markdown
Collaborator

Changes

  • core (cqlib-core): pair every is_*() predicate on Instruction and ValueInstruction with an Option-returning payload accessor — mc_gate(), unitary_gate(), circuit_gate(), classical_data(), classical_control() return references; directive() returns the Copy payload by value. ValueInstruction delegates to the wrapped Instruction via as_instruction().
  • binding-python: add mc_gate / unitary_gate / circuit_gate / classical_data getters to Instruction and ValueInstruction (payload cloned by value), and register the new ClassicalDataOp class (kind / target / value / result) with its runtime module, type stubs and tests.
  • docs: list the new accessors in the Python and Rust API references (EN + CN); add a ClassicalDataOp section to the classical data / control flow pages and the circuit overview tables.
  • release: bump versions to 0.1.0-beta.3 / 2.0.0-beta3.

Design notes

  • Gate objects returned by instruction-level accessors carry no bound parameters: parameters belong to the operation layer (ValueOperation.params). This matches the pre-rewrite semantics and is now documented.
  • Instruction.classical_control is intentionally not exposed on the Python storage-layer type: the storage-layer ClassicalControlOp inlines circuit-internal handles, so control-flow content is read via ValueInstruction.classical_control (or the DAG). This exception is documented in the API reference.

Pair every is_*() predicate with an Option-returning payload accessor,
so callers can dispatch on the predicate and read the payload without
pattern matching or parsing instruction names:

- Instruction: mc_gate(), unitary_gate(), circuit_gate(),
  classical_data() and classical_control() return references,
  directive() returns the Copy payload by value
- ValueInstruction: mc_gate(), unitary_gate(), circuit_gate() and
  classical_data() delegate to the wrapped Instruction, and
  classical_control() returns the value-level control-flow payload
…calDataOp

- Add mc_gate / unitary_gate / circuit_gate / classical_data getters
  to Instruction and ValueInstruction, cloning the payload by value;
  gate parameters belong to the operation layer (ValueOperation.params)
- Register the new ClassicalDataOp class wrapping core classical data
  ops, with kind / target / value / result getters, its runtime module
  and type stubs
- List the new Instruction / ValueInstruction payload accessors in the
  Python and Rust API references (EN + CN)
- Add a ClassicalDataOp section to the classical data / control flow
  pages and to the circuit overview tables
@jianjian01
jianjian01 merged commit 6c2b8c7 into cq-lib:release/2.0 Sep 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant