Quantum Information
qiskit.quantum_info
Operators
Operator (data[, input_dims, output_dims]) | Matrix operator class |
Pauli ([data]) | N-qubit Pauli operator. |
Clifford (data[, validate, copy]) | An N-qubit unitary operator from the Clifford group. |
ScalarOp ([dims, coeff]) | Scalar identity operator class. |
SparseObservable | An observable over Pauli bases that stores its data in a qubit-sparse format. |
SparsePauliOp (data[, coeffs, ...]) | Sparse N-qubit operator in a Pauli basis representation. |
CNOTDihedral ([data, num_qubits, validate]) | An N-qubit operator from the CNOT-Dihedral group. |
PauliList (data) | List of N-qubit Pauli operators. |
pauli_basis (num_qubits[, weight]) | Return the ordered PauliList for the n-qubit Pauli basis. |
States
Statevector (data[, dims]) | Statevector class |
DensityMatrix (data[, dims]) | DensityMatrix class |
StabilizerState (data[, validate]) | StabilizerState class. |
Channels
Choi (data[, input_dims, output_dims]) | Choi-matrix representation of a Quantum Channel. |
SuperOp (data[, input_dims, output_dims]) | Superoperator representation of a quantum channel. |
Kraus (data[, input_dims, output_dims]) | Kraus representation of a quantum channel. |
Stinespring (data[, input_dims, output_dims]) | Stinespring representation of a quantum channel. |
Chi (data[, input_dims, output_dims]) | Pauli basis Chi-matrix representation of a quantum channel. |
PTM (data[, input_dims, output_dims]) | Pauli Transfer Matrix (PTM) representation of a Quantum Channel. |
Measures
average_gate_fidelity
qiskit.quantum_info.average_gate_fidelity(channel, target=None, require_cp=True, require_tp=False)
Return the average gate fidelity of a noisy quantum channel.
The average gate fidelity is given by
where is the process_fidelity()
of the input quantum channel with a target unitary , and is the dimension of the channel.
Parameters
- channel (QuantumChannel or Operator) – noisy quantum channel.
- target (Operator or None) – target unitary operator. If None target is the identity operator [Default: None].
- require_cp (bool) – check if input and target channels are completely-positive and if non-CP log warning containing negative eigenvalues of Choi-matrix [Default: True].
- require_tp (bool) – check if input and target channels are trace-preserving and if non-TP log warning containing negative eigenvalues of partial Choi-matrix [Default: True].
Returns
The average gate fidelity .
Return type
Raises
QiskitError – if the channel and target do not have the same dimensions, or have different input and output dimensions.
process_fidelity
qiskit.quantum_info.process_fidelity(channel, target=None, require_cp=True, require_tp=True)
Return the process fidelity of a noisy quantum channel.
The process fidelity between two quantum channels is given by
where is the state_fidelity()
, is the normalized Choi
matrix for the channel , and is the input dimension of .
When the target channel is unitary this is equivalent to
where are the SuperOp
matrices for the input quantum channel and target unitary respectively, and is the input dimension of the channel.
Parameters
- channel (Operator or QuantumChannel) – input quantum channel.
- target (Operator or QuantumChannel or None) – target quantum channel. If None target is the identity operator [Default: None].
- require_cp (bool) – check if input and target channels are completely-positive and if non-CP log warning containing negative eigenvalues of Choi-matrix [Default: True].
- require_tp (bool) – check if input and target channels are trace-preserving and if non-TP log warning containing negative eigenvalues of partial Choi-matrix [Default: True].
Returns
The process fidelity .
Return type
Raises
QiskitError – if the channel and target do not have the same dimensions.
gate_error
qiskit.quantum_info.gate_error(channel, target=None, require_cp=True, require_tp=False)
Return the gate error of a noisy quantum channel.
The gate error is given by the average gate infidelity
where is the average_gate_fidelity()
of the input quantum channel with a target unitary .
Parameters
- channel (QuantumChannel) – noisy quantum channel.
- target (Operator or None) – target unitary operator. If None target is the identity operator [Default: None].
- require_cp (bool) – check if input and target channels are completely-positive and if non-CP log warning containing negative eigenvalues of Choi-matrix [Default: True].
- require_tp (bool) – check if input and target channels are trace-preserving and if non-TP log warning containing negative eigenvalues of partial Choi-matrix [Default: True].
Returns
The average gate error .
Return type
Raises
QiskitError – if the channel and target do not have the same dimensions, or have different input and output dimensions.
diamond_norm
qiskit.quantum_info.diamond_norm(choi, solver='SCS', **kwargs)
Return the diamond norm of the input quantum channel object.
This function computes the completely-bounded trace-norm (often referred to as the diamond-norm) of the input quantum channel object using the semidefinite-program from reference [1].
Parameters
- choi (Choi or QuantumChannel) – a quantum channel object or Choi-matrix array.
- solver (str) – The solver to use.
- kwargs – optional arguments to pass to CVXPY solver.
Returns
The completely-bounded trace norm .
Return type
Raises
QiskitError – if CVXPY package cannot be found.
Additional Information:
The input to this function is typically not a CPTP quantum channel, but rather the difference between two quantum channels where .
Reference:
J. Watrous. “Simpler semidefinite programs for completely bounded norms”, arXiv:1207.5726 [quant-ph] (2012).
This function requires the optional CVXPY package to be installed. Any additional kwargs will be passed to the cvxpy.solve
function. See the CVXPY documentation for information on available SDP solvers.
state_fidelity
qiskit.quantum_info.state_fidelity(state1, state2, validate=True)
Return the state fidelity between two quantum states.
The state fidelity for density matrix input states is given by
If one of the states is a pure state this simplifies to , where .
Parameters
- state1 (Statevector orDensityMatrix) – the first quantum state.
- state2 (Statevector orDensityMatrix) – the second quantum state.
- validate (bool) – check if the inputs are valid quantum states [Default: True]
Returns
The state fidelity .
Return type
Raises
QiskitError – if validate=True
and the inputs are invalid quantum states.
purity
qiskit.quantum_info.purity(state, validate=True)
Calculate the purity of a quantum state.
The purity of a density matrix is
Parameters
- state (Statevector orDensityMatrix) – a quantum state.
- validate (bool) – check if input state is valid [Default: True]
Returns
the purity .
Return type
Raises
QiskitError – if the input isn’t a valid quantum state.
concurrence
qiskit.quantum_info.concurrence(state)
Calculate the concurrence of a quantum state.
The concurrence of a bipartite Statevector
is given by
where is the reduced state from by taking the partial_trace()
of the input state.
For density matrices the concurrence is only defined for 2-qubit states, it is given by:
where are the ordered eigenvalues of the matrix .
Parameters
state (Statevector orDensityMatrix) – a 2-qubit quantum state.
Returns
The concurrence.
Return type
Raises
- QiskitError – if the input state is not a valid QuantumState.
- QiskitError – if input is not a bipartite QuantumState.
- QiskitError – if density matrix input is not a 2-qubit state.
entropy
qiskit.quantum_info.entropy(state, base=2)
Calculate the von-Neumann entropy of a quantum state.
The entropy is given by
Parameters
- state (Statevector orDensityMatrix) – a quantum state.
- base (int) – the base of the logarithm [Default: 2].
Returns
The von-Neumann entropy S(rho).
Return type
Raises
QiskitError – if the input state is not a valid QuantumState.
entanglement_of_formation
qiskit.quantum_info.entanglement_of_formation(state)
Calculate the entanglement of formation of quantum state.
The input quantum state must be either a bipartite state vector, or a 2-qubit density matrix.
Parameters
state (Statevector orDensityMatrix) – a 2-qubit quantum state.
Returns
The entanglement of formation.
Return type
Raises
- QiskitError – if the input state is not a valid QuantumState.
- QiskitError – if input is not a bipartite QuantumState.
- QiskitError – if density matrix input is not a 2-qubit state.
mutual_information
qiskit.quantum_info.mutual_information(state, base=2)
Calculate the mutual information of a bipartite state.
The mutual information is given by:
where , are the reduced density matrices of the bipartite state .
Parameters
- state (Statevector orDensityMatrix) – a bipartite state.
- base (int) – the base of the logarithm [Default: 2].
Returns
The mutual information .
Return type
Raises
- QiskitError – if the input state is not a valid QuantumState.
- QiskitError – if input is not a bipartite QuantumState.
Utility Functions
Quaternion (data) | A class representing a Quaternion. |
partial_trace
qiskit.quantum_info.partial_trace(state, qargs)
Return reduced density matrix by tracing out part of quantum state.
If all subsystems are traced over this returns the trace()
of the input state.
Parameters
- state (Statevector orDensityMatrix) – the input state.
- qargs (list) – The subsystems to trace over.
Returns
The reduced density matrix.
Return type
Raises
QiskitError – if input state is invalid.
schmidt_decomposition
qiskit.quantum_info.schmidt_decomposition(state, qargs)
Return the Schmidt Decomposition of a pure quantum state.
For an arbitrary bipartite state:
its Schmidt Decomposition is given by the single-index sum over k:
where and are an orthonormal set of vectors in their respective spaces and , and the Schmidt coefficients are positive real values.
Parameters
- state (Statevector orDensityMatrix) – the input state.
- qargs (list) – the list of Input state positions corresponding to subsystem .
Returns
list of tuples (s, u, v)
, where s
(float) are the Schmidt coefficients , and u
(Statevector), v
(Statevector) are the Schmidt vectors , , respectively.
Return type
Raises
- QiskitError – if Input qargs is not a list of positions of the Input state.
- QiskitError – if Input qargs is not a proper subset of Input state.
In Qiskit, qubits are ordered using little-endian notation, with the least significant qubits having smaller indices. For example, a four-qubit system is represented as . Using this convention, setting qargs=[0]
will partition the state as . Furthermore, qubits will be organized in this notation regardless of the order they are passed. For instance, passing either qargs=[1,2]
or qargs=[2,1]
will result in partitioning the state as .
shannon_entropy
qiskit.quantum_info.shannon_entropy(pvec, base=2)
Compute the Shannon entropy of a probability vector.
The shannon entropy of a probability vector is defined as
where is the log base and (default 2), and .
Parameters
- pvec (array_like) – a probability vector.
- base (int) – the base of the logarithm [Default: 2].
Returns
The Shannon entropy H(pvec).
Return type
commutator
qiskit.quantum_info.commutator(a, b)
Compute commutator of a and b.
Parameters
- a (OperatorTypeT) – Operator a.
- b (OperatorTypeT) – Operator b.
Returns
The commutator
Return type
OperatorTypeT
anti_commutator
qiskit.quantum_info.anti_commutator(a, b)
Compute anti-commutator of a and b.
Parameters
- a (OperatorTypeT) – Operator a.
- b (OperatorTypeT) – Operator b.
Returns
The anti-commutator
Return type
OperatorTypeT
double_commutator
qiskit.quantum_info.double_commutator(a, b, c, *, commutator=True)
Compute symmetric double commutator of a, b and c.
See also Equation (13.6.18) in [1].
If commutator is True, it returns
If commutator is False, it returns
Parameters
- a (OperatorTypeT) – Operator a.
- b (OperatorTypeT) – Operator b.
- c (OperatorTypeT) – Operator c.
- commutator (bool) – If
True
compute the double commutator, ifFalse
the double anti-commutator.
Returns
The double commutator
Return type
OperatorTypeT
References
[1]: R. McWeeny.
Methods of Molecular Quantum Mechanics. 2nd Edition, Academic Press, 1992. ISBN 0-12-486552-6.
Random
random_statevector
qiskit.quantum_info.random_statevector(dims, seed=None)
Generator a random Statevector.
The statevector is sampled from the uniform distribution. This is the measure induced by the Haar measure on unitary matrices.
Parameters
- dims (int ortuple) – the dimensions of the state.
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
the random statevector.
Return type
Reference:
K. Zyczkowski and H. Sommers (2001), “Induced measures in the space of mixed quantum states”, J. Phys. A: Math. Gen. 34 7111.
random_density_matrix
qiskit.quantum_info.random_density_matrix(dims, rank=None, method='Hilbert-Schmidt', seed=None)
Generator a random DensityMatrix.
Parameters
- dims (int ortuple) – the dimensions of the DensityMatrix.
- rank (int or None) – Optional, the rank of the density matrix. The default value is full-rank.
- method (string) – Optional. The method to use. ‘Hilbert-Schmidt’: (Default) sample from the Hilbert-Schmidt metric. ‘Bures’: sample from the Bures metric.
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
the random density matrix.
Return type
Raises
QiskitError – if the method is not valid.
random_unitary
qiskit.quantum_info.random_unitary(dims, seed=None)
Return a random unitary Operator.
The operator is sampled from the unitary Haar measure.
Parameters
- dims (int ortuple) – the input dimensions of the Operator.
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
a unitary operator.
Return type
random_hermitian
qiskit.quantum_info.random_hermitian(dims, traceless=False, seed=None)
Return a random hermitian Operator.
The operator is sampled from Gaussian Unitary Ensemble.
Parameters
- dims (int ortuple) – the input dimension of the Operator.
- traceless (bool) – Optional. If True subtract diagonal entries to return a traceless hermitian operator (Default: False).
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
a Hermitian operator.
Return type
random_pauli
qiskit.quantum_info.random_pauli(num_qubits, group_phase=False, seed=None)
Return a random Pauli.
Parameters
- num_qubits (int) – the number of qubits.
- group_phase (bool) – Optional. If True generate random phase. Otherwise the phase will be set so that the Pauli coefficient is +1 (default: False).
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
a random Pauli
Return type
random_clifford
qiskit.quantum_info.random_clifford(num_qubits, seed=None)
Return a random Clifford operator.
The Clifford is sampled using the method of Reference [1].
Parameters
- num_qubits (int) – the number of qubits for the Clifford
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
a random Clifford operator.
Return type
Reference:
- S. Bravyi and D. Maslov, Hadamard-free circuits expose the structure of the Clifford group. arXiv:2003.09412 [quant-ph]
random_quantum_channel
qiskit.quantum_info.random_quantum_channel(input_dims=None, output_dims=None, rank=None, seed=None)
Return a random CPTP quantum channel.
This constructs the Stinespring operator for the quantum channel by sampling a random isometry from the unitary Haar measure.
Parameters
- input_dims (int ortuple) – the input dimension of the channel.
- output_dims (int ortuple) – the input dimension of the channel.
- rank (int) – Optional. The rank of the quantum channel Choi-matrix.
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
Returns
a quantum channel operator.
Return type
Raises
QiskitError – if rank or dimensions are invalid.
random_cnotdihedral
qiskit.quantum_info.random_cnotdihedral(num_qubits, seed=None)
Return a random CNOTDihedral element.
Parameters
- num_qubits (int) – the number of qubits for the CNOTDihedral object.
- seed (int or RandomState) – Optional. Set a fixed seed or generator for RNG.
Returns
a random CNOTDihedral element.
Return type
random_pauli_list
qiskit.quantum_info.random_pauli_list(num_qubits, size=1, seed=None, phase=True)
Return a random PauliList.
Parameters
- num_qubits (int) – the number of qubits.
- size (int) – Optional. The length of the Pauli list (Default: 1).
- seed (int or np.random.Generator) – Optional. Set a fixed seed or generator for RNG.
- phase (bool) – If True the Pauli phases are randomized, otherwise the phases are fixed to 0. [Default: True]
Returns
a random PauliList.
Return type
Analysis
hellinger_distance
qiskit.quantum_info.hellinger_distance(dist_p, dist_q)
Computes the Hellinger distance between two counts distributions.
Parameters
Returns
Distance
Return type
References
hellinger_fidelity
qiskit.quantum_info.hellinger_fidelity(dist_p, dist_q)
Computes the Hellinger fidelity between two counts distributions.
The fidelity is defined as where H is the Hellinger distance. This value is bounded in the range [0, 1].
This is equivalent to the standard classical fidelity that in turn is equal to the quantum state fidelity for diagonal density matrices.
Parameters
Returns
Fidelity
Return type
Example
from qiskit import QuantumCircuit
from qiskit.quantum_info.analysis import hellinger_fidelity
from qiskit.providers.basic_provider import BasicSimulator
qc = QuantumCircuit(5, 5)
qc.h(2)
qc.cx(2, 1)
qc.cx(2, 3)
qc.cx(3, 4)
qc.cx(1, 0)
qc.measure(range(5), range(5))
sim = BasicSimulator()
res1 = sim.run(qc).result()
res2 = sim.run(qc).result()
hellinger_fidelity(res1.get_counts(), res2.get_counts())
References
Z2Symmetries (symmetries, sq_paulis, sq_list) | The $Z_2$ symmetry converter identifies symmetries from the problem hamiltonian and uses them to provide a tapered - more efficient - representation of operators as Paulis for this problem. |