Math Utils#
A collection of model-agnostic math tools, operating on density matrices or states directly.
from jaqsi.math import quantum_fisher_information, fubini_study_metric, fidelity, trace_distance, phase_difference
Quantum Fisher Information#
The Quantum Fisher Information (QFI) is the metric tensor of the state manifold evaluated at a specific parameter point \(\theta\). Because it depends on the derivatives of the state with respect to the parameters, it is computed from the state as a function of the parameters rather than from a single state. The Jacobian is obtained via forward-mode automatic differentiation, which yields the complex Jacobian directly for the real-valued circuit parameters.
For a pure, normalised state \(\ket{\psi(\theta)}\) the QFI is the Fubini-Study metric (scaled by four):
For a mixed state \(\rho(\theta) = \sum_k p_k \ket{k}\bra{k}\) the QFI is given through the symmetric logarithmic derivative:
Both cases are handled by the same function, which dispatches on the kind of state returned by the provided callable.
Execute with type="state" to obtain the pure-state QFI, or with type="density" (e.g. for noisy circuits) to obtain the mixed-state QFI:
import jax.numpy as jnp
from jaqsi.script import Script
from jaqsi import Gates
from jaqsi.math import quantum_fisher_information, fubini_study_metric
def state_fn(theta):
def circuit(t):
Gates.RX(t[0], wires=0)
Gates.RY(t[1], wires=1)
Gates.CX(wires=[0, 1])
return Script(circuit, n_qubits=2).execute(type="state", args=(theta,))
theta = jnp.array([0.7, 1.3])
qfi = quantum_fisher_information(state_fn, theta)
metric = fubini_study_metric(state_fn, theta)
The result is a real, symmetric \((P, P)\) matrix, where \(P\) is the total number of parameters (the parameter axes are flattened). The state returned by the callable is assumed to be normalised, which the simulator guarantees.
Any function mapping parameters to a state vector works, so a higher-level model wrapping a
Script can be passed just as well, closing over any data inputs
(e.g. lambda p: model(params=p, inputs=x)).
Fubini-Study Metric#
The Fubini-Study metric is the real part of the quantum geometric tensor on the manifold of pure states. It is the underlying geometric object of the pure-state QFI and is related to it by a factor of four, \(F_{ij} = 4\,g_{ij}\):
fubini_study_metric(state_fn, params) follows the same calling convention as
quantum_fisher_information but, since the metric is only defined for pure states, requires
state_fn to return a state vector (type="state"):
Fidelity#
fidelity(state0, state1) computes the fidelity between two states, accepting either state
vectors or density matrices.
For pure states it evaluates \(F(\ket{\psi}, \ket{\phi}) = \left|\braket{\psi | \phi}\right|^2\),
while for density matrices it uses the Uhlmann fidelity
\(F(\rho, \sigma) = \left(\mathrm{Tr}\sqrt{\sqrt{\rho}\,\sigma\,\sqrt{\rho}}\right)^2\).
Both single states and batches of shape \((B, \dots)\) are supported.
Trace distance#
trace_distance(state0, state1) returns the trace distance between two density matrices,
where \(\lambda_i\) are the eigenvalues of \(\rho - \sigma\).
Phase difference#
phase_difference(state0, state1) returns the phase \(\arg\braket{\psi | \phi}\) between two
state vectors.
A value of zero indicates the two states differ by at most a real global factor.
Matrix logarithm#
logm_v(A) computes the matrix logarithm of a single matrix of shape \((d, d)\) or of each
matrix in a batch of shape \((B, d, d)\), as used internally by the entropy-based measures.