symop.ccr.algebra.density.partial_trace

Partial trace for symbolic density polynomials.

Given a density polynomial on a factorized Hilbert space \(\mathcal{H} = \mathcal{H}_K \otimes \mathcal{H}_T\), this module traces out a subset of modes corresponding to \(\mathcal{H}_T\).

Each density term is \(c\,|L\rangle\langle R|\). We split the left/right monomials into kept and traced parts and contract the traced subsystem:

\[\mathrm{Tr}_T\!\big(c\,|L\rangle\langle R|\big) = \big(c\,\langle R^T \mid L^T \rangle\big)\,|L^K\rangle\langle R^K|.\]

The overlap \(\langle R^T \mid L^T \rangle\) is evaluated symbolically using the ket inner product.

Functions

density_partial_trace(terms, trace_over_modes)

Partial trace over a subset of modes for a symbolic density polynomial.

_split_monomial_by_modes(m: Monomial, trace_sigs: set[Any]) tuple[Monomial, Monomial]

Partition a monomial into kept vs traced parts.

Operators whose op.mode.signature is not in trace_sigs go to the kept monomial; those whose signatures are in trace_sigs go to the traced monomial. The return value is (kept, traced).

Parameters:
  • m (Monomial)

  • trace_sigs (set[Any])

Return type:

tuple[Monomial, Monomial]

_to_mode_signatures(trace_over_modes: Iterable[object]) set[Any]

Normalize a list of modes to a set of ModeOp.signature keys.

Accepts a heterogeneous iterable containing any of:

  • a ModeOp instance (its signature is used),

  • a LadderOp instance (its mode.signature is used),

  • a Monomial (all of its mode_ops signatures are added),

  • a pre-constructed signature tuple.

Returns a set of signature-tuples suitable for membership checks.

Parameters:

trace_over_modes (Iterable[object])

Return type:

set[Any]

density_partial_trace(terms: tuple[DensityTerm, ...], trace_over_modes: Iterable[object]) tuple[DensityTerm, ...]

Partial trace over a subset of modes for a symbolic density polynomial.

Let the Hilbert space factor as \(\mathcal{H} = \mathcal{H}_K \otimes \mathcal{H}_T\), where \(\mathcal{H}_T\) is the subsystem to be traced out. Each density term is \(c \, |L\rangle \langle R|\). We split the left/right monomials into kept/traced parts and contract the traced pieces:

\[\mathrm{Tr}_T\!\big(c \, |L\rangle\langle R|\big) \;=\; \big(c \, \langle R^T \mid L^T \rangle\big) \; |L^K\rangle\langle R^K|.\]

The overlap \(\langle R^T \mid L^T \rangle\) is evaluated symbolically via ket_inner() on one-term kets built from the traced monomials. Terms with zero contraction are dropped, and identical \(|L^K\rangle\langle R^K|\) terms are merged using combine_like_terms_density().

Parameters:
  • terms (tuple[DensityTerm, ...]) – Input density polynomial.

  • trace_over_modes (Iterable[object]) – Specification of the modes to trace out. May contain ModeOp, LadderOp, Monomial, or raw signature tuples (or a mix).

Returns:

The resulting density polynomial on \(\mathcal{H}_K\) with traced modes removed and coefficients contracted.

Return type:

tuple[DensityTerm, …]