Observables¶
Observable utilities for states and density matrices.
- openquantumsim.observables.expect(operator, state)¶
Expectation value of an operator for a ket or density matrix.
- Parameters:
operator (Operator)
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
complex
- openquantumsim.observables.von_neumann_entropy(rho, *, base=2.0)¶
Von Neumann entropy -Tr(rho log rho).
- Parameters:
rho (ndarray[tuple[Any, ...], dtype[complex128]])
base (float)
- Return type:
float
- openquantumsim.observables.renyi_entropy(state, alpha=2.0, *, base=2.0)¶
Renyi entropy
S_alpha = log(Tr(rho^alpha))/(1-alpha).- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
alpha (float)
base (float)
- Return type:
float
- openquantumsim.observables.purity(state, *, normalize=False)¶
Return
Tr(rho^2)for a ket or density matrix.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
normalize (bool)
- Return type:
float
- openquantumsim.observables.linear_entropy(state, *, normalized=False)¶
Linear entropy
1 - Tr(rho^2).Set
normalized=Trueto scale byd/(d-1)for ad-dimensional state, giving 1 for a maximally mixed state.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
normalized (bool)
- Return type:
float
- openquantumsim.observables.participation_ratio(state)¶
Effective number of populated eigenstates,
1 / Tr(rho^2).- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.fidelity(state_a, state_b, *, squared=True)¶
Uhlmann state fidelity between two kets or density matrices.
By default this returns the squared convention
F = (Tr sqrt(sqrt(rho) sigma sqrt(rho)))^2. For pure states this is|<psi|phi>|^2; forrhoand|psi>it is<psi|rho|psi>. Setsquared=Falseto return the root fidelity.- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
squared (bool)
- Return type:
float
- openquantumsim.observables.infidelity(state_a, state_b)¶
Return
1 - fidelity(state_a, state_b).- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.trace_norm(matrix, *, hermitian=None)¶
Trace norm
Tr(sqrt(A†A)).- Parameters:
matrix (ndarray[tuple[Any, ...], dtype[complex128]])
hermitian (bool | None)
- Return type:
float
- openquantumsim.observables.trace_distance(state_a, state_b)¶
Trace distance
0.5 * ||rho - sigma||_1.- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.hilbert_schmidt_distance(state_a, state_b)¶
Hilbert-Schmidt distance
sqrt(Tr((rho-sigma)^2)).- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.bures_angle(state_a, state_b)¶
Bures angle
acos(sqrt(F))in radians.- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.bures_distance(state_a, state_b)¶
Bures distance
sqrt(2 * (1 - sqrt(F))).- Parameters:
state_a (ndarray[tuple[Any, ...], dtype[complex128]])
state_b (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.is_hermitian(matrix, *, atol=1e-10)¶
Return whether
matrixis Hermitian withinatol.- Parameters:
matrix (ndarray[tuple[Any, ...], dtype[complex128]])
atol (float)
- Return type:
bool
- openquantumsim.observables.is_density_matrix(matrix, *, atol=1e-10)¶
Return whether
matrixis positive, Hermitian, and trace one.- Parameters:
matrix (ndarray[tuple[Any, ...], dtype[complex128]])
atol (float)
- Return type:
bool
- openquantumsim.observables.normalize_state(state)¶
Normalize a ket by norm or a density matrix by trace.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
ndarray[tuple[Any, …], dtype[complex128]]
- openquantumsim.observables.populations(state)¶
Return basis populations from a ket or density matrix.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- openquantumsim.observables.l1_coherence(state)¶
Basis-dependent l1 coherence, sum of off-diagonal magnitudes.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.bloch_vector(state)¶
Return the Bloch vector
(<sigma_x>, <sigma_y>, <sigma_z>).- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
ndarray[tuple[Any, …], dtype[float64]]
- openquantumsim.observables.evaluate_state_observables(states, observables)¶
Evaluate named scalar callbacks on each saved ket or density matrix.
- Parameters:
states (Sequence[ndarray[tuple[Any, ...], dtype[complex128]]])
observables (Mapping[str, object])
- Return type:
dict[str, ndarray[tuple[Any, …], dtype[complex128]]]
- openquantumsim.observables.state_metrics(*, purity=False, entropy=False, linear_entropy=False, participation_ratio=False, population_indices=None, l1_coherence=False, bloch_vector=False, fidelity_to=None, trace_distance_to=None)¶
Build common state-observable callbacks for solver runs.
The returned mapping can be passed directly to solvers via
state_observables=....mcsolveaggregates built-in metrics in the backend when they reduce to linear expectations or pure-trajectory constants.- Parameters:
purity (bool)
entropy (bool)
linear_entropy (bool)
participation_ratio (bool)
population_indices (Sequence[int] | None)
l1_coherence (bool)
bloch_vector (bool)
fidelity_to (ndarray[tuple[Any, ...], dtype[complex128]] | None)
trace_distance_to (ndarray[tuple[Any, ...], dtype[complex128]] | None)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.fidelity_observable(reference, *, name='fidelity')¶
Return a named fidelity callback mapping for solver runs.
- Parameters:
reference (ndarray[tuple[Any, ...], dtype[complex128]])
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.purity_observable(*, name='purity')¶
Return a named purity callback mapping for solver runs.
- Parameters:
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.entropy_observable(*, name='entropy')¶
Return a named von Neumann entropy callback mapping for solver runs.
- Parameters:
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.linear_entropy_observable(*, normalized=False, name='linear_entropy')¶
Return a named linear-entropy callback mapping for solver runs.
- Parameters:
normalized (bool)
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.participation_ratio_observable(*, name='participation_ratio')¶
Return a named participation-ratio callback mapping for solver runs.
- Parameters:
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.l1_coherence_observable(*, name='l1_coherence')¶
Return a named l1-coherence callback mapping for solver runs.
- Parameters:
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.trace_distance_observable(reference, *, name='trace_distance')¶
Return a named trace-distance callback mapping for solver runs.
- Parameters:
reference (ndarray[tuple[Any, ...], dtype[complex128]])
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.population_observable(index, *, name=None)¶
Return a named callback for one basis population.
- Parameters:
index (int)
name (str | None)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.population_observables(indices, *, prefix='population')¶
Return callbacks for selected basis populations.
- Parameters:
indices (Sequence[int])
prefix (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.bloch_observables(prefix='bloch')¶
Return callbacks for Bloch-vector components.
- Parameters:
prefix (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]
- openquantumsim.observables.partial_trace(state, dims, keep)¶
Trace out all subsystems except
keepfor a ket or density matrix.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dims (Sequence[int])
keep (int | Sequence[int])
- Return type:
ndarray[tuple[Any, …], dtype[complex128]]
- openquantumsim.observables.mutual_information(state, dims, subsystem_a, subsystem_b, *, base=2.0)¶
Quantum mutual information
I(A:B)for arbitrary subsystem groups.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dims (Sequence[int])
subsystem_a (int | Sequence[int])
subsystem_b (int | Sequence[int])
base (float)
- Return type:
float
- openquantumsim.observables.bipartite_mutual_information(state, dim_a, dim_b, *, base=2.0)¶
Quantum mutual information for a two-part system
A ⊗ B.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dim_a (int)
dim_b (int)
base (float)
- Return type:
float
- openquantumsim.observables.partial_traces(state, dim_a, dim_b)¶
Bipartite reduced density matrices for a ket or density matrix.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dim_a (int)
dim_b (int)
- Return type:
tuple[ndarray[tuple[Any, …], dtype[complex128]], ndarray[tuple[Any, …], dtype[complex128]]]