symop.ccr.common.keys¶
Key helpers for CCR algebra canonicalization.
This module defines small, strict helpers that produce hashable keys for grouping and sorting CCR objects in algorithms such as “combine like terms”.
Keys vs signatures¶
Objects in the CCR layer expose:
signature: exact structural identity.approx_signature(decimals=..., ignore_global_phase=...): identity under an approximation scheme based on rounding and optional phase normalization.
A key is the value used by algorithms to bucket or sort objects. In most cases, the key is simply the object’s signature (exact or approximate), but this module centralizes the decision logic to keep the CCR layer consihstent.
Strict keyword convention¶
This project standardizes approximate signatures to accept only:
decimals: intignore_global_phase: bool
Accordingly, the helpers in this module do not accept **kwargs and forward
only these parameters.
Notes
This module should remain dependency-light and must not import concrete CCR polynomial implementations. It is intended to sit near the bottom of the CCR dependency tree.
Functions
|
Return an exact or approximate key for a ladder operator. |
|
Return an exact or approximate key for a signature-bearing object. |
|
Return a key for an operator word (ordered product of ladder operators). |
- sig_lop(op: HasSignature, *, approx: bool = False, decimals: int = 12, ignore_global_phase: bool = False) tuple[object, ...]¶
Return an exact or approximate key for a ladder operator.
- Parameters:
op (
HasSignature) – A ladder-operator-like object withsignatureandapprox_signature(decimals=..., ignore_global_phase=...).approx (
bool) – IfTrue, returnop.approx_signature(...). IfFalse, returnop.signature.decimals (
int) – Number of decimals to round to (forwarded toapprox_signature).ignore_global_phase (
bool) – IfTrue, treat global phase parameters as zero for grouping (forwarded toapprox_signature).
- Returns:
Hashable ladder-operator key.
- Return type:
SignatureProto
Notes
This function exists mostly for readability. It is equivalent to
sig_obj()but communicates intent at call sites.
- sig_obj(obj: HasSignature, *, approx: bool = False, decimals: int = 12, ignore_global_phase: bool = False) tuple[object, ...]¶
Return an exact or approximate key for a signature-bearing object.
- Parameters:
obj (
HasSignature) – Any object that providessignatureandapprox_signature(decimals=..., ignore_global_phase=...).approx (
bool) – IfTrue, returnobj.approx_signature(...). IfFalse, returnobj.signature.decimals (
int) – Number of decimals to round to (forwarded toapprox_signature).ignore_global_phase (
bool) – IfTrue, treat global phase parameters as zero for grouping (forwarded toapprox_signature).
- Returns:
A hashable signature tuple suitable for use as a dictionary key.
- Return type:
SignatureProto
- sig_word(ops: Iterable[HasSignature], *, approx: bool = False, decimals: int = 12, ignore_global_phase: bool = False) tuple[tuple[object, ...], ...]¶
Return a key for an operator word (ordered product of ladder operators).
- Parameters:
ops (
Iterable[HasSignature]) – Iterable of ladder operators defining a word. The iterable is materialized into a tuple to make the key stable and hashable.approx (
bool) – IfTrue, each operator key is taken fromapprox_signature(...). IfFalse, each operator key is taken fromsignature.decimals (
int) – Number of decimals to round to (forwarded to eachapprox_signature).ignore_global_phase (
bool) – IfTrue, treat global phase parameters as zero for grouping (forwarded to eachapprox_signature).
- Returns:
Hashable key representing the ordered operator word.
- Return type:
tuple[SignatureProto, …]