Quantities#
This module provides functions and a mixin for calculating quantum quantities.
from qhronology.mechanics.quantities import trace, purity, distance, fidelity, entropy, mutual
from qhronology.mechanics.quantities import QuantitiesMixin
Functions#
- trace(
- matrix: mat | QuantumObject,
Calculate the (complete) trace \(\trace[\op{\rho}]\) of
matrix(\(\op{\rho}\)).- Parameters:
matrix (mat | QuantumObject) – The input matrix.
- Returns:
num | sym – The trace of the input
matrix.
Examples
>>> matrix = sp.Matrix([["a", "b"], ["c", "d"]]) >>> trace(matrix) a + d
>>> matrix = sp.MatrixSymbol("U", 3, 3).as_mutable() >>> trace(matrix) U[0, 0] + U[1, 1] + U[2, 2]
- purity(
- state: mat | QuantumObject,
Calculate the purity (\(\Purity\)) of
state(\(\op{\rho}\)):(316)#\[\Purity(\op{\rho}) = \trace[\op{\rho}^2].\]- Parameters:
state (mat | QuantumObject) – The matrix representation of the input state.
- Returns:
num | sym – The purity of the input
state.
Examples
>>> matrix = sp.Matrix([["a", "b"], ["c", "d"]]) >>> purity(matrix) a**2 + 2*b*c + d**2
>>> matrix = sp.Matrix( ... [["a*conjugate(a)", "a*conjugate(b)"], ["b*conjugate(a)", "b*conjugate(b)"]] ... ) >>> purity(matrix) (a*conjugate(a) + b*conjugate(b))**2
- distance(
- state_A: mat | QuantumObject,
- state_B: mat | QuantumObject,
Calculate the trace distance (\(\TraceDistance\)) between two states
state_A(\(\op{\rho}\)) andstate_B(\(\op{\tau}\)):(317)#\[\TraceDistance(\op{\rho}, \op{\tau}) = \frac{1}{2}\trace{\abs{\op{\rho} - \op{\tau}}}.\]- Parameters:
state_A (mat | QuantumObject) – The matrix representation of the first input state.
state_B (mat | QuantumObject) – The matrix representation of the second input state.
- Returns:
num | sym – The trace distance between the inputs
state_Aandstate_B.
Examples
>>> matrix_A = sp.Matrix([["p", 0], [0, "1 - p"]]) >>> matrix_B = sp.Matrix([["q", 0], [0, "1 - q"]]) >>> distance(matrix_A, matrix_B) sqrt((p - q)*(conjugate(p) - conjugate(q)))
>>> matrix_A = sp.Matrix([["1/sqrt(2)"], ["1/sqrt(2)"]]) >>> matrix_B = sp.Matrix([["1/sqrt(2)"], ["-1/sqrt(2)"]]) >>> distance(matrix_A, matrix_B) 1
>>> matrix = sp.Matrix([["a", "b"], ["c", "d"]]) >>> distance(matrix, matrix) 0
- fidelity(
- state_A: mat | QuantumObject,
- state_B: mat | QuantumObject,
Calculate the fidelity (\(\Fidelity\)) between two states
state_A(\(\op{\rho}\)) andstate_B(\(\op{\tau}\)):(318)#\[\Fidelity(\op{\rho}, \op{\tau}) = \left(\trace{\sqrt{\sqrt{\op{\rho}}\,\op{\tau}\sqrt{\op{\rho}}}}\right)^2.\]- Parameters:
state_A (mat | QuantumObject) – The matrix representation of the first input state.
state_B (mat | QuantumObject) – The matrix representation of the second input state.
- Returns:
num | sym – The fidelity between the inputs
state_Aandstate_B.
Examples
>>> matrix_A = sp.Matrix([["a"], ["b"]]) >>> matrix_B = sp.Matrix([["c"], ["d"]]) >>> fidelity(matrix_A, matrix_A) (a*conjugate(a) + b*conjugate(b))**2 >>> fidelity(matrix_B, matrix_B) (c*conjugate(c) + d*conjugate(d))**2 >>> fidelity(matrix_A, matrix_B) (a*conjugate(c) + b*conjugate(d))*(c*conjugate(a) + d*conjugate(b))
>>> matrix_A = sp.Matrix([["p", 0], [0, "1 - p"]]) >>> matrix_B = sp.Matrix([["q", 0], [0, "1 - q"]]) >>> fidelity(matrix_A, matrix_B) (sqrt(p*q) + sqrt((1 - p)*(1 - q)))**2
>>> matrix_A = sp.Matrix([["1/sqrt(2)"], ["1/sqrt(2)"]]) >>> matrix_B = sp.Matrix([["1/sqrt(2)"], ["-1/sqrt(2)"]]) >>> fidelity(matrix_A, matrix_B) 0
- entropy(
- state_A: mat | QuantumObject,
- state_B: mat | QuantumObject | None = None,
- base: num | None = None,
Calculate the relative von Neumann entropy (\(\Entropy\)) between two states
state_A(\(\op{\rho}\)) andstate_B(\(\op{\tau}\)):(319)#\[\Entropy(\op{\rho} \Vert \op{\tau}) = \trace\bigl[\op{\rho} (\log_\Base\op{\rho} - \log_\Base\op{\tau})\bigr].\]If
state_Bis not specified (i.e.,None), calculate the ordinary von Neumann entropy ofstate_A(\(\op{\rho}\)) instead:(320)#\[\Entropy(\op{\rho}) = \trace[\op{\rho}\log_\Base\op{\rho}].\]Here, \(\Base\) represents
base, which is the dimensionality of the unit of information with which the entropy is measured.- Parameters:
state_A (mat | QuantumObject) – The matrix representation of the first input state.
state_B (mat | QuantumObject) – The matrix representation of the second input state.
base (num) – The dimensionality of the unit of information with which the entropy is measured. Defaults to
2.
- Returns:
num | sym – The von Neumann entropy of the input
state_A(ifstate_BisNone) or the relative entropy betweenstate_Aandstate_B(ifstate_Bis notNone).
Examples
>>> matrix = sp.Matrix([["a"], ["b"]]) >>> entropy(matrix, base='d') -(a*conjugate(a) + b*conjugate(b))**2*log(a*conjugate(a) + b*conjugate(b))/(b*log(d)*conjugate(b))
>>> matrix_A = sp.Matrix([["p", 0], [0, "1 - p"]]) >>> matrix_B = sp.Matrix([["q", 0], [0, "1 - q"]]) >>> entropy(matrix_A, base="d") (-p*log(p) + (p - 1)*log(1 - p))/log(d) >>> entropy(matrix_B, base="d") (-q*log(q) + (q - 1)*log(1 - q))/log(d) >>> entropy(matrix_A, matrix_B, base="d") (p*(log(p) - log(q)) - (p - 1)*(log(1 - p) - log(1 - q)))/log(d)
>>> matrix_A = sp.Matrix([["1/sqrt(2)"], ["1/sqrt(2)"]]) >>> matrix_B = sp.eye(2) / 2 >>> entropy(matrix_A) 0 >>> entropy(matrix_B) 1 >>> entropy(matrix_A, matrix_B) 1 >>> entropy(matrix_B, matrix_A) -1
- mutual(
- state: mat | QuantumObject,
- systems_A: int | list[int] | None = None,
- systems_B: int | list[int] | None = None,
- dim: int | None = None,
Calculate the mutual information (\(\MutualInformation\)) between two subsystems
systems_A(\(A\)) andsystems_B(\(B\)) of a composite quantum system represented bystate(\(\rho^{A,B}\)):(321)#\[\MutualInformation(A : B) = \Entropy(\op{\rho}^A) + \Entropy(\op{\rho}^B) - \Entropy(\op{\rho}^{A,B})\]where \(\Entropy(\op{\rho})\) is the von Neumann entropy of a state \(\op{\rho}\).
- Parameters:
state (mat | QuantumObject) – The matrix representation of the composite input state.
systems_A (int | list[int]) – The indices of the first subsystem. Defaults to
[0].systems_B (int | list[int]) – The indices of the second subsystem. Defaults to the complement of
systems_Awith respect to the entire composition of subsystems ofstate.dim (int) – The dimensionality of the composite quantum system (and its subsystems). Must be a non-negative integer. Defaults to
2.
- Returns:
num | sym – The mutual information between the subsystems
systems_Aandsystems_Bof the composite inputstate.
Examples
>>> matrix = sp.Matrix([1, 0, 0, 1]) / sp.sqrt(2) >>> mutual(matrix, [0], [1]) 2
>>> matrix = sp.eye(4) / 4 >>> mutual(matrix, [0], [1]) 0
Mixin#
- class QuantitiesMixin[source]#
A mixin for endowing classes with the ability to calculate various quantum quantities.
Any inheriting class must possess a matrix representation that can be accessed by either an
output()method or amatrixproperty.Note
The
QuantitiesMixinmixin is used exclusively by theQuantumStateclass—please see the corresponding section (Quantities) for documentation on its methods.