Observables¶
Observable utilities for states and density matrices.
- openquantumsim.observables.expect(operator, state)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
Basis-dependent l1 coherence, sum of off-diagonal magnitudes.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.bloch_vector(state)[source]¶
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)[source]¶
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)[source]¶
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')[source]¶
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')[source]¶
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')[source]¶
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')[source]¶
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')[source]¶
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')[source]¶
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')[source]¶
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)[source]¶
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')[source]¶
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')[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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)[source]¶
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]]]
- openquantumsim.observables.negativity(state, dims, subsystem_a, subsystem_b)[source]¶
Vidal-Werner negativity
(||rho^T_B||_1 - 1) / 2for the AB block.Accepts a ket or density matrix;
dimsdescribes the full tensor product. For separable states the value is zero, and for a maximally entangled two-qubit state it is 0.5.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dims (Sequence[int])
subsystem_a (int | Sequence[int])
subsystem_b (int | Sequence[int])
- Return type:
float
- openquantumsim.observables.logarithmic_negativity(state, dims, subsystem_a, subsystem_b)[source]¶
Logarithmic negativity
log2(||rho^T_B||_1)for the AB block.Measured in bits; a maximally entangled two-qubit state gives 1.0.
- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
dims (Sequence[int])
subsystem_a (int | Sequence[int])
subsystem_b (int | Sequence[int])
- Return type:
float
- openquantumsim.observables.concurrence(state)[source]¶
Wootters concurrence for a two-qubit ket or density matrix.
The state must be a dimension-4 ket or 4x4 density matrix in the computational basis
|00>, |01>, |10>, |11>. Returns zero for separable states and one for maximally entangled states.- Parameters:
state (ndarray[tuple[Any, ...], dtype[complex128]])
- Return type:
float
- openquantumsim.observables.negativity_observable(dims, subsystem_a, subsystem_b, *, name='negativity')[source]¶
Return a named negativity callback mapping for solver runs.
- Parameters:
dims (Sequence[int])
subsystem_a (int | Sequence[int])
subsystem_b (int | Sequence[int])
name (str)
- Return type:
dict[str, Callable[[ndarray[tuple[Any, …], dtype[complex128]]], Any]]