mimiqcircuits.operations.operators.lossyoperator

Classes

LossyOperator(mat[, lossy])

Kraus operator of a loss branch: a matrix plus the qubits it loses.

class LossyOperator(mat, lossy=None)[source]

Bases: AbstractOperator

Kraus operator of a loss branch: a matrix plus the qubits it loses.

Only one- and two-qubit lossy operators are supported.

A LossyOperator represents a tagged custom operator used as a loss branch inside a Kraus channel. The matrix is expressed in the computational basis, exactly like Operator, while lossy marks which of the operator’s local qubits leak when this branch is selected.

The lossy indices are local to the operator and numbered from 1 to N (not from 0). They are not circuit-global qubit indices. When a surrounding Kraus channel is applied to circuit targets (q_1, ..., q_N), each local index i in lossy maps to the corresponding physical target q_i.

A Kraus channel that contains one or more LossyOperator branches is a loss-aware channel. The helpers Kraus.hasloss(), Kraus.lossoperators(), Kraus.survivaloperators(), and Kraus.losseffect() inspect those branches.

See also

AbstractOperator, Operator, Kraus

Parameters:
  • mat (symengine.Matrix | sympy.Matrix | numpy.ndarray) – The \(2^N \times 2^N\) matrix of the operator.

  • lossy (int | tuple | list) – One or more local qubit indices, from 1 to N, that leak when this branch is selected. Stored sorted in the lossy attribute. For one-qubit operators the default is (1,); for two-qubit operators it must be given.

Raises:
  • TypeError – If mat is not a SymEngine, SymPy or NumPy matrix, or lossy is not an int, tuple or list.

  • ValueError – If mat is not square, its size is not 2 or 4, lossy is missing for a two-qubit operator, or an index is out of range or repeated.

Examples

>>> from mimiqcircuits import *
>>> from symengine import Matrix, sqrt
>>> op = LossyOperator(Matrix([[0, 1], [0, 0]]))
>>> op
1-qubit LossyOperator (lossy=(1,)):
├── 0 1
└── 0 0
>>> # amplitude damping where the decay branch also loses the qubit
>>> c = Circuit()
>>> c.push(Kraus([Matrix([[1, 0], [0, sqrt(0.9)]]),
...               LossyOperator(Matrix([[0, sqrt(0.1)], [0, 0]]))]), 1)
2-qubit circuit with 1 instruction:
└── Kraus(Operator([[1, 0], [0, 0.948683298050514]]), LossyOperator([[0, 0.316227766016838], [0, 0]]; lossy=(1,))) @ q[1]
static is_valid_power_of_2(n)[source]

Return whether n is a positive power of 2.

opname()[source]

Return "LossyOperator".

iswrapper()[source]

Lossy operators do not wrap another operation. Returns None.

property parnames

Names of the operation’s parameters, as a tuple of strings.

Read-only: assigning to it raises ValueError.

lossyqubits()[source]

Return the local indices of the lost qubits, numbered from 1.

Returns:

The sorted lossy indices.

Return type:

tuple

lossytargets(*targets)[source]

Return the circuit qubits lost by this branch for the given targets.

Parameters:

*targets – The N circuit qubits the operator is applied to, as separate arguments or as one tuple.

Returns:

The entries of targets selected by the lossy indices.

Return type:

tuple

Raises:

ValueError – If the number of targets is not N.

Examples

>>> from mimiqcircuits import *
>>> from symengine import Matrix
>>> # a two-qubit branch that loses its second qubit
>>> op = LossyOperator(Matrix([[0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]), 2)
>>> op.lossytargets(5, 7)
(7,)
unwrappedmatrix()[source]

Return the numeric matrix of the operator as a NumPy array.

Use this instead of matrix() when plain numbers are needed, for example to feed a simulator. Gates with a fast numeric path (see mimiqcircuits.numerics) skip SymEngine entirely; other operators build the SymEngine matrix and convert it.

Operators fully determined by their type return a cached, read-only array. Copy it before modifying it.

Returns:

The matrix, with dtype complex128.

Return type:

numpy.ndarray

Raises:

UnexpectedSymbolics – If any parameter is still symbolic.

Examples

>>> from mimiqcircuits import *
>>> GateX().unwrappedmatrix()
array([[0.+0.j, 1.+0.j],
       [1.+0.j, 0.+0.j]])
evaluate(values)[source]

Substitute values for the symbols in the matrix.

Parameters:

values (dict) – Map from symbols to values.

Returns:

A new operator with the same lossy indices.

Return type:

LossyOperator

opsquared()[source]

Return \(O^\dagger O\) as a plain Operator.

rescale(scale)[source]

Return a new lossy operator with the matrix multiplied by scale.

pretty_print()[source]

Return the matrix and lossy indices as a multi-line string.