Skip to content

Give stimcirq annotations a gate so they can be included in gatesets - #1120

Merged
Strilanc merged 1 commit into
quantumlib:mainfrom
senecameeks:u/smeeks/annotations_subclass_gate
Oct 12, 2026
Merged

Strilanc merged 1 commit into
quantumlib:mainfrom
senecameeks:u/smeeks/annotations_subclass_gate

Conversation

@senecameeks

Copy link
Copy Markdown
Contributor

stimcirq.DetAnnotation, stimcirq.CumulativeObservableAnnotation and stimcirq.ShiftCoordsAnnotation are cirq.Operations whose gate was None. As a result they can't be matched by a cirq.GateFamily, so they are rejected by gateset-based validation such as cirq_google.GridDevice, and circuits converted from stim can't be validated against hardware devices.

This adds a gate form for each annotation (stimcirq.DetAnnotationGate, stimcirq.CumulativeObservableAnnotationGate,
stimcirq.ShiftCoordsAnnotationGate) which is returned by the annotation's gate property, similar to how cirq.GlobalPhaseGate relates to global phase operations. Applying the gate to qubits returns the annotation. Devices can now explicitly allow annotations, e.g.
cirq.Gateset(..., stimcirq.DetAnnotationGate).

The annotations themselves remain plain cirq.Operations (rather than also subclassing cirq.Gate) because cirq's simulators treat anything that is a cirq.Gate as needing explicit qubits in cirq.act_on, which raises for operations.

`stimcirq.DetAnnotation`, `stimcirq.CumulativeObservableAnnotation` and
`stimcirq.ShiftCoordsAnnotation` are `cirq.Operation`s whose `gate` was
`None`. As a result they can't be matched by a `cirq.GateFamily`, so they are
rejected by gateset-based validation such as `cirq_google.GridDevice`, and
circuits converted from stim can't be validated against hardware devices.

This adds a gate form for each annotation (`stimcirq.DetAnnotationGate`,
`stimcirq.CumulativeObservableAnnotationGate`,
`stimcirq.ShiftCoordsAnnotationGate`) which is returned by the annotation's
`gate` property, similar to how `cirq.GlobalPhaseGate` relates to global phase
operations. Applying the gate to qubits returns the annotation. Devices can now
explicitly allow annotations, e.g.
`cirq.Gateset(..., stimcirq.DetAnnotationGate)`.

The annotations themselves remain plain `cirq.Operation`s (rather than also
subclassing `cirq.Gate`) because cirq's simulators treat anything that is a
`cirq.Gate` as needing explicit qubits in `cirq.act_on`, which raises for
operations.

@Strilanc Strilanc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I like the boilerplate but if this is actually causing trouble with interop then it's important to fix.

@Strilanc
Strilanc merged commit e51d048 into quantumlib:main Oct 12, 2026
57 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.

2 participants