tensorcircuit.channels¶
Some common noise quantum channels.
- class tensorcircuit.channels.KrausList(iterable, name, is_unitary)[source]¶
Bases:
list- append(object, /)¶
Append object to the end of the list.
- clear()¶
Remove all items from list.
- copy()¶
Return a shallow copy of the list.
- count(value, /)¶
Return number of occurrences of value.
- extend(iterable, /)¶
Extend list by appending elements from the iterable.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- insert(index, object, /)¶
Insert object before index.
- pop(index=-1, /)¶
Remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.
- remove(value, /)¶
Remove first occurrence of value.
Raises ValueError if the value is not present.
- reverse()¶
Reverse IN PLACE.
- sort(*, key=None, reverse=False)¶
Sort the list in ascending order and return None.
The sort is in-place (i.e. the list itself is modified) and stable (i.e. the order of two equal elements is maintained).
If a key function is given, apply it once to each list item and sort them, ascending or descending, according to their function values.
The reverse flag can be set to sort in descending order.
- tensorcircuit.channels.amplitudedampingchannel(gamma: float, p: float) Sequence[Gate][source]¶
Return an amplitude damping channel. Notice: Amplitude damping corrspondings to p = 1.
\[\begin{split}\sqrt{p} \begin{bmatrix} 1 & 0\\ 0 & \sqrt{1-\gamma}\\ \end{bmatrix}\qquad \sqrt{p} \begin{bmatrix} 0 & \sqrt{\gamma}\\ 0 & 0\\ \end{bmatrix}\qquad \sqrt{1-p} \begin{bmatrix} \sqrt{1-\gamma} & 0\\ 0 & 1\\ \end{bmatrix}\qquad \sqrt{1-p} \begin{bmatrix} 0 & 0\\ \sqrt{\gamma} & 0\\ \end{bmatrix}\end{split}\]- Example:
>>> cs = amplitudedampingchannel(0.25, 0.3) >>> tc.channels.single_qubit_kraus_identity_check(cs)
- Parameters:
gamma (float) – the damping parameter of amplitude (\(\gamma\))
p (float) – \(p\)
- Returns:
An amplitude damping channel with given \(\gamma\) and \(p\)
- Return type:
Sequence[Gate]
- tensorcircuit.channels.check_rep_transformation(kraus: Sequence[Gate], density_matrix: Any, verbose: bool = False)[source]¶
Check the convertation between those representations.
- Parameters:
kraus (Sequence[Gate]) – A sequence of Gate
density_matrix (Matrix) – Initial density matrix
verbose (bool, optional) – Whether print Kraus and new Kraus operators, defaults to False
- tensorcircuit.channels.choi_to_kraus(choi: Any, truncation_rules: Dict[str, Any] | None = None) Any[source]¶
Convert the Choi matrix representation to Kraus operator representation.
This can be done by firstly geting eigen-decomposition of Choi-matrix
\[\Lambda = \sum_k \gamma_k \vert \phi_k \rangle \langle \phi_k \vert\]Then define Kraus operators
\[K_k = \sqrt{\gamma_k} V_k\]where \(\gamma_k\geq0\) and \(\phi_k\) is the col-val vectorization of \(V_k\) .
- Examples:
>>> kraus = tc.channels.phasedampingchannel(0.2) >>> superop = tc.channels.kraus_to_choi(kraus) >>> kraus_new = tc.channels.choi_to_kraus(superop, truncation_rules={"max_singular_values":3})
- Parameters:
choi (Matrix) – Choi matrix
truncation_rules (Dictionary) – A dictionary to restrict the calculation of kraus matrices. The restriction can be the number of kraus terms, which is jitable. It can also be the truncattion error, which is not jitable.
- Returns:
A list of Kraus operators
- Return type:
Sequence[Matrix]
- tensorcircuit.channels.choi_to_super(choi: Any) Any[source]¶
Convert from Choi representation to Superoperator representation.
- Parameters:
choi (Matrix) – Choi matrix
- Returns:
Superoperator
- Return type:
Matrix
- tensorcircuit.channels.composedkraus(kraus1: KrausList, kraus2: KrausList) KrausList[source]¶
Compose the noise channels
- tensorcircuit.channels.depolarizingchannel(px: float, py: float, pz: float) Sequence[Gate][source]¶
Return a Depolarizing Channel
\[\begin{split}\sqrt{1-p_x-p_y-p_z} \begin{bmatrix} 1 & 0\\ 0 & 1\\ \end{bmatrix}\qquad \sqrt{p_x} \begin{bmatrix} 0 & 1\\ 1 & 0\\ \end{bmatrix}\qquad \sqrt{p_y} \begin{bmatrix} 0 & -1j\\ 1j & 0\\ \end{bmatrix}\qquad \sqrt{p_z} \begin{bmatrix} 1 & 0\\ 0 & -1\\ \end{bmatrix}\end{split}\]- Example:
>>> cs = depolarizingchannel(0.1, 0.15, 0.2) >>> tc.channels.single_qubit_kraus_identity_check(cs)
- Parameters:
px (float) – \(p_x\)
py (float) – \(p_y\)
pz (float) – \(p_z\)
- Returns:
Sequences of Gates
- Return type:
Sequence[Gate]
- tensorcircuit.channels.evol_kraus(density_matrix: Any, kraus_list: Sequence[Any]) Any[source]¶
The dynamic evolution according to Kraus operators.
\[\rho' = \sum_{k} K_k \rho K_k^{\dagger}\]- Examples:
>>> density_matrix = np.array([[0.5,0.5],[0.5,0.5]]) >>> kraus = tc.channels.phasedampingchannel(0.2) >>> evol_kraus(density_matrix,kraus)
- Parameters:
density_matrix (Matrix) – Initial density matrix
kraus_list (Sequence[Matrix]) – A list of Kraus operator
- Returns:
Final density matrix
- Return type:
Matrix
- tensorcircuit.channels.evol_superop(density_matrix: Any, superop: Any) Any[source]¶
The dynamic evolution according to Superoperator.
- Examples:
>>> density_matrix = np.array([[0.5,0.5],[0.5,0.5]]) >>> kraus = tc.channels.phasedampingchannel(0.2) >>> superop = kraus_to_super(kraus) >>> evol_superop(density_matrix,superop)
- Parameters:
density_matrix (Matrix) – Initial density matrix
superop (Sequence[Matrix]) – Superoperator
- Returns:
Final density matrix
- Return type:
Matrix
- tensorcircuit.channels.generaldepolarizingchannel(p: float | Sequence[float], num_qubits: int = 1) Sequence[Gate][source]¶
Return a depolarizing channel. If \(p\) is a float number, the one qubit channel is
\[\mathcal{E}(\rho) = (1 - 3p)\rho + p(X\rho X + Y\rho Y + Z\rho Z)\]Or alternatively
\[\mathcal{E}(\rho) = 4p \frac{I}{2} + (1 - 4p) \rho\]Note
The definition of
pin this method is different fromisotropicdepolarizingchannel().And if \(p\) is a sequence, the one qubit channel is
\[\mathcal{E}(\rho) = (1 - \sum_i p_i) \rho + p_1 X\rho X + p_2 Y\rho Y + p_3 \rho Z\]The logic for two-qubit or more-qubit channel follows similarly.
- Example:
>>> cs = tc.channels.generaldepolarizingchannel([0.1,0.1,0.1],1) >>> tc.channels.kraus_identity_check(cs) >>> cs = tc.channels.generaldepolarizingchannel(0.02,2) >>> tc.channels.kraus_identity_check(cs)
- Parameters:
p (Union[float, Sequence]) – parameter for each Pauli channel
num_qubits (int, optional) – number of qubits, defaults 1
- Returns:
Sequences of Gates
- Return type:
Sequence[Gate]
- tensorcircuit.channels.is_hermitian_matrix(mat: Any, rtol: float = 1e-08, atol: float = 1e-05)[source]¶
Test if an array is a Hermitian matrix
- Parameters:
mat (Matrix) – Matrix
rtol (float, optional) – _description_, defaults to 1e-8
atol (float, optional) – _description_, defaults to 1e-5
- Returns:
_description_
- Return type:
_type_
- tensorcircuit.channels.isotropicdepolarizingchannel(p: float, num_qubits: int = 1) Sequence[Gate][source]¶
Return an isotropic depolarizing channel.
\[\mathcal{E}(\rho) = (1 - p)\rho + p/(4^n-1)\sum_j P_j \rho P_j\]where $n$ is the number of qubits and $P_j$ are $n$-qubit Pauli strings except $I$. Or alternatively
\[\mathcal{E}(\rho) = \frac{4^n}{4^n-1}p \frac{I}{2} + (1 - \frac{4^n}{4^n-1}p) \rho\]Note
The definition of
pin this method is different fromgeneraldepolarizingchannel().- Example:
>>> cs = tc.channels.isotropicdepolarizingchannel(0.30,2) >>> tc.channels.kraus_identity_check(cs)
- Parameters:
p (float) – error probability
num_qubits (int, optional) – number of qubits, defaults 1
- Returns:
Sequences of Gates
- Return type:
Sequence[Gate]
- tensorcircuit.channels.kraus_identity_check(kraus: Sequence[Gate]) None[source]¶
Check identity of Kraus operators.
\[\sum_{k}^{} K_k^{\dagger} K_k = I\]- Examples:
>>> cs = resetchannel() >>> tc.channels.kraus_identity_check(cs)
- Parameters:
kraus (Sequence[Gate]) – List of Kraus operators.
- tensorcircuit.channels.kraus_to_choi(kraus_list: Sequence[Any]) Any[source]¶
Convert from Kraus representation to Choi representation.
- Parameters:
kraus_list (Sequence[Matrix]) – A list Kraus operators
- Returns:
Choi matrix
- Return type:
Matrix
- tensorcircuit.channels.kraus_to_super(kraus_list: Sequence[Any]) Any[source]¶
Convert Kraus operator representation to Louivile-Superoperator representation.
In the col-vec basis, the evolution of a state \(\rho\) in terms of tensor components of superoperator \(\varepsilon\) can be expressed as
\[\rho'_{mn} = \sum_{\mu \nu}^{} \varepsilon_{nm,\nu \mu} \rho_{\mu \nu}\]The superoperator \(\varepsilon\) must make the dynamic map from \(\rho\) to \(\rho'\) to satisfy hermitian-perserving (HP), trace-preserving (TP), and completely positive (CP).
We can construct the superoperator from Kraus operators by
\[\varepsilon = \sum_{k} K_k^{*} \otimes K_k\]- Examples:
>>> kraus = resetchannel() >>> tc.channels.kraus_to_super(kraus)
- Parameters:
kraus_list (Sequence[Gate]) – A sequence of Gate
- Returns:
The corresponding Tensor of Superoperator
- Return type:
Matrix
- tensorcircuit.channels.kraus_to_super_gate(kraus_list: Sequence[Gate]) Any[source]¶
Convert Kraus operators to one Tensor (as one Super Gate).
\[\sum_{k}^{} K_k \otimes K_k^{*}\]- Parameters:
kraus_list (Sequence[Gate]) – A sequence of Gate
- Returns:
The corresponding Tensor of the list of Kraus operators
- Return type:
Tensor
- tensorcircuit.channels.krausgate_to_krausmatrix(kraus_list: Sequence[Gate]) Sequence[Any][source]¶
Convert Kraus of Gate form to Matrix form.
- Parameters:
kraus_list (Sequence[Gate]) – A list of Kraus
- Returns:
A list of Kraus operators
- Return type:
Sequence[Matrix]
- tensorcircuit.channels.krausmatrix_to_krausgate(kraus_list: Sequence[Any]) Sequence[Gate][source]¶
Convert Kraus of Matrix form to Gate form.
- Parameters:
kraus_list (Sequence[Matrix]) – A list of Kraus
- Returns:
A list of Kraus operators
- Return type:
Sequence[Gate]
- tensorcircuit.channels.phasedampingchannel(gamma: float) Sequence[Gate][source]¶
Return a phase damping channel with given \(\gamma\)
\[\begin{split}\begin{bmatrix} 1 & 0\\ 0 & \sqrt{1-\gamma}\\ \end{bmatrix}\qquad \begin{bmatrix} 0 & 0\\ 0 & \sqrt{\gamma}\\ \end{bmatrix}\end{split}\]- Example:
>>> cs = phasedampingchannel(0.6) >>> tc.channels.single_qubit_kraus_identity_check(cs)
- Parameters:
gamma (float) – The damping parameter of phase (\(\gamma\))
- Returns:
A phase damping channel with given \(\gamma\)
- Return type:
Sequence[Gate]
- tensorcircuit.channels.resetchannel() Sequence[Gate][source]¶
Reset channel
\[\begin{split}\begin{bmatrix} 1 & 0\\ 0 & 0\\ \end{bmatrix}\qquad \begin{bmatrix} 0 & 1\\ 0 & 0\\ \end{bmatrix}\end{split}\]- Example:
>>> cs = resetchannel() >>> tc.channels.single_qubit_kraus_identity_check(cs)
- Returns:
Reset channel
- Return type:
Sequence[Gate]
- tensorcircuit.channels.reshuffle(op: Any, order: Sequence[int]) Any[source]¶
Reshuffle the dimension index of a matrix.
- Parameters:
op (Matrix) – Input matrix
order (Tuple) – required order
- Returns:
Reshuffled matrix
- Return type:
Matrix
- tensorcircuit.channels.single_qubit_kraus_identity_check(kraus: Sequence[Gate]) None¶
Check identity of Kraus operators.
\[\sum_{k}^{} K_k^{\dagger} K_k = I\]- Examples:
>>> cs = resetchannel() >>> tc.channels.kraus_identity_check(cs)
- Parameters:
kraus (Sequence[Gate]) – List of Kraus operators.
- tensorcircuit.channels.super_to_choi(superop: Any) Any[source]¶
Convert Louivile-Superoperator representation to Choi representation.
In the col-vec basis, the evolution of a state \(\rho\) in terms of Choi matrix \(\Lambda\) can be expressed as
\[\rho'_{mn} = \sum_{\mu,\nu}^{} \Lambda_{\mu m,\nu n} \rho_{\mu \nu}\]The Choi matrix \(\Lambda\) must make the dynamic map from \(\rho\) to \(\rho'\) to satisfy hermitian-perserving (HP), trace-preserving (TP), and completely positive (CP).
Interms of tensor components we have the relationship of Louivile-Superoperator representation and Choi representation
\[\Lambda_{mn,\mu \nu} = \varepsilon_{\nu n,\mu m}\]- Examples:
>>> kraus = resetchannel() >>> superop = tc.channels.kraus_to_super(kraus) >>> tc.channels.super_to_choi(superop)
- Parameters:
superop (Matrix) – Superoperator
- Returns:
Choi matrix
- Return type:
Matrix
- tensorcircuit.channels.super_to_kraus(superop: Any) Any[source]¶
Convert from Superoperator representation to Kraus representation.
- Parameters:
superop (Matrix) – Superoperator
- Returns:
A list of Kraus operator
- Return type:
Matrix
- tensorcircuit.channels.thermalrelaxationchannel(t1: float, t2: float, time: float, method: str = 'ByChoi', excitedstatepopulation: float = 0.0) Sequence[Gate][source]¶
Return a thermal_relaxation_channel
- Example:
>>> cs = thermalrelaxationchannel(100,200,100,"AUTO",0.1) >>> tc.channels.single_qubit_kraus_identity_check(cs)
- Parameters:
t1 (float) – the T1 relaxation time.
t2 (float) – the T2 dephasing time.
time (str) – gate time
method – method to express error (default: “ByChoi”). When \(T1>T2\), choose method “ByKraus” or “ByChoi” for jit. When \(T1<T2\),choose method “ByChoi” for jit. Users can also set method as “AUTO” and never mind the relative magnitude of \(T1,T2\), which is not jitable.
excitedstatepopulation – the population of state \(|1\rangle\) at equilibrium (default: 0)
- Returns:
A thermal_relaxation_channel
- Return type:
Sequence[Gate]