Skip to content

python-math #5: feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A) - #2618

Draft
jucor wants to merge 1 commit into
spr/edge/2324207efrom
spr/edge/d61d82ad
Draft

python-math #5: feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A)#2618
jucor wants to merge 1 commit into
spr/edge/2324207efrom
spr/edge/d61d82ad

Conversation

@jucor

@jucor jucor commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

What

Introduces POLISMATH_ENGINE_MODE, the engine-mode switch that will select between Clojure-parity warm-start behavior (clojure-legacy — the setting that reproduces the old Clojure engine's tick-to-tick behavior exactly) and the current cold-recompute behavior (improved, the default). This commit only adds the flag and the plumbing to capture the previous tick's state (a tick = one incremental math recompute over newly arrived votes); no behavior changes yet — the follow-up commits PR-B and PR-D consume the captured state.

Changes

  • New polismath/utils/engine_mode.py: ENGINE_MODE_* constants + resolve_engine_mode(), reusing pca._resolve_impl_flag (pca.py:37-57) so resolution rules match the PCA-solver switch. Default improved.
  • Conversation.__init__ gains cold-default fields group_clusterings={} and group_k_smoother={} (the Clojure engine threads these on the conversation object across ticks, conversation.clj:433-484; NOT persisted, per conv_man.clj:52-74).
  • recompute() captures prev_pca / prev_group_clusterings / prev_group_k_smoother from the deepcopied result BEFORE the compute steps overwrite them (mirroring the Clojure fnks that read the incoming conversation: conversation.clj:385, 457) and threads them into _compute_pca / _compute_clusters as optional params (unused in this commit).

Testing

TDD RED evidence (before implementing engine_mode.py): tests/test_engine_mode.py collection error — "ModuleNotFoundError: No module named 'polismath.utils.engine_mode'".

Cold-start invariance guard: a single-shot pipeline run on the small vw test conversation dataset is byte-identical under both modes (first-tick warm-start state is empty, so the modes must coincide). This guards PR-B and PR-D against drifting on the cold path.

Tests: 8 new (7 flag-resolution + 1 cold invariance). Full suite 414 passed, 17 skipped, 47 xfailed (was 406/17/47).

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

commit-id:d61d82ad


Stack:


⚠️ Part of a stack created by spr. Do not merge manually using the UI - doing so may have unexpected results.

@jucor
jucor marked this pull request as draft July 18, 2026 01:48
@jucor
jucor force-pushed the spr/edge/d61d82ad branch from d27ed5f to 29d0998 Compare July 18, 2026 01:59
@jucor jucor changed the title feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A) feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start sca… Jul 18, 2026
@jucor
jucor changed the base branch from spr/edge/c9daf6b3 to edge July 18, 2026 13:27
@jucor
jucor force-pushed the spr/edge/d61d82ad branch from 29d0998 to 4d179bd Compare July 18, 2026 13:28
@jucor jucor changed the title feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start sca… feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A) Jul 18, 2026
@jucor jucor mentioned this pull request Jul 18, 2026
@jucor
jucor changed the base branch from edge to spr/edge/d83b0abf July 18, 2026 13:28
This was referenced Jul 27, 2026
@jucor
jucor force-pushed the spr/edge/d61d82ad branch from a4bf15a to 4eff15b Compare July 28, 2026 00:11
@jucor
jucor force-pushed the spr/edge/2324207e branch from acaddd8 to 4dec574 Compare July 28, 2026 00:12
@jucor jucor changed the title feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A) python-math #5: feat(math): add POLISMATH_ENGINE_MODE flag + prev-tick warm-start scaffolding (PR-A) Jul 28, 2026
…k warm-start scaffolding (PR-A)

## What

Introduces `POLISMATH_ENGINE_MODE`, the engine-mode switch that will select between Clojure-parity warm-start behavior (`clojure-legacy` — the setting that reproduces the old Clojure engine's tick-to-tick behavior exactly) and the current cold-recompute behavior (`improved`, the default). This commit only adds the flag and the plumbing to capture the previous tick's state (a tick = one incremental math recompute over newly arrived votes); no behavior changes yet — the follow-up commits PR-B and PR-D consume the captured state.

## Changes

- New `polismath/utils/engine_mode.py`: `ENGINE_MODE_*` constants + `resolve_engine_mode()`, reusing `pca._resolve_impl_flag` (`pca.py:37-57`) so resolution rules match the PCA-solver switch. Default `improved`.
- `Conversation.__init__` gains cold-default fields `group_clusterings={}` and `group_k_smoother={}` (the Clojure engine threads these on the conversation object across ticks, `conversation.clj:433-484`; NOT persisted, per `conv_man.clj:52-74`).
- `recompute()` captures `prev_pca` / `prev_group_clusterings` / `prev_group_k_smoother` from the deepcopied `result` BEFORE the compute steps overwrite them (mirroring the Clojure fnks that read the incoming conversation: `conversation.clj:385, 457`) and threads them into `_compute_pca` / `_compute_clusters` as optional params (unused in this commit).

## Testing

TDD RED evidence (before implementing `engine_mode.py`): `tests/test_engine_mode.py` collection error — "ModuleNotFoundError: No module named 'polismath.utils.engine_mode'".

Cold-start invariance guard: a single-shot pipeline run on the small `vw` test conversation dataset is byte-identical under both modes (first-tick warm-start state is empty, so the modes must coincide). This guards PR-B and PR-D against drifting on the cold path.

Tests: 8 new (7 flag-resolution + 1 cold invariance). Full suite 414 passed, 17 skipped, 47 xfailed (was 406/17/47).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

commit-id:d61d82ad
@jucor
jucor force-pushed the spr/edge/2324207e branch from 4dec574 to 10de96c Compare July 28, 2026 01:10
@jucor
jucor force-pushed the spr/edge/d61d82ad branch from 4eff15b to 236f8ea Compare July 28, 2026 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants