mimiqcircuits.operations.noisechannel.kraus

Functions

is_valid_power_of_2(n)

Check if a number is a power of 2.

Classes

Kraus(E[, rtol])

Custom N-qubit Kraus channel given by a list of Kraus operators.

class Kraus(E, rtol=1e-12)[source]

Bases: krauschannel

Custom N-qubit Kraus channel given by a list of Kraus operators.

The channel acts on a density matrix as

\[\mathcal{E}(\rho) = \sum_k E_k \rho E_k^\dagger,\]

where the Kraus operators \(E_k\) must fulfill \(\sum_k E_k^\dagger E_k = I\). If all Kraus operators are proportional to unitaries, MixedUnitary is the better choice, since it can be sampled as a random unitary.

Matrices are written in the computational basis in the usual textbook order, with the first qubit as the left-most one: \(|0\rangle, |1\rangle\) for one qubit, \(|00\rangle, |01\rangle, |10\rangle, |11\rangle\) for two.

A Kraus channel models qubit loss when one or more of its operators is a LossyOperator. The entries of a LossyOperator are amplitudes, not probabilities: losseffect() returns the loss probabilities as \(\sum_k L_k^\dagger L_k\) over the lossy branches \(L_k\). hasloss(), lossoperators() and survivaloperators() split the channel into lossy and surviving branches.

Parameters:
  • E (List[MutableDenseMatrix | ndarray | sympy.Matrix | AbstractOperator]) – Kraus operators, each a \(2^N \times 2^N\) matrix (symengine, sympy or numpy) or an operator such as Operator, Projector0 or LossyOperator. Matrices are wrapped in Operator. All entries must act on the same number of qubits \(N\).

  • rtol – Tolerance of the check \(\sum_k E_k^\dagger E_k = I\) (default 1e-12). The check is skipped when any entry is symbolic.

Raises:
  • ValueError – If E is empty, the operators have different sizes, the size is not a power of 2, \(N\) is not 1 or 2, or the numeric operators do not fulfill \(\sum_k E_k^\dagger E_k = I\).

  • TypeError – If an entry of E is neither a matrix nor an operator.

Note

Only 1- and 2-qubit custom Kraus channels are supported.

See also

MixedUnitary, GateCustom, LossyOperator, Operator

Examples

>>> from mimiqcircuits import *
>>> from symengine import *
>>> # amplitude damping with gamma = 0.1, written out by hand
>>> c = Circuit()
>>> c.push(Kraus([Matrix([[1, 0], [0, sqrt(0.9)]]), Matrix([[0, sqrt(0.1)], [0, 0]])]), 0)
1-qubit circuit with 1 instruction:
└── Kraus(Operator([[1, 0], [0, 0.948683298050514]]), Operator([[0, 0.316227766016838], [0, 0]])) @ q[0]
>>> # the Kraus matrices can be read back
>>> g = Kraus([Matrix([[1, 0], [0, sqrt(0.9)]]), Matrix([[0, sqrt(0.1)], [0, 0]])])
>>> g.krausmatrices()
[[1.0, 0]
[0, 0.948683298050514]
, [0, 0.316227766016838]
[0, 0]
]
>>> # operators can be used directly: here a Z-basis dephasing
>>> c = Circuit()
>>> c.push(Kraus([Projector0(), Projector1()]), 0)
1-qubit circuit with 1 instruction:
└── Kraus(P₀(1), P₁(1)) @ q[0]
>>> # matrices and operators can be mixed
>>> c = Circuit()
>>> c.push(Kraus([Matrix([[1, 0], [0, 0]]), Projector1()]), 0)
1-qubit circuit with 1 instruction:
└── Kraus(Operator([[1, 0], [0, 0]]), P₁(1)) @ q[0]
>>> # a lossy branch: the qubit is lost from |1> with probability 0.2
>>> lossy = LossyOperator(Matrix([[0, 0], [0, sqrt(0.2)]]))
>>> survival = Operator(Matrix([[1, 0], [0, sqrt(0.8)]]))
>>> lk = Kraus([survival, lossy])
>>> lk.hasloss()
True
>>> lk.lossoperators()
[1-qubit LossyOperator (lossy=(1,)):
├── 0 0
└── 0 0.447213595499958]
>>> lk.survivaloperators()
[1-qubit Operator:
├── 1 0
└── 0 0.894427190999916]
>>> lk.losseffect()
1-qubit Operator:
├── 0.0 + 0.0*I 0.0 + 0.0*I
└── 0.0 + 0.0*I 0.2 + 0.0*I
>>> # symbolic parameters are substituted with evaluate
>>> x = Symbol("x")
>>> g = Kraus([Projector0(), Projector1(x)])
>>> g
Kraus(P₀(1), P₁(x))
>>> g.evaluate({x: 1})
Kraus(P₀(1), P₁(1))
evaluate(values)[source]

Return a copy with symbols substituted by values.

The normalization check runs again on the result when it is fully numeric, with the default tolerance.

Parameters:

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

Returns:

A new channel with substituted operators.

Return type:

Kraus

Raises:

ValueError – If the substituted operators do not fulfill \(\sum_k E_k^\dagger E_k = I\).

krausoperators()[source]

Return the Kraus operators, in the order they were given.

hasloss()[source]

Whether any Kraus operator is a LossyOperator.

Same result as haslossybranch().

lossoperators()[source]

Return the Kraus operators that are LossyOperator, in order.

survivaloperators()[source]

Return the Kraus operators that are not LossyOperator, in order.

losseffect(tol=1e-12)[source]

Compute the loss-probability operator over all lossy branches.

This returns the operator

\[\Lambda = \sum_k L_k^\dagger L_k,\]

where \(L_k\) runs over the LossyOperator branches of the channel.

\(\Lambda\) is a positive semidefinite operator whose diagonal entries give the loss probabilities for each computational basis state. For a basis state \(|i\rangle\),

\[\langle i|\Lambda|i\rangle\]

is the probability that \(|i\rangle\) leaks out of the computational subspace. For a general state \(|\psi\rangle\), the total loss probability is \(\langle\psi|\Lambda|\psi\rangle\).

The survival and lossy operators together satisfy

\[\sum_k S_k^\dagger S_k + \Lambda = I,\]

where \(S_k\) are the non-lossy branches.

If the channel has no lossy operators, the zero matrix is returned.

Parameters:

tol – Entries with absolute value below tol are set to zero (default 1e-12).

Returns:

\(\Lambda\) as a numeric Operator.

Return type:

Operator

Raises:

RuntimeError – If a lossy operator has symbolic entries.

Examples

>>> from mimiqcircuits import *
>>> from symengine import Matrix, sqrt
>>> g = Kraus([Matrix([[1, 0], [0, sqrt(0.9)]]),
...            LossyOperator(Matrix([[0, 0], [0, sqrt(0.1)]]))])
>>> g.losseffect()
1-qubit Operator:
├── 0.0 + 0.0*I 0.0 + 0.0*I
└── 0.0 + 0.0*I 0.1 + 0.0*I
__str__()[source]

String representation, listing either AbstractOperators or matrix slices.

unwrappedkrausmatrices()[source]

Return the Kraus matrices; same as krausmatrices().