mimiqcircuits.operations.noisechannel.kraus¶
Functions
|
Check if a number is a power of 2. |
Classes
|
Custom N-qubit Kraus channel given by a list of Kraus operators. |
- class Kraus(E, rtol=1e-12)[source]¶
Bases:
krauschannelCustom 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,
MixedUnitaryis 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
Krauschannel models qubit loss when one or more of its operators is aLossyOperator. The entries of aLossyOperatorare amplitudes, not probabilities:losseffect()returns the loss probabilities as \(\sum_k L_k^\dagger L_k\) over the lossy branches \(L_k\).hasloss(),lossoperators()andsurvivaloperators()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,Projector0orLossyOperator. Matrices are wrapped inOperator. 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
Eis 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
Eis neither a matrix nor an operator.
Note
Only 1- and 2-qubit custom Kraus channels are supported.
See also
MixedUnitary,GateCustom,LossyOperator,OperatorExamples
>>> 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:
- Raises:
ValueError – If the substituted operators do not fulfill \(\sum_k E_k^\dagger E_k = I\).
- 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
LossyOperatorbranches 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
tolare set to zero (default1e-12).- Returns:
\(\Lambda\) as a numeric
Operator.- Return type:
- Raises:
RuntimeError – If a lossy operator has symbolic entries.
See also
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