symop.polynomial.kernels.measurements.number.detect¶
Detection kernel for polynomial density-state number measurement.
This module implements stochastic number-detection evaluation for polynomial density states.
The kernel resolves the number distribution associated with a semantic
DetectAction, samples an
outcome according to that distribution, projects the density state onto
the sampled outcome sector, and returns the corresponding
DetectionResult.
Both ordinary number detection and joint per-port number detection are
supported. The selected behavior is determined by the measurement
grouping specified in action.resolution.grouping.
Notes
For polynomial density states, the probability of a sampled outcome is obtained from the trace of the projected density state. If the measurement is destructive, the measured modes are discarded by tracing them out after postselection and normalization.
Random sampling uses ctx.rng when the apply context implements
SupportsRng.
Otherwise, a fresh random.Random instance is created.
- raises ValueError:
If detection is attempted on an empty resolved number distribution.
Functions
Sample a number-detection outcome for a polynomial density state. |
- detect_number_detector_poly_density(*, state: DensityPolyState, action: DetectAction, ctx: ApplyContext | None = None) DetectionResult¶
Sample a number-detection outcome for a polynomial density state.
- Parameters:
state (
DensityPolyState) – Polynomial density-state wrapper on which number detection is performed.action (
DetectAction) – Semantic detect action defining the measurement target, resolution, and whether the measurement is destructive.ctx (
ApplyContext|None) – Optional apply context. If it implementsSupportsRng, its random-number generator is used for sampling.
- Returns:
Detection result containing the sampled outcome, the associated record, the probability of the sampled branch, and the postselected output state when that branch has nonzero weight.
- Return type:
DetectionResult
- Raises:
ValueError – If the resolved number distribution is empty and therefore no outcome can be sampled.
Notes
If
action.resolution.groupingis"joint_ports", joint per-port number statistics are resolved and sampled. Otherwise, ordinary number statistics on the selected target are used.The sampled branch is obtained by projecting
stateonto the chosen outcome sector. Its branch probability is computed as\[p = \mathrm{Tr}(\rho_{\mathrm{proj}}).\]If the probability is strictly positive, the projected state is trace-normalized before being returned. If the action is destructive, the measured subsystem is then discarded by tracing out the measured modes.
If the sampled branch has non-positive probability, the returned result contains
state=Noneand probability0.0.