Comprehensive Python library for simulating quantum systems dynamics and quantum information processing.
—
Tools for quantum information processing including entropy measures, entanglement quantification, and quantum correlations.
Various entropy and information measures for quantum states.
def entropy_vn(rho: Qobj, base: float = np.e, sparse: bool = False) -> float:
"""
Calculate von Neumann entropy S(ρ) = -Tr(ρ log ρ).
Parameters:
- rho: Density matrix
- base: Logarithm base (e for nats, 2 for bits)
- sparse: Use sparse eigenvalue decomposition
Returns:
- float: von Neumann entropy
"""
def entropy_linear(rho: Qobj) -> float:
"""
Calculate linear entropy S_L(ρ) = 1 - Tr(ρ²).
Parameters:
- rho: Density matrix
Returns:
- float: Linear entropy
"""
def entropy_mutual(rho: Qobj, selA: list, selB: list, base: float = np.e, sparse: bool = False) -> float:
"""
Calculate mutual information I(A:B) = S(A) + S(B) - S(AB).
Parameters:
- rho: Bipartite density matrix
- selA: Subsystem A indices
- selB: Subsystem B indices
- base: Logarithm base
- sparse: Use sparse calculations
Returns:
- float: Mutual information
"""
def entropy_conditional(rho: Qobj, selA: list, selB: list, base: float = np.e, sparse: bool = False) -> float:
"""
Calculate conditional entropy S(A|B) = S(AB) - S(B).
Parameters:
- rho: Bipartite density matrix
- selA: Subsystem A indices
- selB: Subsystem B indices
- base: Logarithm base
- sparse: Use sparse calculations
Returns:
- float: Conditional entropy
"""
def entropy_relative(rho: Qobj, sigma: Qobj, base: float = np.e, sparse: bool = False) -> float:
"""
Calculate relative entropy (Kullback-Leibler divergence) S(ρ||σ) = Tr(ρ log ρ - ρ log σ).
Parameters:
- rho: First density matrix
- sigma: Second density matrix
- base: Logarithm base
- sparse: Use sparse calculations
Returns:
- float: Relative entropy
"""Quantification of quantum entanglement in bipartite systems.
def concurrence(rho: Qobj) -> float:
"""
Calculate concurrence for two-qubit states.
Parameters:
- rho: Two-qubit density matrix
Returns:
- float: Concurrence (0 = separable, 1 = maximally entangled)
"""
def negativity(rho: Qobj, mask) -> float:
"""
Calculate negativity as entanglement measure.
Parameters:
- rho: Bipartite density matrix
- mask: Subsystem indices for partial transpose
Returns:
- float: Negativity
"""
def logarithmic_negativity(rho: Qobj, mask) -> float:
"""
Calculate logarithmic negativity E_N = log₂(2N + 1).
Parameters:
- rho: Bipartite density matrix
- mask: Subsystem indices for partial transpose
Returns:
- float: Logarithmic negativity
"""Measures of similarity and distance between quantum states.
def fidelity(rho: Qobj, sigma: Qobj) -> float:
"""
Calculate quantum fidelity F(ρ,σ) = Tr(√(√ρ σ √ρ))².
Parameters:
- rho: First quantum state (pure or mixed)
- sigma: Second quantum state (pure or mixed)
Returns:
- float: Fidelity (0 to 1)
"""
def trace_distance(rho: Qobj, sigma: Qobj) -> float:
"""
Calculate trace distance D(ρ,σ) = ½Tr|ρ - σ|.
Parameters:
- rho: First density matrix
- sigma: Second density matrix
Returns:
- float: Trace distance (0 to 1)
"""
def hilbert_schmidt_distance(rho: Qobj, sigma: Qobj) -> float:
"""
Calculate Hilbert-Schmidt distance.
Parameters:
- rho: First quantum state
- sigma: Second quantum state
Returns:
- float: Hilbert-Schmidt distance
"""
def bures_distance(rho: Qobj, sigma: Qobj) -> float:
"""
Calculate Bures distance D_B(ρ,σ) = √(2(1 - √F(ρ,σ))).
Parameters:
- rho: First density matrix
- sigma: Second density matrix
Returns:
- float: Bures distance
"""Measures of a quantum operation's ability to create entanglement.
def entangling_power(U: Qobj, targets: list = None) -> float:
"""
Calculate entangling power of unitary operation.
Parameters:
- U: Unitary operator
- targets: Target qubit indices
Returns:
- float: Entangling power
"""
def entanglement_capacity(kraus_ops: list) -> float:
"""
Calculate entanglement capacity of quantum channel.
Parameters:
- kraus_ops: List of Kraus operators
Returns:
- float: Entanglement capacity
"""Information-theoretic measures for quantum channels.
def channel_fidelity(channel1: list, channel2: list) -> float:
"""
Calculate fidelity between quantum channels.
Parameters:
- channel1: Kraus operators for first channel
- channel2: Kraus operators for second channel
Returns:
- float: Channel fidelity
"""
def diamond_norm(kraus_ops: list) -> float:
"""
Calculate diamond norm of quantum channel.
Parameters:
- kraus_ops: List of Kraus operators
Returns:
- float: Diamond norm
"""Tools for analyzing quantum state separability.
def partial_transpose(rho: Qobj, mask) -> Qobj:
"""
Calculate partial transpose of density matrix.
Parameters:
- rho: Density matrix
- mask: Subsystem indices to transpose
Returns:
- Qobj: Partially transposed density matrix
"""
def is_separable(rho: Qobj, tol: float = 1e-15) -> bool:
"""
Test if bipartite state is separable using PPT criterion.
Parameters:
- rho: Bipartite density matrix
- tol: Numerical tolerance
Returns:
- bool: True if separable (PPT), False if entangled
"""Tools for Schmidt decomposition of bipartite pure states.
def schmidt_decompose(state: Qobj, splitting: list = None) -> tuple:
"""
Perform Schmidt decomposition of bipartite pure state.
Parameters:
- state: Bipartite pure state vector
- splitting: Dimensions of subsystems [dimA, dimB]
Returns:
- tuple: (schmidt_coefficients, states_A, states_B)
"""
def schmidt_rank(state: Qobj, splitting: list = None, tol: float = 1e-12) -> int:
"""
Calculate Schmidt rank of bipartite pure state.
Parameters:
- state: Bipartite pure state
- splitting: Subsystem dimensions
- tol: Tolerance for zero coefficients
Returns:
- int: Schmidt rank
"""import qutip as qt
import numpy as np
# Entropy calculations
# Pure state entropy
psi_pure = qt.basis(2, 0) # |0⟩ state
rho_pure = psi_pure * psi_pure.dag()
S_pure = qt.entropy_vn(rho_pure)
print(f"Pure state entropy: {S_pure:.6f}") # Should be 0
# Mixed state entropy
rho_mixed = 0.7 * qt.ket2dm(qt.basis(2,0)) + 0.3 * qt.ket2dm(qt.basis(2,1))
S_mixed = qt.entropy_vn(rho_mixed)
S_linear = qt.entropy_linear(rho_mixed)
print(f"Mixed state entropy: {S_mixed:.3f}")
print(f"Linear entropy: {S_linear:.3f}")
# Maximum entropy state
rho_max = qt.maximally_mixed_dm(2) # I/2
S_max = qt.entropy_vn(rho_max, base=2) # Using base 2 for bits
print(f"Maximum entropy (bits): {S_max:.3f}") # Should be 1 bit
# Bipartite system entropies
bell = qt.bell_state('00') # (|00⟩ + |11⟩)/√2
rho_bell = bell * bell.dag()
# Mutual information
I_AB = qt.entropy_mutual(rho_bell, [0], [1])
print(f"Bell state mutual information: {I_AB:.3f}")
# Conditional entropy
S_A_given_B = qt.entropy_conditional(rho_bell, [0], [1])
print(f"Conditional entropy S(A|B): {S_A_given_B:.3f}")
# Entanglement measures
# Concurrence for two-qubit states
C_bell = qt.concurrence(rho_bell)
print(f"Bell state concurrence: {C_bell:.3f}") # Should be 1
# Separable state
sep_state = qt.tensor(qt.basis(2,0), qt.basis(2,0)) * qt.tensor(qt.basis(2,0), qt.basis(2,0)).dag()
C_sep = qt.concurrence(sep_state)
print(f"Separable state concurrence: {C_sep:.6f}") # Should be 0
# Negativity
N_bell = qt.negativity(rho_bell, [0])
N_sep = qt.negativity(sep_state, [0])
print(f"Bell state negativity: {N_bell:.3f}")
print(f"Separable state negativity: {N_sep:.6f}")
# Logarithmic negativity
E_N = qt.logarithmic_negativity(rho_bell, [0])
print(f"Bell state log negativity: {E_N:.3f}")
# Fidelity calculations
psi1 = qt.basis(2, 0) # |0⟩
psi2 = qt.basis(2, 1) # |1⟩
psi3 = (psi1 + psi2).unit() # |+⟩
F_identical = qt.fidelity(psi1, psi1)
F_orthogonal = qt.fidelity(psi1, psi2)
F_overlap = qt.fidelity(psi1, psi3)
print(f"Identical states fidelity: {F_identical:.6f}") # Should be 1
print(f"Orthogonal states fidelity: {F_orthogonal:.6f}") # Should be 0
print(f"Overlapping states fidelity: {F_overlap:.3f}") # Should be 0.5
# Mixed state fidelity
rho1 = 0.8 * qt.ket2dm(psi1) + 0.2 * qt.ket2dm(psi2)
rho2 = 0.6 * qt.ket2dm(psi1) + 0.4 * qt.ket2dm(psi2)
F_mixed = qt.fidelity(rho1, rho2)
print(f"Mixed states fidelity: {F_mixed:.3f}")
# Trace distance
T_dist = qt.trace_distance(rho1, rho2)
print(f"Trace distance: {T_dist:.3f}")
# Bures distance
B_dist = qt.bures_distance(rho1, rho2)
print(f"Bures distance: {B_dist:.3f}")
# Entangling power of quantum gates
CNOT = qt.cnot()
U_local = qt.tensor(qt.rx(np.pi/4), qt.ry(np.pi/3)) # Local unitary
EP_CNOT = qt.entangling_power(CNOT)
EP_local = qt.entangling_power(U_local)
print(f"CNOT entangling power: {EP_CNOT:.3f}")
print(f"Local unitary entangling power: {EP_local:.6f}") # Should be 0
# Partial transpose and separability test
rho_PT = qt.partial_transpose(rho_bell, [0])
eigenvals_PT = rho_PT.eigenenergies()
print(f"Partial transpose eigenvalues: {eigenvals_PT}")
# Negative eigenvalue indicates entanglement
separable = qt.is_separable(sep_state)
entangled = qt.is_separable(rho_bell)
print(f"Separable state test: {separable}") # Should be True
print(f"Entangled state test: {entangled}") # Should be False
# Schmidt decomposition
bell_state = qt.bell_state('00')
schmidt_coeffs, states_A, states_B = qt.schmidt_decompose(bell_state, [2, 2])
schmidt_r = qt.schmidt_rank(bell_state, [2, 2])
print(f"Schmidt coefficients: {schmidt_coeffs}")
print(f"Schmidt rank: {schmidt_r}")
# Verify Schmidt decomposition
reconstructed = sum(c * qt.tensor(sA, sB)
for c, sA, sB in zip(schmidt_coeffs, states_A, states_B))
fidelity_check = qt.fidelity(bell_state, reconstructed)
print(f"Schmidt decomposition fidelity: {fidelity_check:.6f}") # Should be 1
# Multi-partite entangled state
ghz3 = qt.ghz_state(3)
rho_ghz3 = ghz3 * ghz3.dag()
# Tripartite mutual information
I_ABC = (qt.entropy_vn(qt.ptrace(rho_ghz3, [0])) +
qt.entropy_vn(qt.ptrace(rho_ghz3, [1])) +
qt.entropy_vn(qt.ptrace(rho_ghz3, [2])) -
qt.entropy_vn(rho_ghz3))
print(f"GHZ state tripartite mutual info: {I_ABC:.3f}")
# Pairwise entanglement in GHZ state
rho_AB = qt.ptrace(rho_ghz3, [0, 1])
N_AB = qt.negativity(rho_AB, [0])
print(f"GHZ pairwise negativity: {N_AB:.6f}") # GHZ has no pairwise entanglement
# Information processing
# Quantum relative entropy (distinguishability)
rho_signal = 0.9 * qt.ket2dm(qt.basis(2,0)) + 0.1 * qt.ket2dm(qt.basis(2,1))
rho_noise = qt.maximally_mixed_dm(2)
S_rel = qt.entropy_relative(rho_signal, rho_noise, base=2)
print(f"Relative entropy (signal||noise): {S_rel:.3f} bits")# All quantum information functions return numerical values (float or int)
# or quantum objects (Qobj) for operations like partial transpose