Skip to content

IrregSpacedGrid: extra_param_names for user-side runtime scalars#351

Open
hmgaudecker wants to merge 1 commit intofeat/categorical-scalarintfrom
feat/runtime-grid-extra-params
Open

IrregSpacedGrid: extra_param_names for user-side runtime scalars#351
hmgaudecker wants to merge 1 commit intofeat/categorical-scalarintfrom
feat/runtime-grid-extra-params

Conversation

@hmgaudecker
Copy link
Copy Markdown
Member

Summary

  • Adds IrregSpacedGrid(extra_param_names=("foo", "bar")) so scalar params consumed by user-side code that builds the runtime points (e.g., an upper bound that changes per optimizer iteration) can flow through fixed_params / per-call params without tripping broadcast_to_template's unknown-keys check.
  • Each name surfaces as a ScalarFloat slot in the grid's pseudo-function template entry alongside points. Pylcm itself never reads these values — they're carried through so user-side injection code can pick them up via model.fixed_params[name] (or the resolved internal params) before computing the points.
  • Rejected on fixed-points grids — a baked-in grid has no user-side runtime computation to feed.

Closes #348. Stacks on #350 (uses the feat/categorical-scalarint branch as base).

Test plan

  • pixi run -e tests-cpu tests — 961 passed (4 new tests in test_runtime_params.py).
  • pixi run -e type-checking ty — clean.
  • prek run --all-files — clean.
  • Downstream cascade verified in aca-model (216 + workspace 407 green; aca-model PR cascading off PR [pre-commit.ci] pre-commit autoupdate #10 follows).

🤖 Generated with Claude Code

`broadcast_to_template` rejects any `fixed_params` key that no DAG
function lists in its signature. That assumption breaks for
runtime-supplied grids whose points are computed by user-side code
from per-iteration scalars (e.g., a grid upper bound) — pylcm itself
never reads those scalars, but they still need to flow through the
params machinery instead of being funneled through
`simulate(params=...)` where they compete with estimation parameters.

This adds an `extra_param_names: tuple[str, ...]` keyword to
`IrregSpacedGrid`. When `pass_points_at_runtime=True`, each name in
the tuple surfaces as a `ScalarFloat` slot in the action/state's
pseudo-function template entry alongside `points`. The user's
injection code reads the resolved values from `model.fixed_params`
(or per-iteration params) before computing the points; pylcm just
threads them through `broadcast_to_template` unchanged.

Rejected on fixed-points grids — a baked-in grid has no user-side
runtime computation to feed.

Closes #348.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@read-the-docs-community
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Benchmark comparison (main → HEAD)

Comparing 99a5e31d (main) → e639f185 (HEAD)

Benchmark Statistic before after Ratio Alert
aca-baseline execution time 27.474 s 27.578 s 1.00
peak GPU mem 509 MB 854 MB 1.68
compilation time 299.51 s 296.71 s 0.99
peak CPU mem 7.65 GB 12.02 GB 1.57
Mahler-Yum execution time 4.712 s 4.752 s 1.01
peak GPU mem 529 MB 529 MB 1.00
compilation time 14.59 s 14.11 s 0.97
peak CPU mem 1.68 GB 1.68 GB 1.00
Precautionary Savings - Solve execution time 50.8 ms 54.5 ms 1.07
peak GPU mem 101 MB 101 MB 1.00
compilation time 2.71 s 2.85 s 1.05
peak CPU mem 1.13 GB 1.13 GB 1.00
Precautionary Savings - Simulate execution time 126.7 ms 127.5 ms 1.01
peak GPU mem 344 MB 344 MB 1.00
compilation time 4.90 s 5.06 s 1.03
peak CPU mem 1.31 GB 1.31 GB 1.00
Precautionary Savings - Solve & Simulate execution time 145.2 ms 142.3 ms 0.98
peak GPU mem 578 MB 578 MB 1.00
compilation time 7.02 s 7.32 s 1.04
peak CPU mem 1.28 GB 1.29 GB 1.01
Precautionary Savings - Solve & Simulate (irreg) execution time 283.3 ms 280.8 ms 0.99
peak GPU mem 2.19 GB 2.19 GB 1.00
compilation time 7.58 s 7.39 s 0.97
peak CPU mem 1.34 GB 1.34 GB 1.01

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.

1 participant