tn_noise_learning.losses#
Loss terms for LPDO training: transition probabilities, negative log-likelihood, trace-preservation penalty.
Every loss term has the signature term(lpdo_tn, probs) -> scalar so that custom terms plug into
TrainingConfig.extra_loss_terms exactly like the built-in ones.
measurement_network #
measurement_network(
povms: ndarray | Array,
) -> qtn.TensorNetwork
Batched POVM effects povms[j, exp] (shape (num_sites, batch, 2, 2)) as tensors (exp, bn_j, kn_j).
Source code in src/tn_noise_learning/losses.py
41 42 43 44 45 46 47 48 | |
negative_log_likelihood #
negative_log_likelihood(
lpdo_tn: TensorNetwork, probs: ndarray
) -> jnp.ndarray
-mean(log p) over the batch, the KL divergence up to a data-dependent constant.
Source code in src/tn_noise_learning/losses.py
67 68 69 | |
probabilities #
probabilities(
lpdo_tn: TensorNetwork,
states: ndarray | Array,
povms: ndarray | Array,
circuit_tn: TensorNetwork | None = None,
optimize: str = "auto-hq",
) -> jnp.ndarray
Transition probabilities Tr[E Λ(U ρ U†)] for a batch of (state, effect) pairs, clipped from below.
Source code in src/tn_noise_learning/losses.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
tp_penalty #
tp_penalty(
lpdo_tn: TensorNetwork, probs: ndarray | None = None
) -> jnp.ndarray
Squared relative distance of the output-traced channel from the identity, ‖Tr_out Λ − 𝟙‖_F² / 2**n.
Squaring keeps the gradient proportional to the violation, so large weights act as a smooth quadratic
constraint. The likelihood alone rewards inflating the channel's trace, which this term counteracts; at
weight w the equilibrium trace exceeds 2**n by a factor 1 + 1/(2w).
Source code in src/tn_noise_learning/losses.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |