mimiqcircuits.operations.annotations

Circuit annotations (Detector, QubitCoordinates, etc.).

Classes

AbstractAnnotation()

Base class for circuit annotations.

AncillaAlloc()

A marker recording that a qubit is in |0> here and is used as a clean ancilla from here on.

AncillaFree()

A marker recording that a clean ancilla is back in |0> here and is free for reuse.

Detector(*args)

Annotation marking a set of measurement bits whose parity is deterministic.

Lost()

Marker recording that a qubit was lost at this point.

ObservableInclude(*args)

Annotation adding measurement bits to a logical observable.

QubitCoordinates(*args)

Annotation giving the spatial coordinates of a qubit.

Reloaded()

Marker recording that a qubit was reloaded at this point.

ShiftCoordinates(*args)

Annotation shifting the coordinates of later annotations.

Tick()

Annotation marking the boundary between two time steps.

class Detector(*args)[source]

Bases: AbstractAnnotation

Annotation marking a set of measurement bits whose parity is deterministic.

A detector covers N classical 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): N bits, no notes.

  • Detector(N, notes): N bits with a list of notes.

  • Detector(N, n1, n2, ...): N bits with integer notes.

  • Detector(notes): a lazy expression that takes N later.

Raises:

ValueError – If the arguments match none of the forms above, or N is less than 1.

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]
static opname()[source]

Return "Detector".

get_notes()[source]

Return the notes attached to the annotation, as a list of floats.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

class QubitCoordinates(*args)[source]

Bases: AbstractAnnotation

Annotation 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.

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]
static opname()[source]

Return "QubitCoordinates".

get_notes()[source]

Return the coordinates of the annotation, as a list of floats.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

class ShiftCoordinates(*args)[source]

Bases: AbstractAnnotation

Annotation 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.

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)
static opname()[source]

Return "ShiftCoordinates".

get_notes()[source]

Return the coordinates of the annotation, as a list of floats.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool

class ObservableInclude(*args)[source]

Bases: AbstractAnnotation

Annotation 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. ObservableInclude adds the N bits 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): N bits, no notes.

  • ObservableInclude(N, notes): N bits with a list of notes.

  • ObservableInclude(N, n1, n2, ...): N bits with integer notes.

  • ObservableInclude(notes): a lazy expression that takes N later.

Raises:

ValueError – If the arguments match none of the forms above, or N is less than 1.

Examples

>>> 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]
static opname()[source]

Return "ObservableInclude".

get_notes()[source]

Return the notes attached to the annotation, as a list of ints.

iswrapper()[source]

Whether the operation wraps another operation.

True for composite operations such as Control, Power, Inverse, Parallel or IfStatement, False otherwise.

Returns:

bool