Skip to content

FE-1518: Optimization constraints as shared HIR expressions - #9371

Draft
kube wants to merge 3 commits into
cf/fe-1517-scenario-creation-uses-the-ad-hoc-formfrom
cf/fe-1518-optimization-constraints
Draft

FE-1518: Optimization constraints as shared HIR expressions#9371
kube wants to merge 3 commits into
cf/fe-1517-scenario-creation-uses-the-ad-hoc-formfrom
cf/fe-1518-optimization-constraints

Conversation

@kube

@kube kube commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #9368 (FE-1517). First cut of the constraints system (FE-1518).

Two blocks in the create-optimization drawer (only there, for now):

  • Parameter constraints — boolean TypeScript expressions over the study's parameters (scenario.*, parameters.*), e.g. scenario.min_load < scenario.max_load.
  • State constraints — metric-like bodies over the simulation state returning boolean, e.g. return state.places.Queue.count <= 10;.

Mechanics:

  • lowerOptimizationConstraint (core, worker/Node only) lowers on the existing scenario-expression / metric surfaces and type-checks a boolean result (the metric surface gained an expected: "real" | "boolean" knob).
  • The manifest gains an optional constraints: { parameterSpace, stateSpace }, each item { id, name?, code, hir } — the authored source plus its serialized HIR (serializedHirFunctionSchema validates the envelope; the TypeScript grammar in hir/hir.ts stays the authority). Old manifests parse unchanged.
  • The CLI describe() passes constraints through verbatim; the protocol JSON schema and the generated pydantic models are regenerated.
  • Python: petrinaut.Constraint wraps one constraint as a plain callable — constraint(scenario={...}) → bool — plus constraint.margin(...), a signed robustness margin (comparisons → slack, && = min, || = max, ! = negate; ≥ 0 iff satisfied) ready to feed samplers that consume violations (e.g. Optuna's constraints_func takes -margin). Behind both sits a small dependency-free HIR evaluator (petrinaut/hir.py) with ECMAScript semantics (strict equality, Math.round half-up, JS division/remainder), tested against fixtures lowered by the real TypeScript frontend.
  • Deliberately not included: enforcement, pruning, Optuna changes, or sympy conversion. An interpreter beats sympy here — it covers conditionals and Math.* without Piecewise contortions, and the same walk re-run with interval arithmetic later can bound a constraint over a whole parameter box (safe-region margins); that door is documented in hir.py.

Nothing enforces constraints yet — they are recorded, displayed, and readable; a failing one only blocks drawer submission with its diagnostic.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview Aug 30, 2026 5:03am
petrinaut Ready Ready Preview Aug 30, 2026 5:03am
petrinaut-docs Ready Ready Preview Aug 30, 2026 5:03am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hashdotdesign-tokens Ignored Ignored Preview Aug 30, 2026 5:03am

Request Review

@github-actions github-actions Bot added area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team type/eng > backend Owned by the @backend team area/tests New or updated tests labels Aug 27, 2026
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 540f999 to ca852c2 Compare August 27, 2026 20:09
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from ca852c2 to 08758e2 Compare August 27, 2026 23:53
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 08758e2 to a6118e1 Compare August 28, 2026 00:20
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from a6118e1 to 5b4bf6c Compare August 28, 2026 01:35
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 5673923 to 18a3492 Compare August 28, 2026 14:00
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 18a3492 to 50abbe9 Compare August 28, 2026 15:17
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 50abbe9 to 6b95109 Compare August 28, 2026 15:18
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 6b95109 to 35291c2 Compare August 28, 2026 15:33
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from 35291c2 to ba0715b Compare August 28, 2026 16:39
@kube
kube force-pushed the cf/fe-1518-optimization-constraints branch from ba0715b to 29a3999 Compare August 28, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) area/tests New or updated tests type/eng > backend Owned by the @backend team type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant