mimiqcircuits.operations.krauschannel

Kraus channel definitions.

Classes

krauschannel()

Base class for all N-qubit Kraus channels.

class krauschannel[source]

Bases: Operation

Base class for all N-qubit Kraus channels.

A Kraus channel acts on a density matrix \(\rho\) as

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

where the Kraus operators \(E_k\) fulfill \(\sum_k E_k^\dagger E_k \leq I\). The channel is completely positive and trace preserving (CPTP) when the equality \(\sum_k E_k^\dagger E_k = I\) holds.

A Kraus channel is a mixed unitary channel when every \(E_k\) is proportional to a unitary \(U_k\), so that \(\mathcal{E}(\rho) = \sum_k p_k U_k \rho U_k^\dagger\) with probabilities \(p_k\) that add up to 1. Mixed unitary channels can be sampled as a random choice of unitary gate (see sample_mixedunitaries()).

Kraus channels cannot be inverted or raised to a power: inverse() and power() raise NotImplementedError.

krausmatrices()[source]

Return the matrices of the Kraus operators \(E_k\) of the channel.

These are the matrices of krausoperators(), in the same order. For a parametric channel the entries are symbolic expressions.

Returns:

One symengine matrix per Kraus operator.

Return type:

list

Examples

>>> from mimiqcircuits import *
>>> AmplitudeDamping(0.36).krausmatrices()
[[1.0, 0]
[0, 0.8]
, [0, 0.6]
[0, 0]
]
unwrappedkrausmatrices()[source]

Return the Kraus matrices of a channel whose parameters all have values.

Returns the same matrices as krausmatrices(), after checking that every parameter evaluates to a constant.

Returns:

One symengine matrix per Kraus operator.

Return type:

list

Raises:

ValueError – If a parameter is still a free symbol.

See also

krausmatrices()

Examples

>>> from mimiqcircuits import *
>>> # PauliX(p) has Kraus operators sqrt(1-p) I and sqrt(p) X
>>> op = PauliX(0.2)
>>> op.unwrappedkrausmatrices()
[[0.894427190999916, 0]
[0, 0.894427190999916]
, [0, 0.447213595499958]
[0.447213595499958, 0]
]
classmethod isCPTP()[source]

Whether the channel is completely positive and trace preserving (CPTP).

A channel is CPTP when its Kraus operators fulfill \(\sum_k E_k^\dagger E_k = I\), and only trace decreasing when \(\sum_k E_k^\dagger E_k < I\). Every channel in the package is CPTP.

Returns:

True.

Return type:

bool

classmethod ismixedunitary()[source]

Whether the channel is a mixed unitary channel.

A channel is mixed unitary when every Kraus operator \(E_k\) is proportional to a unitary matrix \(U_k\), so that

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

with probabilities \(0 \leq p_k \leq 1\) that add up to 1. The answer depends only on the channel type, not on its parameters, so this is a class method. Only mixed unitary channels support probabilities(), cumprobabilities(), unitarygates() and unitarymatrices().

Returns:

True for mixed unitary channel types, False otherwise.

Return type:

bool

Examples

>>> from mimiqcircuits import *
>>> # PauliX applies X with probability p: mixed unitary
>>> PauliX(0.1).ismixedunitary()
True
>>> # amplitude damping has a non-unitary Kraus operator
>>> AmplitudeDamping(0.1).ismixedunitary()
False
inverse()[source]

Kraus channels have no inverse.

Raises:

NotImplementedError – Always.

power(n)[source]

Kraus channels cannot be raised to a power.

Raises:

NotImplementedError – Always.

iswrapper()[source]

Whether the operation wraps another operation.

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

Returns:

bool

probabilities()[source]

Return the probabilities \(p_k\) of a mixed unitary channel.

For \(\mathcal{E}(\rho) = \sum_k p_k U_k \rho U_k^\dagger\) this is the list of \(p_k\), in the same order as unitarygates().

Returns:

One probability per unitary.

Return type:

list

Raises:

ValueError – If the channel is not mixed unitary.

Examples

>>> from mimiqcircuits import *
>>> # identity with probability 0.9, X with probability 0.1
>>> PauliX(0.1).probabilities()
[0.9, 0.1]
numparams()[source]

Return the number of parameters of the operation.

Returns:

The length of getparams().

Return type:

int

cumprobabilities()[source]

Return the cumulative sums of probabilities().

The last entry is 1. Drawing a uniform number r and picking the first index whose cumulative probability exceeds r samples one of the unitaries with the right probability.

Returns:

Cumulative probabilities as symengine values, symbolic expressions when the probabilities are symbolic.

Return type:

list

Raises:

ValueError – If the channel is not mixed unitary.

Examples

>>> from mimiqcircuits import *
>>> # identity with probability 0.9, then X, Y, Z with 0.1/3 each
>>> Depolarizing1(0.1).cumprobabilities()
[0.9, 0.933333333333333, 0.966666666666667, 1.0]
unwrappedcumprobabilities()[source]

Return cumprobabilities() as plain Python floats.

Returns:

Cumulative probabilities.

Return type:

list[float]

Raises:

ValueError – If the channel is not mixed unitary.

Examples

>>> from mimiqcircuits import *
>>> PauliX(0.1).unwrappedcumprobabilities()
[0.9, 1.0]
krausoperators()[source]

Return the Kraus operators \(E_k\) of the channel as operator objects.

Every concrete channel implements this method; the base class raises.

Returns:

One operator (for example Operator, DiagonalOp or RescaledGate) per Kraus operator.

Return type:

list

Raises:

NotImplementedError – When called on a class that does not define it.

Examples

>>> from mimiqcircuits import *
>>> # projective noise in Z: project on |0> or on |1>
>>> ProjectiveNoise("Z").krausoperators()
[P₀(1), P₁(1)]
haslossybranch()[source]

Whether any branch of the channel loses qubits when drawn.

A branch is lossy when its Kraus operator is a LossyOperator.

Returns:

True if at least one Kraus operator is lossy.

Return type:

bool

Examples

>>> from mimiqcircuits import *
>>> PauliX(0.1).haslossybranch()
False
>>> # a Kraus channel where |1> is lost with probability 0.2
>>> import numpy as np
>>> survival = Operator(np.array([[1, 0], [0, np.sqrt(0.8)]]))
>>> lossy = LossyOperator(np.array([[0, 0], [0, np.sqrt(0.2)]]))
>>> Kraus([survival, lossy]).haslossybranch()
True
squaredkrausoperators()[source]

Return \(E_k^\dagger E_k\) for every Kraus operator \(E_k\).

The sum of the returned operators is the identity for a trace preserving channel.

Returns:

One operator per Kraus operator, in the same order.

Return type:

list

Examples

>>> from mimiqcircuits import *
>>> # a projector P satisfies P^dagger P = P
>>> Kraus([Projector0(), Projector1()]).squaredkrausoperators()
[P₀(1), P₁(1)]
unitarymatrices()[source]

Return the matrices of the unitaries \(U_k\) of a mixed unitary channel.

For \(\mathcal{E}(\rho) = \sum_k p_k U_k \rho U_k^\dagger\) these are the matrices of unitarygates(), in the same order as probabilities(). For a parametric channel the entries are symbolic expressions.

Returns:

One symengine matrix per unitary.

Return type:

list

Raises:

ValueError – If the channel is not mixed unitary.

Examples

>>> from mimiqcircuits import *
>>> # identity and Pauli X
>>> PauliX(0.2).unitarymatrices()
[[1.0, 0]
[0, 1.0]
, [0, 1.0]
[1.0, 0]
]
unwrappedunitarymatrices()[source]

Return unitarymatrices() with every entry evaluated to a number.

Real entries become float and complex entries complex.

Returns:

One symengine matrix with numeric entries per unitary.

Return type:

list

Raises:

ValueError – If the channel is not mixed unitary.

unitarygates()[source]

Return the unitaries \(U_k\) of a mixed unitary channel as gates.

For \(\mathcal{E}(\rho) = \sum_k p_k U_k \rho U_k^\dagger\) these are the \(U_k\), in the same order as probabilities().

Returns:

One gate per unitary.

Return type:

list

Raises:

ValueError – If the channel is not mixed unitary.

Examples

>>> from mimiqcircuits import *
>>> PauliX(0.1).unitarygates()
[ID, X]