Skip to content

refactor(math): move impl-flag resolver to polismath/utils/env_flags.py#2641

Draft
jucor wants to merge 1 commit into
spr/edge/18c7048ffrom
spr/edge/bc0518d7
Draft

refactor(math): move impl-flag resolver to polismath/utils/env_flags.py#2641
jucor wants to merge 1 commit into
spr/edge/18c7048ffrom
spr/edge/bc0518d7

Conversation

@jucor

@jucor jucor commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Move the generic legacy-vs-improved env-switch resolver out of pca.py into
polismath/utils/env_flags.py (public name resolve_impl_flag). pca.py and
utils/engine_mode.py both import it from there, so reading
POLISMATH_ENGINE_MODE no longer drags the numpy/pandas pca import chain,
and resolution warnings log under polismath.utils.env_flags instead of the
pca logger. Resolution rules unchanged (strip+lowercase, unknown -> default
with warning, read at call time). tests/test_env_flags.py pins the rules,
the shared-resolver identity, and the light engine_mode import (RED observed
on ModuleNotFoundError before the move; the light-import test fails on the
old code by construction).

commit-id:bc0518d7


Stack:


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

Move the generic legacy-vs-improved env-switch resolver out of pca.py into
polismath/utils/env_flags.py (public name resolve_impl_flag). pca.py and
utils/engine_mode.py both import it from there, so reading
POLISMATH_ENGINE_MODE no longer drags the numpy/pandas pca import chain,
and resolution warnings log under polismath.utils.env_flags instead of the
pca logger. Resolution rules unchanged (strip+lowercase, unknown -> default
with warning, read at call time). tests/test_env_flags.py pins the rules,
the shared-resolver identity, and the light engine_mode import (RED observed
on ModuleNotFoundError before the move; the light-import test fails on the
old code by construction).

commit-id:bc0518d7
This was referenced Jul 22, 2026
@jucor
jucor marked this pull request as draft July 22, 2026 00:51
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 02:01
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 02:02
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 02:10
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 02:10
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 03:54
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 03:54
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 06:16
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 06:16
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 06:50
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 06:50
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 08:11
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 08:11
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 09:58
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 09:58
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 22, 2026 11:21
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 22, 2026 11:21
@jucor
jucor changed the base branch from spr/edge/18c7048f to edge July 24, 2026 06:02
@jucor
jucor changed the base branch from edge to spr/edge/18c7048f July 24, 2026 06:02
@jucor
jucor requested a review from Copilot July 25, 2026 22:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the legacy-vs-improved environment-flag resolver out of the PCA module into a lightweight utility module so POLISMATH_ENGINE_MODE can be read without importing the NumPy/Pandas PCA chain, while keeping resolution semantics (strip+lowercase, invalid→default+warning, read-at-call-time) unchanged.

Changes:

  • Add polismath.utils.env_flags.resolve_impl_flag as the shared env-switch resolver.
  • Update polismath.utils.engine_mode and polismath.pca_kmeans_rep.pca to use the shared resolver.
  • Add tests/test_env_flags.py to pin resolver behavior, shared-identity, and “engine_mode import doesn’t load pca” behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
delphi/polismath/utils/env_flags.py Introduces shared, lightweight env-flag resolver with warning-on-invalid behavior.
delphi/polismath/utils/engine_mode.py Switches engine-mode resolution to use the new shared resolver to avoid importing PCA.
delphi/polismath/pca_kmeans_rep/pca.py Removes the local resolver and delegates PCA impl-flag resolution to the shared utility.
delphi/tests/test_env_flags.py Adds tests for resolver rules, shared import identity, and lightweight engine_mode import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +23
The flag is resolved AT CALL TIME (never cached at import) by the shared
`utils.env_flags.resolve_impl_flag`: unknown values fall back to the default
with a warning so a typo in a deployment env cannot crash the math worker.
This lives in a shared spot (polismath.utils) because the mode cross-cuts both
PCA (conversation._compute_pca) and clustering (conversation._compute_clusters).
Comment on lines +12 to +15
This lives in polismath.utils (not pca.py, where it originated) so that
lightweight consumers — e.g. `utils.engine_mode`, read on every conv-update
tick — do not drag in the numpy/pandas pca import chain, and resolution
warnings are logged under this module's logger rather than pca's.
# docs/CLJ-PARITY-FIXES-JOURNAL.md.

# Solver switch (read at call time — see _resolve_impl_flag):
# Solver switch (read at call time — see utils.env_flags.resolve_impl_flag):
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