Skip to content

Simulation primitives: useful-flow (Phi) + sensitivity, in both languages - #5

Merged
bigboateng merged 1 commit into
mainfrom
feat/cmg-simulation
Jun 13, 2026
Merged

Simulation primitives: useful-flow (Phi) + sensitivity, in both languages#5
bigboateng merged 1 commit into
mainfrom
feat/cmg-simulation

Conversation

@bigboateng

Copy link
Copy Markdown
Contributor

The first feature on the dual-language structure (follows #4). Adds the cmg-native simulation capability the Tower simulations surfaced: score configurations by useful flow (Phi = quality / cost) and rank knobs by sensitivity (what to tune next). Configuration what-if + sensitivity is cmg's lane; flow-network min-cut/critical-path stay in intelligence-flow.

New primitives (TS + Python, parity)

  • usefulFlowScore + combineCost / combineQuality in core (beside compareRuns): Phi = Q / C, useful output per unit cost. Placed in the zero-dep core so every layer can use it. Domain influence: network flow / OR.
  • sensitivity + rankSensitivity in math (beside errorSensitivity): the central finite-difference gradient d(objective)/d(knob), ranked by magnitude. Domain influence: calculus / neural gradient / control.

Example

08-system-simulation in both languages: sweep a parameterized pipeline, score each config by Phi (quality bounded via sigmoid, cost summed from recorded trace signals), pick the best, then rank knobs by sensitivity. The cost lives on the trace, so the run is inspectable.

TS and Python output is byte-identical (verified by diff); each ships a PASS/FAIL self-check and expected-output.txt. Example output:

1. SWEEP  -  best: effort 5 (Phi 0.192). Beyond it, cost outruns quality.
2. SENSITIVITY  -  tune first: effort (gradient 0.0517); parallelism only adds cost (-0.0091).

Math in the code

Per the request, the principle is documented, not just named: docs/05-useful-flow-and-sensitivity.md frames Phi (network flow / OR) and sensitivity (calculus / gradient / control) for a math, engineering, or CS reader, and each primitive carries a full math docstring.

Discipline

Both languages at parity; CHANGELOG entry per capability (Change / Why / Domain / Languages); domain-free; no modelgraph changes (cmg is standalone); pnpm typecheck + tests green, Python smoke green. Deferred (noted): Monte-Carlo sampling, and Python parity-catchup of compareRuns / evaluators / feedback.

🤖 Generated with Claude Code

…n both languages

Adds the cmg-native simulation capability the Tower simulations surfaced: score
configurations by useful flow (Phi = quality/cost) and rank knobs by sensitivity
(what to tune next). Configuration what-if + sensitivity is cmg's lane; flow-network
min-cut stays in intelligence-flow.

- core: usefulFlowScore + combineCost/combineQuality (TS + Python), beside compareRuns.
- math: sensitivity + rankSensitivity, finite-difference gradient (TS + Python),
  beside errorSensitivity.
- example 08-system-simulation in both languages: sweep a parameterized pipeline,
  score by Phi, pick the best, rank knobs by sensitivity. TS and Python output is
  byte-identical; each has a self-check + expected-output.txt.
- docs/05-useful-flow-and-sensitivity.md: the math/principle (network flow for Phi,
  finite-difference gradient for sensitivity), framed for math / engineering / CS.
- CHANGELOG entries (Change / Why / Domain influence / Languages).

No modelgraph changes (cmg is standalone). Parity enforced. Domain-free.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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