mimiqcircuits.operations.noisechannel.mixedunitary

Classes

MixedUnitary(*args[, lossy])

Custom N-qubit mixed unitary channel.

class MixedUnitary(*args, lossy=None)[source]

Bases: krauschannel

Custom N-qubit mixed unitary channel.

The channel applies the unitary \(U_k\) with probability \(p_k\):

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

with \(0 \leq p_k \leq 1\) and \(\sum_k p_k = 1\). If some Kraus operators are not proportional to a unitary, use Kraus instead.

There are two ways to build it:

  • MixedUnitary(p, U) with a list of probabilities p and a list U of the same length of gates or \(2^N \times 2^N\) matrices (symengine, sympy or numpy). Matrices are wrapped in GateCustom.

  • MixedUnitary(gates) with a list of RescaledGate, where the gate RescaledGate(U_k, s_k) stands for \(U_k\) applied with probability \(p_k = s_k^2\).

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.

Parameters:
  • *args – Either (p, U) or (gates,) as described above.

  • lossy (list, optional) – One entry per branch listing the qubits that are lost when that branch is drawn, as 1-based positions within the channel’s targets (1 is the first target, up to \(N\)). For example [[], [1]] makes the second branch lose the first target qubit. Branches are lossless by default. Circuit.sample_mixedunitaries() emits a certain Loss on these qubits when it draws a lossy branch.

Raises:

ValueError – If the arguments do not match one of the two forms, the lists have different lengths, a numeric probability is outside \([0, 1]\), numeric probabilities do not add up to 1, a matrix size is not a power of 2, \(N\) is not 1 or 2, or a lossy entry is out of range.

Note

Only 1- and 2-qubit custom mixed unitary channels are supported.

See also

Kraus, ismixedunitary(), RescaledGate

Examples

>>> from mimiqcircuits import *
>>> from symengine import *
>>> # identity with probability 0.9, X with probability 0.1
>>> c = Circuit()
>>> c.push(MixedUnitary([0.9, 0.1], [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [1, 0]])]), 0)
1-qubit circuit with 1 instruction:
└── MixedUnitary((0.9, "Custom([1 0; 0 1])"),(0.1, "Custom([0 1; 1 0])")) @ q[0]
>>> # matrices can come from existing gates
>>> c.push(MixedUnitary([0.8, 0.2], [Matrix(GateID().matrix()), Matrix(GateRX(0.2).matrix())]), 1)
2-qubit circuit with 2 instructions:
├── MixedUnitary((0.9, "Custom([1 0; 0 1])"),(0.1, "Custom([0 1; 1 0])")) @ q[0]
└── MixedUnitary((0.8, "Custom([1.0 0; 0 1.0])"),(0.2, "Custom([0.995004165278026 0.0 - 0.0998334166468282*I; 0.0 - 0.0998334166468282*I 0.995004165278026])")) @ q[1]
>>> # the same kind of channel from rescaled gates: the scale is sqrt(p)
>>> rescaled_gate1 = RescaledGate(GateCustom(Matrix([[1, 0], [0, 1]])), sqrt(0.2))
>>> rescaled_gate2 = RescaledGate(GateCustom(Matrix([[0, 1], [1, 0]])), sqrt(0.8))
>>> op = MixedUnitary([rescaled_gate1, rescaled_gate2])
>>> op
MixedUnitary((0.2, "Custom([1 0; 0 1])"), (0.8, "Custom([0 1; 1 0])"))
>>> c.push(op, 1)
2-qubit circuit with 3 instructions:
├── MixedUnitary((0.9, "Custom([1 0; 0 1])"),(0.1, "Custom([0 1; 1 0])")) @ q[0]
├── MixedUnitary((0.8, "Custom([1.0 0; 0 1.0])"),(0.2, "Custom([0.995004165278026 0.0 - 0.0998334166468282*I; 0.0 - 0.0998334166468282*I 0.995004165278026])")) @ q[1]
└── MixedUnitary((0.2, "Custom([1 0; 0 1])"),(0.8, "Custom([0 1; 1 0])")) @ q[1]
>>> # gates work too; here the X branch also loses the qubit
>>> MixedUnitary([0.5, 0.5], [GateID(), GateX()], lossy=[[], [1]])
MixedUnitary((0.5, "ID"), (0.5, "X"); lossy=((), (1,)))
haslossybranch()[source]

Whether any branch loses qubits when drawn, as set by lossy.

evaluate(values)[source]

Return a copy with symbols substituted by values.

Substitutes into the probabilities and into the gates. The lossy masks are kept.

Parameters:

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

Returns:

A new channel with substituted parameters.

Return type:

MixedUnitary

Raises:

ValueError – If the substituted probabilities are all numeric and do not add up to 1.

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

Compact string representation for the MixedUnitary.

__repr__()[source]

Full string representation for the MixedUnitary.