Monitor — Merge Window¶
MergeWindowMonitor is the PHA-C.4 runtime gate for deciding when a
moving-frame phase cluster has actually merged. It combines two predicates:
wrapped phase dispersion around a reference phase and axial spatial dispersion
around a reference point. The monitor emits lock_achieved=True only after both
predicates remain inside tolerance for the configured number of consecutive
samples.
What it is for¶
The monitor is intended for PHA-C pipelines where phase dynamics and physical or abstract position are both meaningful. Examples include moving-frame UPDE runs, coalescence studies, chamber or conveyor synchronization, plasma or beam alignment experiments, robotic swarms, and digital-twin cells where a phase lock alone is not enough evidence that the population has spatially merged.
Contract¶
- Phase dispersion:
max_i |wrap(theta_i - theta_ref)| <= phase_tol_rad. - Spatial dispersion:
max_i |z_i - z_ref| <= spatial_tol_m. - Signed margins:
phase_margin_rad = phase_tol_rad - phase_dispersion_radandspatial_margin_m = spatial_tol_m - spatial_dispersion_m. - Signed-margin replay tolerance:
MERGE_WINDOW_MARGIN_REPLAY_TOLERANCE. - Consecutive gate: both predicates must pass for
required_consecutive_samples. - Default tolerances:
phase_tol_rad=0.01,spatial_tol_m=0.002,required_consecutive_samples=3. - Named profiles multiply the reviewed baseline:
baseline_1x,buffer_3x, andreview_5x. - Public scalar and vector inputs must contain finite real numeric evidence before conversion. Boolean, complex, numeric-string, and broken array-protocol payloads fail closed; real numeric object arrays remain valid.
- A directly constructed tolerance profile must replay its reviewed name,
multiplier, baseline, and resolved tolerances. A directly constructed
MergeReportindependently validates finite scalar fields, non-negative dispersions, canonical booleans/counts, signed-margin lock semantics, and the current joint-lock/count relationship before it can be serialised. - Evidence boundary: benchmark timings are local regression evidence unless run under the documented isolated-core benchmark protocol.
import numpy as np
from scpn_phase_orchestrator.monitor.merge_window import MergeWindowMonitor
monitor = MergeWindowMonitor(
phase_tol_rad=0.01,
spatial_tol_m=0.002,
required_consecutive_samples=3,
)
for t in range(3):
report = monitor.evaluate(
np.array([0.0, 0.004, -0.005]),
np.array([0.0, 0.001, -0.0015]),
t=float(t),
)
assert report.lock_achieved
Tolerance profiles¶
PHA-C and MIF/FRC review lanes often need to separate the reviewed baseline
window from wider diagnostic buffers. resolve_merge_window_tolerance_profile
keeps that boundary explicit:
from scpn_phase_orchestrator.monitor.merge_window import (
MergeWindowMonitor,
resolve_merge_window_tolerance_profile,
)
profile = resolve_merge_window_tolerance_profile("buffer_3x")
assert profile.spatial_tol_m == 0.006
monitor = MergeWindowMonitor(tolerance_profile="buffer_3x")
The default baseline is 0.01 rad and 0.002 m. Passing explicit
phase_tol_rad or spatial_tol_m with a profile treats those values as the
baseline before applying the multiplier.
Polyglot surfaces¶
The Python monitor is the public runtime reference. Rust, Go, Julia, and Mojo
source-contract adapter modules are present for parity gates and downstream
accelerator wiring. The benchmark gate records all declared backend slots and
labels the local workstation timing data as non-isolated evidence. Adapter
parity includes the signed margin fields, so a backend cannot pass with only
boolean lock evidence. The benchmark payload also publishes
phase_margin_equation_validated, spatial_margin_equation_validated,
signed_margin_equations_validated, and margin_replay_tolerance; the gate
fails unless every declared backend row proves both signed-margin equations.
The shared accelerator validator checks raw MergeReport fields before parity
comparison: numeric fields must be finite real non-boolean scalars, lock fields
must be plain booleans, consecutive counts must be non-negative integers, and
the comparison tolerance itself must be finite and non-negative.
Event/state handoff¶
When the merge-window report must cross into MIF, Studio, audit replay, or
another downstream PHA-C lane, use
build_pha_c_handoff_record(...). It binds the merge report to the source
phase and position digests, adds signed margin and order-parameter evidence,
and fixes the
non-actuating claim boundary for later review.
from scpn_phase_orchestrator.upde.pha_c_handoff import (
build_pha_c_handoff_record,
)
handoff = build_pha_c_handoff_record(
phases,
positions,
phase_tol_rad=0.01,
spatial_tol_m=0.002,
required_consecutive_samples=3,
)
Operational role¶
- This monitor is the gate where “mostly synchronized” becomes “merged” in a replayable way.
- Signed-margin outputs are what operators use to tune recovery aggressiveness without guessing how close the signal was to the boundary.
- The handoff record keeps review lanes deterministic: MIF, Studio, and audit replay all receive the same lock/evidence contract.
What this means for operations¶
Merge-window gates are most useful when teams need a binary operational decision
(lock_achieved) plus a continuous confidence context (margins).
The signed-margin design makes recovery tuning possible without guesswork:
phase_margin_radandspatial_margin_mquantify how far the current state is from the lock boundary.required_consecutive_samplesfilters transients and reduces false merge-on-spike behaviour.
In production review lanes, that combination is what allows teams to avoid both premature lock declarations and excessive delay in returning to active control.
merge_window ¶
Phase-and-space merge-window lock monitor.
The PHA-C moving-frame lane tracks phase theta and axial position z for
candidate merger/coalescence events. A merge is accepted only when both the
wrapped phase dispersion and the axial spatial dispersion remain inside their
reviewed tolerances for a configured number of consecutive samples.
Classes¶
MergeWindowToleranceProfile
dataclass
¶
MergeWindowToleranceProfile(
name: str,
phase_tol_rad: float,
spatial_tol_m: float,
multiplier: float,
baseline_phase_tol_rad: float,
baseline_spatial_tol_m: float,
)
Resolved phase and spatial tolerances for a PHA-C merge window.
Methods:¶
__post_init__ ¶
Validate and normalise the resolved named-profile evidence.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
MergeReport
dataclass
¶
MergeReport(
t: float,
phase_dispersion_rad: float,
spatial_dispersion_m: float,
phase_margin_rad: float,
spatial_margin_m: float,
phase_locked: bool,
spatial_locked: bool,
lock_achieved: bool,
consecutive_lock_samples: int,
)
Audit-ready merge-window state for one sampled instant.
Attributes¶
t: Sample timestamp in the caller's runtime units.
phase_dispersion_rad: Maximum wrapped distance to the reference phase.
spatial_dispersion_m: Maximum axial distance to the reference point.
phase_margin_rad: Signed distance from phase tolerance to dispersion.
spatial_margin_m: Signed distance from spatial tolerance to dispersion.
phase_locked: True when phase margin is non-negative.
spatial_locked: True when spatial margin is non-negative.
lock_achieved: True after the required consecutive joint-lock count.
consecutive_lock_samples: Current consecutive joint-lock count.
Methods:¶
__post_init__ ¶
Validate and normalise directly constructed merge evidence.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
MergeWindowMonitor ¶
MergeWindowMonitor(
*,
phase_tol_rad: object = DEFAULT_PHASE_TOL_RAD,
spatial_tol_m: object = DEFAULT_SPATIAL_TOL_M,
required_consecutive_samples: object = 3,
tolerance_profile: object | None = None,
)
Stateful consecutive-sample gate for PHA-C merge events.
Initialise the stateful merge gate.
Parameters¶
phase_tol_rad : object
Baseline phase tolerance in radians.
spatial_tol_m : object
Baseline spatial tolerance in metres.
required_consecutive_samples : object
Positive joint-lock sample count required for acceptance.
tolerance_profile : object | None
Reviewed named tolerance profile, or None for explicit values.
Raises¶
ValueError If a tolerance, count, or named-profile contract is invalid.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
Attributes¶
consecutive_lock_samples
property
¶
Methods:¶
reset ¶
evaluate ¶
evaluate(
phases: ArrayLike,
positions: ArrayLike,
*,
t: object = 0.0,
reference_phase: object = 0.0,
reference_point: object = 0.0,
) -> MergeReport
Evaluate one sample and update the consecutive joint-lock counter.
Parameters¶
phases : ArrayLike
Oscillator phases in radians, shape (N,).
positions : ArrayLike
Absolute axial coordinates per oscillator, shape (N,).
t : object
Absolute time of the sample in seconds.
reference_phase : object
Reference phase for the lock criterion, in radians.
reference_point : object
Reference axial coordinate for the spatial-margin criterion.
Returns¶
MergeReport The merge-window report with the updated lock counter.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
__call__ ¶
__call__(
phases: ArrayLike,
positions: ArrayLike,
*,
t: object = 0.0,
reference_phase: object = 0.0,
reference_point: object = 0.0,
) -> MergeReport
Alias for :meth:evaluate for monitor-pipeline call sites.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
Functions:¶
resolve_merge_window_tolerance_profile ¶
resolve_merge_window_tolerance_profile(
tolerance_profile: object,
*,
phase_baseline_rad: object = DEFAULT_PHASE_TOL_RAD,
spatial_baseline_m: object = DEFAULT_SPATIAL_TOL_M,
) -> MergeWindowToleranceProfile
Resolve a named PHA-C tolerance profile into numeric tolerances.
Parameters¶
tolerance_profile : object
Named tolerance profile, or None for the baseline.
phase_baseline_rad : object
Baseline phase tolerance in radians.
spatial_baseline_m : object
Baseline spatial tolerance in metres.
Returns¶
MergeWindowToleranceProfile The resolved numeric tolerance profile.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
evaluate_merge_window ¶
evaluate_merge_window(
phases: ArrayLike,
positions: ArrayLike,
*,
t: object = 0.0,
reference_phase: object = 0.0,
reference_point: object = 0.0,
phase_tol_rad: object = DEFAULT_PHASE_TOL_RAD,
spatial_tol_m: object = DEFAULT_SPATIAL_TOL_M,
required_consecutive_samples: object = 3,
prior_consecutive_lock_samples: object = 0,
tolerance_profile: object | None = None,
) -> MergeReport
Evaluate one PHA-C merge-window sample.
Phase lock is max_i |wrap(theta_i - theta_ref)| <= phase_tol_rad.
Spatial lock is max_i |z_i - z_ref| <= spatial_tol_m. The combined lock
counter increments only when both predicates pass; otherwise it resets to
zero. lock_achieved becomes true once the counter reaches
required_consecutive_samples.
Parameters¶
phases : ArrayLike
Oscillator phases in radians, shape (N,).
positions : ArrayLike
Absolute axial coordinates per oscillator, shape (N,).
t : object
Absolute time of the sample in seconds.
reference_phase : object
Reference phase for the lock criterion, in radians.
reference_point : object
Reference axial coordinate for the spatial-margin criterion.
phase_tol_rad : object
Phase lock tolerance in radians.
spatial_tol_m : object
Spatial lock tolerance in metres.
required_consecutive_samples : object
Consecutive in-tolerance samples required to declare lock.
prior_consecutive_lock_samples : object
Consecutive lock-sample count carried in from a prior window.
tolerance_profile : object | None
Named tolerance profile, or None for the baseline.
Returns¶
MergeReport The merge-window evaluation report for the sample.
Raises¶
ValueError If any input is invalid.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
merge_window_report_to_dict ¶
Convert a :class:MergeReport into a JSON-safe dictionary.
Parameters¶
report : MergeReport The merge-window report to serialise.
Returns¶
dict[str, float | int | bool] The JSON-safe merge-window report dictionary.
Source code in src/scpn_phase_orchestrator/monitor/merge_window.py
merge_window_tolerance_profile_to_dict ¶
merge_window_tolerance_profile_to_dict(
profile: MergeWindowToleranceProfile,
) -> dict[str, float | str]
Convert a resolved tolerance profile into a JSON-safe dictionary.
Parameters¶
profile : MergeWindowToleranceProfile The resolved tolerance profile to serialise.
Returns¶
dict[str, float | str] The JSON-safe tolerance-profile dictionary.