mimiqcircuits.operations.annotations¶
Circuit annotations (Detector, QubitCoordinates, etc.).
Classes
|
Base class for circuit annotations. |
|
A marker recording that a qubit is in |
|
A marker recording that a clean ancilla is back in |
|
Annotation marking a set of measurement bits whose parity is deterministic. |
|
Marker recording that a qubit was lost at this point. |
|
Annotation adding measurement bits to a logical observable. |
|
Annotation giving the spatial coordinates of a qubit. |
|
Marker recording that a qubit was reloaded at this point. |
|
Annotation shifting the coordinates of later annotations. |
|
Annotation marking the boundary between two time steps. |
- class Detector(*args)[source]¶
Bases:
AbstractAnnotationAnnotation marking a set of measurement bits whose parity is deterministic.
A detector covers
Nclassical bits holding measurement results. In a noiseless run their parity is always the same, so a change in parity signals an error. Detectors are used by error-correction tools and in Stim export; they do not change the circuit’s state.The notes are optional numbers attached to the detector, usually its coordinates.
The constructor accepts:
Detector(): one bit, no notes.Detector(N):Nbits, no notes.Detector(N, notes):Nbits with a list of notes.Detector(N, n1, n2, ...):Nbits with integer notes.Detector(notes): a lazy expression that takesNlater.
- Raises:
ValueError – If the arguments match none of the forms above, or
Nis less than 1.
See also
Examples
>>> from mimiqcircuits import * >>> c = Circuit() >>> # measure two qubits >>> c.push(Measure(), 0, 0) 1-qubit, 1-bit circuit with 1 instruction: └── M @ q[0], c[0] >>> c.push(Measure(), 1, 1) 2-qubit, 2-bit circuit with 2 instructions: ├── M @ q[0], c[0] └── M @ q[1], c[1] >>> # declare that the parity of bits 0 and 1 is deterministic, >>> # with coordinates (1.0, 0.5) as notes >>> c.push(Detector(2, [1.0, 0.5]), 0, 1) 2-qubit, 2-bit circuit with 3 instructions: ├── M @ q[0], c[0] ├── M @ q[1], c[1] └── Detector(1.0, 0.5) @ c[0:1]
Passing only the notes gives a lazy detector; call it with the number of bits:
>>> op = Detector([0.1, 0.9]) >>> op lazy Detector(?, [0.1, 0.9]) >>> op(1).get_notes() [0.1, 0.9]
- class QubitCoordinates(*args)[source]¶
Bases:
AbstractAnnotationAnnotation giving the spatial coordinates of a qubit.
Applied to one qubit. The coordinates do not affect simulation; they describe the physical layout for visualization and export.
QubitCoordinates(coords)takes a list of numbers, stored as floats.QubitCoordinates()returns a lazy expression that takes the list later.- Parameters:
coordinates (list) – The coordinates of the qubit.
- Raises:
ValueError – If the argument is not a single list.
See also
Examples
>>> from mimiqcircuits import * >>> QubitCoordinates([0.5, 0.75, 1.0]) QubitCoordinates(0.5, 0.75, 1.0) >>> op = QubitCoordinates([0.5, 0.75, 1.0]) >>> op.get_notes() [0.5, 0.75, 1.0] >>> # place qubit 0 at (0.2, 0.3) >>> c = Circuit() >>> c.push(QubitCoordinates([0.2, 0.3]), 0) 1-qubit circuit with 1 instruction: └── QubitCoordinates(0.2, 0.3) @ q[0]
- class ShiftCoordinates(*args)[source]¶
Bases:
AbstractAnnotationAnnotation shifting the coordinates of later annotations.
Takes no qubits or bits. The offsets are added to the coordinates of the qubit and detector annotations that follow it, and successive shifts accumulate. It does not affect simulation.
The offsets can be given as separate numbers or as one list.
ShiftCoordinates()returns a lazy expression that takes the list of offsets later.- Parameters:
*coordinates – The offsets, as numbers or a single list.
- Raises:
ValueError – If the arguments are neither numbers nor a single list.
See also
Examples
>>> from mimiqcircuits import * >>> ShiftCoordinates(0.1, 0.2, 0.3) ShiftCoordinates(0.1, 0.2, 0.3) >>> ShiftCoordinates([0.4, 0.5]) ShiftCoordinates(0.4, 0.5) >>> ShiftCoordinates(0.4, 0.5) ShiftCoordinates(0.4, 0.5) >>> op = ShiftCoordinates(0.1, 0.9) >>> op.get_notes() [0.1, 0.9] >>> c = Circuit() >>> c.push(ShiftCoordinates(0.4, 0.2)) circuit with 1 instruction: └── ShiftCoordinates(0.4, 0.2)
- class ObservableInclude(*args)[source]¶
Bases:
AbstractAnnotationAnnotation adding measurement bits to a logical observable.
A logical observable is a set of measurement results whose combined parity is deterministic in a noiseless run and encodes the value of a logical qubit.
ObservableIncludeadds theNbits it is applied to into an observable. The notes are integers, usually the index of the observable. It does not change the circuit’s state.The constructor accepts:
ObservableInclude(): one bit, no notes.ObservableInclude(N):Nbits, no notes.ObservableInclude(N, notes):Nbits with a list of notes.ObservableInclude(N, n1, n2, ...):Nbits with integer notes.ObservableInclude(notes): a lazy expression that takesNlater.
- Raises:
ValueError – If the arguments match none of the forms above, or
Nis less than 1.
See also
Detector,QubitCoordinates,ShiftCoordinates,TickExamples
>>> from mimiqcircuits import * >>> c = Circuit() >>> c.push(Measure(), 0, 0) 1-qubit, 1-bit circuit with 1 instruction: └── M @ q[0], c[0] >>> # include bit 0 in observable 0 >>> c.push(ObservableInclude(1, [0]), 0) 1-qubit, 1-bit circuit with 2 instructions: ├── M @ q[0], c[0] └── ObservableInclude(0) @ c[0]