quairkit.qinfo.qinfo

quairkit.qinfo.qinfo.channel_repr_convert(representation, source, target, tol=1e-06)

convert the given representation of a channel to the target implementation

Parameters:
representation : Tensor | ndarray | List[Tensor] | List[ndarray]

input representation

source : str

input form, should be 'choi', 'kraus' or 'stinespring'

target : str

target form, should be 'choi', 'kraus' or 'stinespring'

tol : float

error tolerance for the conversion from Choi, \(10^{-6}\) by default

Raises:

ValueError – Unsupported channel representation: require Choi, Kraus or Stinespring.

Returns:

quantum channel by the target implementation

Return type:

Tensor | ndarray

Note

choi -> kraus currently has the error of order 1e-6 caused by eigh

Raises:

NotImplementedError – does not support the conversion of input data type

quairkit.qinfo.qinfo.create_choi_repr(linear_map, input_dim, input_dtype=None)

Create the Choi representation of a linear map with input checks.

This function verifies if the map is linear and if the output is a square matrix.

Parameters:
linear_map : Callable[[Tensor | ndarray], Tensor | ndarray]

A function representing the linear map, which takes and returns a square matrix.

input_dim : int

The dimension of the space in which the linear map operates.

input_dtype : dtype | None

The dtype of the input. Defaults to None.

Returns:

The Choi matrix of the linear map.

Return type:

torch.Tensor

Raises:

RuntimeWarning – If linear_map is not linear or the output is not a square matrix.

quairkit.qinfo.qinfo.decomp_1qubit(unitary, return_global=False)

Decompose a single-qubit unitary operator into Z-Y-Z rotation angles.

Parameters:
unitary : ndarray | Tensor

A batch of 2x2 unitary matrices representing single-qubit gates, as either a numpy ndarray or a torch Tensor. The shape should be (m, 2, 2).

return_global : bool

If set to True, the global phase angle alpha is also returned.

Returns:

A tuple containing the angles (beta, gamma, delta) or (alpha, beta, gamma, delta) if return_global is True. The type of the tuple elements matches the input type.

Raises:

ValueError – Raises a ValueError if the input matrix is not a batch of 2x2 unitary matrices.

Return type:

Tuple[ndarray, …] | Tuple[Tensor, …]

quairkit.qinfo.qinfo.decomp_ctrl_1qubit(unitary)

Decompose a controlled single-qubit unitary operator into its components.

Parameters:
unitary : ndarray | Tensor

A 2x2 unitary matrix representing the single-qubit gate, as either a numpy ndarray or a torch Tensor.

Returns:

A tuple containing the global phase alpha and the matrices A, B, C, which are components of the decomposition. The type of the tuple elements matches the input type.

Raises:

ValueError – Raises a ValueError if the input matrix is not a 2x2 unitary matrix.

Return type:

Tuple[ndarray, …] | Tuple[Tensor, …]

Reference:

Nielsen, M. A., & Chuang, I. L. (2000). Quantum Computation and Quantum Information. Corollary 4.2 for the decomposition of a single-qubit unitary operation.

quairkit.qinfo.qinfo.diamond_norm(channel_repr, dim_io=None, **kwargs)

Calculate the diamond norm of input.

Parameters:
channel_repr : Channel | Tensor

A Channel or a torch.Tensor instance.

dim_io : int | Tuple[int, int] | None

The input and output dimensions.

**kwargs

Parameters to set cvx.

Raises:
  • RuntimeErrorchannel_repr must be Channel or torch.Tensor.

  • TypeError – “dim_io” should be “int” or “tuple”.

Warning

channel_repr is not in Choi representation, and is converted into ChoiRepr.

Returns:

Its diamond norm.

Return type:

float

Reference:

Khatri, Sumeet, and Mark M. Wilde. “Principles of quantum communication theory: A modern approach.” arXiv preprint arXiv:2011.04672 (2020). Watrous, J. . “Semidefinite Programs for Completely Bounded Norms.” Theory of Computing 5.1(2009):217-238.

quairkit.qinfo.qinfo.gate_fidelity(U, V)

calculate the fidelity between gates

\[F(U, V) = |\text{tr}(UV^\dagger)|/2^n\]

\(U\) is a \(2^n\times 2^n\) unitary gate

Parameters:
U : ndarray | Tensor

quantum gate \(U\) in matrix form

V : ndarray | Tensor

quantum gate \(V\) in matrix form

Returns:

fidelity between gates

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.logarithmic_negativity(density_op)

Calculate the Logarithmic Negativity \(E_N = ||\rho^{T_A}||\) of the input quantum state.

Parameters:
density_op : ndarray | Tensor | State

Density matrix form of the quantum state.

Returns:

The Logarithmic Negativity of the input quantum state.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.mana(matrix, input_str, out_dim=None)

Compute the mana of states or channels

Parameters:
matrix : ndarray | Tensor | State

quantum state or channel, when “channel”, it should be the choi matrix of channel.

input_str : str

“state” or “channel”

out_dim : int | None

output system dimension, only need to compute mana of channel.

Returns:

the output mana

Return type:

ndarray | Tensor | State

quairkit.qinfo.qinfo.negativity(density_op)

Compute the Negativity \(N = ||\frac{\rho^{T_A}-1}{2}||\) of the input quantum state.

Parameters:
density_op : ndarray | Tensor | State

Density matrix form of the quantum state.

Returns:

The Negativity of the input quantum state.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.pauli_str_convertor(observable)

Concatenate the input observable with coefficient 1.

For example, if the input observable is [['z0,x1'], ['z1']], then this function returns the observable [[1, 'z0,x1'], [1, 'z1']].

Parameters:
observable : List

The observable to be concatenated with coefficient 1.

Returns:

The observable with coefficient 1

Return type:

List

quairkit.qinfo.qinfo.purity(rho)

Calculate the purity of a quantum state.

\[P = \text{tr}(\rho^2)\]
Parameters:
rho : ndarray | Tensor | State

Density matrix form of the quantum state.

Returns:

The purity of the input quantum state.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.relative_entropy(rho, sigma, base=2)

Calculate the relative entropy of two quantum states.

\[S(\rho \| \sigma)=\text{tr} \rho(\log \rho-\log \sigma)\]
Parameters:
rho : ndarray | Tensor | State

Density matrix form of the quantum state.

sigma : ndarray | Tensor | State

Density matrix form of the quantum state.

base : int | None

The base of logarithm. Defaults to 2.

Returns:

Relative entropy between input quantum states.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.stab_nullity(unitary)

Tool for calculation of unitary-stabilizer nullity.

Parameters:
unitary : ndarray | Tensor

A batch of unitary matrices.

Returns:

Unitary-stabilizer nullity for each unitary matrix.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.stab_renyi(density, alpha)

Tool for calculation of stabilizer renyi entropy.

Parameters:
density : ndarray | Tensor | State

A batch of density matrices.

Returns:

Stabilizer renyi entropy for each density matrix

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.state_fidelity(rho, sigma)

Calculate the fidelity of two quantum states.

\[F(\rho, \sigma) = \text{tr}(\sqrt{\sqrt{\rho}\sigma\sqrt{\rho}})\]
Parameters:
rho : ndarray | Tensor | State

a quantum state.

sigma : ndarray | Tensor | State

a quantum state.

Returns:

The fidelity between the input quantum states.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.trace_distance(rho, sigma)

Calculate the trace distance of two quantum states.

\[D(\rho, \sigma) = 1 / 2 * \text{tr}|\rho-\sigma|\]
Parameters:
rho : ndarray | Tensor | State

a quantum state.

sigma : ndarray | Tensor | State

a quantum state.

Returns:

The trace distance between the input quantum states.

Return type:

ndarray | Tensor

quairkit.qinfo.qinfo.von_neumann_entropy(rho, base=2)

Calculate the von Neumann entropy of a quantum state.

\[S = -\text{tr}(\rho \log(\rho))\]
Parameters:
rho : ndarray | Tensor | State

Density matrix form of the quantum state.

base : int | None

The base of logarithm. Defaults to 2.

Returns:

The von Neumann entropy of the input quantum state.

Return type:

ndarray | Tensor