Skip to content

physXAI 1.0.0 – Phase 2: expression language and modular ANN - #72

Merged
PatrickHenkel1 merged 5 commits into
refactoring_v1.0.0from
v1/phase-2-expr
Nov 6, 2026
Merged

PatrickHenkel1 merged 5 commits into
refactoring_v1.0.0from
v1/phase-2-expr

Conversation

@PatrickHenkel1

Copy link
Copy Markdown
Collaborator

Phase 2 of the physXAI 1.0.0 refactoring: one expression language for physics and trainable blocks. Stacked on #71 (base v1/phase-1-data; retarget to refactoring_v1.0.0 after #71 is merged).

Summary

  • physXAI.expr replaces constructed features and modular expressions (no global registries any more):
    from physXAI import expr as px
    v = px.Vars()                                   # v.T, v['Func(logistic)'] – no separate declarations
    model = ModularANN(px.Linear([v.mDot, v.load, v.mDot * (v.T_in - v.T), v.T]), solver='ols')
    td = PreprocessingSingleStep(output=px.Change('T')).pipeline(path, model=model)  # inputs from the model
    • Variables, parameters, arithmetic and activations, each with NumPy, Keras and CasADi backends. Names are deterministic; lag() and substitute() are available.
    • Trainable blocks Linear, MLP, MonotoneMLP (CMNN), Polynomial, RBF, Mean, Normalize, Pretrained. Blocks normalize their inputs, arithmetic works on raw physical values.
    • JSON serialization keeps shared nodes shared. The graph is embedded in the model config; the separate modular_expression_config.json is gone.
  • Derived inputs inside the model are the default: AgentLib-MPC receives a KerasANN on raw inputs only, so the MPC no longer has to compute e.g. vT.
    • solver='ols' solves a linear regression on expressions in closed form.
    • As a fallback, columns={'vT': expr} adds a data column. This is also used for PINN targets.
  • The preprocessing takes its inputs from the model. They are ordered as AgentLib-MPC expects: recursive feature and its lags last, missing intermediate lags added.
  • Ported: ConstrainedRegression (fixed: its layer name had no dense, so the CasADi export failed; a second fit duplicated the constraints) and the RNN feature_architecture.
  • Executables, AgentLib examples and tests are migrated. The old coupled unittests/modular test is replaced by independent tests.

Contract

  • Every block translates to CasADi through AgentLib-MPC (new contract test).
  • modular_linreg contract script: vT inside the model. The exported KerasANN has inputs mDot, load, T_in with T recursive; OLS recovers the simulated physics within 0.1 %.

Test plan

  • pytest: 91 passed.
  • AgentLib-MPC plugin tests pass, and run_example(testing=True) runs.
  • All executables/ run (smoke test with 1 epoch).
  • CI on Linux and Windows.

Notes

  • executables/regression_prototype.py does not use physXAI and needs matplotlib, which is not a dependency, so verify_executables would fail on it once it changes. Should it move out of executables/?

🤖 Generated with Claude Code

…es and modular expressions

- physXAI.expr: immutable expression graph (Vars namespace, Var, Const, Param,
  arithmetic, activations) with NumPy, Keras and CasADi backends, deterministic
  names, lag(), substitute() and json serialization with shared nodes
- Trainable blocks Linear, MLP, MonotoneMLP, Polynomial, RBF, Mean, Normalize,
  Pretrained; blocks normalize their inputs, arithmetic stays physical
- ModularANN on a graph with solver 'adam' or 'ols' (closed form linear
  regression on expressions), architecture embedded in the model config
- Preprocessing: inputs derived from the model (contract order), expression
  columns for derived data (e.g. PINN targets)
- ConstrainedRegression and RNN feature architectures ported; constrained
  regression layer name fixed for the CasADi export
- Removed physXAI.preprocessing.constructed and modular_expression with all
  global registries; executables, examples and tests migrated
- Contract tests: CasADi translation of every block, in-model derived input
  exported as KerasANN on raw inputs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 00:33

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

…models

- physXAI.evaluation.rollout: recursion derived from the names (Change(X) /
  X and lags), RecursiveCell (keras RNN cell around the step model) with
  recomputation of derived columns depending on the recursive feature,
  RMSE / MAE / bias per step of the horizon for every split
- Single step models evaluate the horizon automatically with
  PreprocessingSingleStep(eval_horizon='24h'); horizon plot
- physXAI.training.RecursiveTraining: training on the multi step error with
  weighted first step, modes single_then_multi / multi_step, also as fine
  tuning of OLS solutions; the saved model stays a single step model
- Fixes: in-place writes of the legacy multi step evaluation, BuildContext
  id reuse, early stopping without validation data, seeding at creation
- Example TAir_recursive.py, tests for exact rollouts, recomputed columns,
  bias, lags, absolute outputs and the recursive training

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from v1/phase-1-data to refactoring_v1.0.0 November 6, 2026 06:18
PatrickHenkel1 and others added 3 commits November 6, 2026 07:22
- pull_request also triggers on 'edited', the jobs run only if the base
  branch changed (GitHub retargets stacked PRs after a merge)
- the coverage badge is only committed for PRs into main
- executables/regression_prototype.py (experimental) is not verified

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
physXAI 1.0.0 – Phase 3: recursive multi step evaluation and training
@PatrickHenkel1
PatrickHenkel1 merged commit bd20221 into refactoring_v1.0.0 Nov 6, 2026
53 checks passed
@PatrickHenkel1
PatrickHenkel1 deleted the v1/phase-2-expr branch November 6, 2026 06:48
@PatrickHenkel1 PatrickHenkel1 mentioned this pull request Nov 8, 2026
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