microsoft / microsoft/qdk-ec

qodec: Add typed Python builders for parity references

Open
#181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
64
Forks
16
Avg merge
1d 5h
Merged PRs (30d)
5

Description

Is your feature request related to a problem? Please describe.

Writing gadget checks means spelling reference paths by hand:

checks = [
		["circuit.readouts[0:2]", "in[0].stabilizers[0]"],
		["circuit.readouts[0,2]", "out[0].z[0]"],
]

An editor cannot complete stabilizers inside a string. A typo is found only
when Reference parses it, and authors must format selectors themselves.

Describe the solution you'd like

Add typed helpers that build ordinary Reference values. Proposed API,
not currently available:

from qodec.gadgets import circuit, inputs, outputs, readouts

checks = [
		[circuit.readouts[0:2], inputs[0].stabilizers[0]],
		[circuit.readouts[0, 2], outputs[0].z[0]],
]

Each expression uses the existing reference spelling:

assert inputs[0].stabilizers[1].path == "in[0].stabilizers[1]"
assert circuit.readouts[0:6:2].path == "circuit.readouts[0:6:2]"
assert circuit.readouts[2, 0, 2].path == "circuit.readouts[2,0,2]"
assert readouts[0].path == "readouts[0]"

Encoding positions take one zero-based index. Final selectors accept an index,
a bounded slice with a positive step, or a tuple. Preserve tuple order and
duplicates, and keep slices compact until expansion is requested. Invalid
types, Boolean indices, negative indices, and empty selections should raise.

Reuse the existing Rust-backed Reference parser rather than adding another
grammar. Construction checks syntax, not whether the selected stabilizer
exists. Strings remain supported; no circuit parsing or on-disk format change
is needed.

Describe alternatives you've considered

  • Keep strings: no new API, but no completion for properties or selectors.
  • Use factory methods on Reference: fewer proxy objects, but potentially
    longer expressions. Compare their readability and editor support with subscripts.
  • Add methods to Encoding: an encoding does not know its position in a
    gadget, so it cannot construct the whole reference by itself.

Additional context

The sketch adds four exports in qodec.gadgets; helper implementation types
stay private, and no top-level aliases are needed:

  • circuit matches the reference root rather than the obsolete term body.
  • inputs and outputs match the gadget accessors rather than in_ and out_.
  • readouts includes flags; outcomes would suggest the action-guard index space.

This is separate from unifying Reference and model-path resolution: builders
construct addresses; resolve follows them. Settle path spelling with that work
before finalizing these helpers. The examples above use the current parity
grammar. Keep runtime exports, type annotations, and stubs consistent so the
helpers actually provide useful completion.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the qodec.gadgets exports and the existing Rust-backed Reference parser, then review how current parity paths and resolve are separated. Compare the proposed subscript helpers with the factory-method alternative, including the stated selector validation rules. Done means consistent runtime exports, type annotations, and stubs, with paths matching the examples without changing circuit parsing or on-disk formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
backend-api-design, developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.