mimiqcircuits.operations.losschannel

Loss-channel operations.

Classes

Check()

Record whether a qubit is present into a classical bit.

Loss([p])

One-qubit loss event: the qubit is lost with probability p.

MeasureCheck()

Measure a qubit if it is present, and record its presence.

Reload()

Reload a qubit: reset it to \(|0\rangle\) and mark it present.

class Loss(p=1.0)[source]

Bases: Operation

One-qubit loss event: the qubit is lost with probability p.

Loss() is Loss(1.0), a certain loss. A lost qubit leaves the computation: gates on it are dropped, a measurement of it reads 0, and Check reports it as missing, until a Reload brings it back.

The probability is resolved by Circuit.sample_losses(), which turns each Loss(p) into Loss(1.0) or removes it. Circuit.resolve_losses() then gives a runnable, loss-free circuit; a LossModel decides what happens to gates acting on both lost and present qubits.

Loss cannot be inverted, raised to a power or controlled: inverse(), power() and control() raise TypeError.

Parameters:

p – Loss probability, real and in \([0, 1]\) (default 1.0). May be symbolic; it must be numeric before sampling.

Raises:

ValueError – If a numeric p is not real or is outside \([0, 1]\).

Examples

>>> from mimiqcircuits import *
>>> # qubit 0 is lost with probability 0.1
>>> c = Circuit()
>>> c.push(Loss(0.1), 0)
1-qubit circuit with 1 instruction:
└── Loss(0.1) @ q[0]

>>> # qubit 1 is lost for sure
>>> c.push(Loss(), 1)
2-qubit circuit with 2 instructions:
├── Loss(0.1) @ q[0]
└── Loss(1.0) @ q[1]

See also

Reload, Check, MeasureCheck, sample_losses(), resolve_losses()

evaluate(d={})[source]

Return a copy with symbols in p substituted by values.

Parameters:

d (dict) – Map from symbols to the values to substitute.

Returns:

A new operation; p becomes a number when it is fully numeric.

Return type:

Loss

Raises:

ValueError – If the substituted p is not real or is outside \([0, 1]\).

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 Reload[source]

Bases: Operation

Reload a qubit: reset it to \(|0\rangle\) and mark it present.

A reload always resets the qubit, whether or not it was lost. After lower_losses() it becomes a Reset followed by a Reloaded marker.

Reload is not reversible: inverse(), power() and control() raise TypeError.

Examples

>>> from mimiqcircuits import *
>>> # bring qubit 0 back in |0>, lost or not
>>> c = Circuit()
>>> c.push(Reload(), 0)
1-qubit circuit with 1 instruction:
└── Reload @ q[0]

See also

Loss, Reset

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 Check[source]

Bases: Operation

Record whether a qubit is present into a classical bit.

The bit is set to 1 if the qubit is present and to 0 if it is lost. Like Measure records a qubit’s value, Check records its presence; it does not touch the quantum state. It targets one qubit and one bit.

Check cannot be inverted, raised to a power or controlled: those methods raise TypeError.

Examples

>>> from mimiqcircuits import *
>>> # write the presence of qubit 0 into bit 0
>>> c = Circuit()
>>> c.push(Check(), 0, 0)
1-qubit, 1-bit circuit with 1 instruction:
└── Check @ q[0], c[0]

See also

MeasureCheck, Loss, Reload

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 MeasureCheck[source]

Bases: Operation

Measure a qubit if it is present, and record its presence.

It targets one qubit and two bits. The first bit gets the Z-basis measurement result (0 if the qubit is lost), the second the presence (1 present, 0 lost). The state collapses only when the qubit is present.

MeasureCheck cannot be inverted, raised to a power or controlled: those methods raise TypeError.

Examples

>>> from mimiqcircuits import *
>>> # outcome of qubit 0 into bit 0, its presence into bit 1
>>> c = Circuit()
>>> c.push(MeasureCheck(), 0, 0, 1)
1-qubit, 2-bit circuit with 1 instruction:
└── MeasureCheck @ q[0], c[0:1]

See also

Check, Measure, Loss

iswrapper()[source]

Whether the operation wraps another operation.

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

Returns:

bool