symop.polynomial.state.ket¶
Polynomial ket-state wrapper.
This module provides a lightweight state container around
KetPoly, exposing semantic
information about modes, paths, and labels derived from the
polynomial representation.
The wrapper serves several roles:
attaches lightweight metadata (label, index) to a ket polynomial
exposes convenient views of the modes contained in the state
supports relabeling operations used by device kernels
provides normalization helpers for ket states
Important
Mode labels are not stored independently. They are derived directly from the concrete modes present in the ket polynomial, ensuring that semantic information always reflects the actual algebraic state.
The wrapper also enforces the ket-state invariant that the underlying polynomial is creators only (plus the identity term).
Classes
|
Polynomial ket state wrapper. |
- class KetPolyState(ket: KetPoly, label: str | None = None, index: int | None = <factory>) None¶
Bases:
objectPolynomial ket state wrapper.
Invariant¶
The underlying ket polynomial must be creators only (plus identity).
Notes
Semantic mode information is derived from the concrete modes present in
ket. In particular, mode labels are not stored independently; they are derived from the unique modes appearing in the polynomial.- property _mode_by_signature_cached: dict[tuple[object, ...], ModeOp]¶
Cache a lookup from mode signature to mode object.
- Returns:
Mapping from mode signature to the corresponding concrete mode.
- Return type:
dict[Signature, ModeOpProtocol]
- property _mode_labels_cached: dict[tuple[object, ...], ModeLabel]¶
Cache a lookup from mode signature to semantic mode label.
- Returns:
Mapping from mode signature to the corresponding mode label.
- Return type:
dict[Signature, ModeLabelProtocol]
- property _modes_cached: tuple[ModeOp, ...]¶
Cache the unique modes appearing in the ket polynomial.
- Returns:
Unique modes extracted from
ketin the order provided byKetPoly.unique_modes.- Return type:
tuple[ModeOpProtocol, …]
- apply_label_edits(edits: Sequence[LabelEdit]) KetPolyState¶
Apply semantic label edits to the state.
- Parameters:
edits (
Sequence[LabelEdit]) – Sequence of label edits to apply.- Returns:
New state with the requested label changes applied.
- Return type:
- Raises:
KeyError – If an edit refers to a missing mode signature.
NotImplementedError – If a delete-label edit is requested.
TypeError – If an unsupported edit type is encountered.
Notes
Since labels are derived from concrete modes in the ket polynomial, edits are implemented by rebuilding the affected modes and relabeling them algebraically.
- filtered_on_path(*, in_path: Path, out_path: Path | None, update_label: Callable[[ModeLabel], ModeLabel]) KetPolyState¶
Apply a label update to all modes on an input path.
- Parameters:
- Returns:
New state with updated labels for all modes on
in_path.- Return type:
Notes
This is a convenience helper for path-bound devices whose action is naturally expressed as a relabeling of all modes on a selected path.
- static from_creators(creators: Iterable[LadderOp], *, coeff: complex = 1.0) KetPolyState¶
Build a ket state from a word of creation operators.
- Parameters:
- Returns:
Ket state constructed from the supplied creation-operator word.
- Return type:
- Raises:
ValueError – If any supplied operator is not a creation operator.
- static from_ketpoly(ket: KetPoly) KetPolyState¶
Construct a state wrapper from a ket polynomial.
- Parameters:
ket (
KetPoly) – Ket polynomial to wrap.- Returns:
New wrapper around the combined ket polynomial.
- Return type:
- join(other: KetPolyState) KetPolyState¶
Return the algebraic join of two ket states.
- Parameters:
other (
KetPolyState) – Ket state to combine with this state.- Returns:
Product state obtained by multiplying the two underlying ket polynomials.
- Return type:
Notes
This is a convenience alias for
multiply(). It is useful in contexts where combining states is more naturally described as joining branches or subsystems.
- label_for_mode(mode_sig: tuple[object, ...]) ModeLabel¶
Return the semantic label for a given mode signature.
- labels_on_path(path: Path) dict[tuple[object, ...], ModeLabel]¶
Return labels for all modes on a given path.
- Parameters:
path (
Path) – Path identifier.- Returns:
Mapping from mode signature to semantic label for modes on the given path.
- Return type:
dict[Signature, ModeLabelProtocol]
- property mode_by_signature: dict[tuple[object, ...], ModeOp]¶
Return a lookup from mode signature to mode object.
- Returns:
Mapping from mode signature to the corresponding mode.
- Return type:
dict[Signature, ModeOpProtocol]
- property mode_labels: dict[tuple[object, ...], ModeLabel]¶
Return a lookup from mode signature to semantic label.
- Returns:
Mapping from mode signature to the corresponding mode label.
- Return type:
dict[Signature, ModeLabelProtocol]
- property modes: tuple[ModeOp, ...]¶
Return the unique modes present in the ket polynomial.
- Returns:
Unique modes appearing in
ket.- Return type:
tuple[ModeOpProtocol, …]
- modes_on_path(path: Path) tuple[ModeOp, ...]¶
Return all modes that live on a given path.
- Parameters:
path (
Path) – Path identifier.- Returns:
Modes whose label path matches
path.- Return type:
tuple[ModeOpProtocol, …]
Notes
If no modes exist on the requested path, an empty tuple is returned.
- multiply(other: KetPolyState) KetPolyState¶
Return the symbolic product of two ket states.
- Parameters:
other (
KetPolyState) – Ket state whose polynomial should be multiplied onto this state.- Returns:
State wrapper around the combined product polynomial.
- Return type:
Notes
This operation does not require orthogonal or disjoint modes. It multiplies the underlying ket polynomials algebraically and returns the resulting creators-only state wrapper.
- property norm2: float¶
Return the squared norm of the ket state.
- Returns:
Squared norm of the underlying ket polynomial.
- Return type:
- normalized(*, eps: float = 1e-14) KetPolyState¶
Return a normalized copy of the ket state.
- Parameters:
eps (
float) – Threshold used internally by ket normalization.- Returns:
New state with normalized ket polynomial.
- Return type:
- relabel_labels(label_map: dict[tuple[object, ...], ModeLabel]) KetPolyState¶
Return a new ket state with selected labels replaced.
- relabel_modes(mode_map: dict[tuple[object, ...], ModeOp]) KetPolyState¶
Return a new ket state with selected
ModeOpobjectss relabeled.- Parameters:
mode_map (
dict[tuple[object,...],ModeOp]) – Mapping from old labels to replacement label.- Returns:
New state with all matching mode paths updated.
- Return type:
Notes
Only modes whose current path appears in
mode_mapare modified. Other modes are left unchanged.
- relabel_paths(path_map: dict[Path, Path]) KetPolyState¶
Return a new ket state with selected paths relabeled.
- Parameters:
path_map (
dict[Path,Path]) – Mapping from old paths to replacement paths.- Returns:
New state with all matching mode paths updated.
- Return type:
Notes
Only modes whose current path appears in
path_mapare modified. Other modes are left unchanged.
- property rep_kind: Literal['poly']¶
Return the representation kind of this state.
- Returns:
The polynomial representation kind.
- Return type:
Literal[“poly”]
- resolve_target_modes(target: MeasurementTarget) tuple[ModeOp, ...]¶
Resolve a semantic measurement target into concrete modes.
- Parameters:
target (
MeasurementTarget) – Semantic measurement target specifying paths and/or explicit mode signatures to be selected.- Returns:
Concrete modes selected by the target. Modes referenced both by path and by explicit signature are returned only once.
- Return type:
tuple[ModeOpProtocol, …]
Notes
Resolution proceeds by first collecting all modes on the target paths and then adding any explicitly requested mode signatures. Missing explicit signatures are ignored.
- property state_kind: Literal['ket']¶
Return the state kind of this object.
- Returns:
The ket-state kind.
- Return type:
Literal[“ket”]
- to_density() DensityPolyState¶
Convert the ket state to the corresponding pure density state.
- Returns:
Pure density-state wrapper constructed from this ket state.
- Return type:
- static vacuum() KetPolyState¶
Construct the vacuum state.
- Returns:
Ket state represented by the identity-only ket polynomial.
- Return type:
- with_index(index: int | None) KetPolyState¶
Return a copy of the state with a new index.
- Parameters:
- Returns:
New state instance with updated index.
- Return type:
Notes
The index is typically used to distinguish states in simulation pipelines or logging but has no semantic meaning for the state representation itself.
- with_label(label: str | None) KetPolyState¶
Return a copy of the state with a new human-readable label.
- Parameters:
label (
str|None) – Optional label attached to the state wrapper.- Returns:
New state instance with updated label.
- Return type:
Notes
This label is metadata only and does not affect the underlying polynomial representation.
- _ket_check: KetPolyState¶