python-math #6: feat(math): PCA warm start in clojure-legacy engine mode (PR-B) - #2640
Draft
jucor wants to merge 1 commit into
Draft
python-math #6: feat(math): PCA warm start in clojure-legacy engine mode (PR-B)#2640jucor wants to merge 1 commit into
jucor wants to merge 1 commit into
Conversation
This was referenced Jul 18, 2026
jucor
marked this pull request as draft
July 18, 2026 13:35
This was referenced Jul 18, 2026
Draft
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Clojure-parity PCA warm-start behavior to the Python Delphi math pipeline when POLISMATH_ENGINE_MODE=clojure-legacy, by threading the previous tick’s PCA components into the power-iteration solver as start vectors, while keeping the default improved mode cold/recompute behavior unchanged.
Changes:
- Extend
pca_project_dataframeto acceptstart_vectorsandrequire_powerit, and ensure sklearn PCA is not used when warm-start/powerit is required (warn + fall back). - In
Conversation._compute_pca, when in legacy mode, require power-iteration and feed previous tick’spca['comps']as warm-start vectors when available. - Add a dedicated test module covering threading, fallback warning, and two-tick warm-start behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
delphi/polismath/pca_kmeans_rep/pca.py |
Adds warm-start/powerit forcing controls and sklearn-conflict warning/fallback; threads start_vectors into powerit_pca. |
delphi/polismath/conversation/conversation.py |
Wires legacy engine mode to require power-iteration and optionally seed PCA from previous tick comps. |
delphi/tests/test_pca_warm_start.py |
New tests validating warm-start threading, warning/fallback behavior, and cold-path invariance across modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
jucor
force-pushed
the
spr/edge/be96f1da
branch
2 times, most recently
from
July 21, 2026 19:49
e5d3b9f to
d75b16a
Compare
This was referenced Jul 22, 2026
Draft
This was referenced Jul 27, 2026
Draft
Draft
python-math #43: docs(delphi): s7 goal state + journal — mode collapse executed, battery 20/20
#2672
Draft
Draft
Draft
5 tasks
3 tasks
…ode (PR-B) ## What When `POLISMATH_ENGINE_MODE=clojure-legacy` (the engine setting that reproduces the old Clojure engine's behavior exactly), the previous tick's unit PCA components are threaded into the power-iteration PCA as start vectors, matching Clojure (`conversation.clj:381-387` passes `:start-vectors (get-in conv [:pca :comps])` into `powerit-pca`, `pca.clj:86-105`; new columns are absorbed by 1-padding, `pca.clj:46-49`). Default `improved` mode is unchanged (cold recompute). ## Changes - `pca_project_dataframe` gains `start_vectors` (default `None`) and `require_powerit` (default `False`). With both absent, the code path is BYTE-IDENTICAL to before. When a warm start is supplied — or required by legacy mode — and `POLISMATH_PCA_IMPL=sklearn` is set, we warn and fall back to power iteration: sklearn's SVD has no start-vector hook, so running it would silently drop the warm start (documented at the guard). - `powerit_pca` already supported `start_vectors` + 1-padding + all-zero -> `None`; this just wires the production callers to it. - `Conversation._compute_pca`: in legacy mode sets `require_powerit=True` and, when `prev_pca` has real components, `start_vectors` = the previous components (empty/cold -> `None`, which yields the deterministic random cold draw). `prev_pca` is captured in `recompute()` (PR-A, the previous commit in this series). ## Semantic judgment calls (integrator, please verify vs Clojure) - The warm start is POSITIONAL: previous components align to current columns by index, and new (appended) comments are 1-padded — exactly Clojure's behavior. Column removal/reorder would misalign, but Clojure is append-only here, and `_power_iteration` truncates a too-long start vector defensively (pre-existing, `pca.py:124-127`) where Clojure would error. - "Legacy implies powerit" is enforced via `require_powerit=True` even on the cold first tick, so an operator setting `PCA_IMPL=sklearn` + legacy still gets power iteration (with a warning). ## Testing TDD RED evidence (before implementing): `test_start_vectors_reach_powerit` — "TypeError: pca_project_dataframe() got an unexpected keyword argument 'start_vectors'"; `test_legacy_tick2_receives_tick1_comps` — "assert None is not None" (tick 2 ran cold; no components threaded). Tests: 8 new (start_vectors threading, sklearn-conflict warning, improved-mode byte-identity, two-tick legacy warm start via spy, angle stability, cold-tick cross-mode identity). Full suite 422 passed, 17 skipped, 47 xfailed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> commit-id:be96f1da
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When
POLISMATH_ENGINE_MODE=clojure-legacy(the engine setting that reproduces the old Clojure engine's behavior exactly), the previous tick's unit PCA components are threaded into the power-iteration PCA as start vectors, matching Clojure (conversation.clj:381-387passes:start-vectors (get-in conv [:pca :comps])intopowerit-pca,pca.clj:86-105; new columns are absorbed by 1-padding,pca.clj:46-49). Defaultimprovedmode is unchanged (cold recompute).Changes
pca_project_dataframegainsstart_vectors(defaultNone) andrequire_powerit(defaultFalse). With both absent, the code path is BYTE-IDENTICAL to before. When a warm start is supplied — or required by legacy mode — andPOLISMATH_PCA_IMPL=sklearnis set, we warn and fall back to power iteration: sklearn's SVD has no start-vector hook, so running it would silently drop the warm start (documented at the guard).powerit_pcaalready supportedstart_vectors+ 1-padding + all-zero ->None; this just wires the production callers to it.Conversation._compute_pca: in legacy mode setsrequire_powerit=Trueand, whenprev_pcahas real components,start_vectors= the previous components (empty/cold ->None, which yields the deterministic random cold draw).prev_pcais captured inrecompute()(PR-A, the previous commit in this series).Semantic judgment calls (integrator, please verify vs Clojure)
_power_iterationtruncates a too-long start vector defensively (pre-existing,pca.py:124-127) where Clojure would error.require_powerit=Trueeven on the cold first tick, so an operator settingPCA_IMPL=sklearn+ legacy still gets power iteration (with a warning).Testing
TDD RED evidence (before implementing):
test_start_vectors_reach_powerit— "TypeError: pca_project_dataframe() got an unexpected keyword argument 'start_vectors'";test_legacy_tick2_receives_tick1_comps— "assert None is not None" (tick 2 ran cold; no components threaded).Tests: 8 new (start_vectors threading, sklearn-conflict warning, improved-mode byte-identity, two-tick legacy warm start via spy, angle stability, cold-tick cross-mode identity). Full suite 422 passed, 17 skipped, 47 xfailed.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
commit-id:be96f1da
Stack: