Skip to content

feat: Monte Carlo uncertainty propagation (gpu_stack.uncertainty)#8

Merged
Cuuper22 merged 1 commit into
mainfrom
claude/eager-cerf-kvmqta-n6
Jun 11, 2026
Merged

feat: Monte Carlo uncertainty propagation (gpu_stack.uncertainty)#8
Cuuper22 merged 1 commit into
mainfrom
claude/eager-cerf-kvmqta-n6

Conversation

@Cuuper22

Copy link
Copy Markdown
Owner

$(cat <<'EOF'

Summary

  • Adds gpu_stack/uncertainty.py with a public API for Monte Carlo uncertainty propagation over the existing symbolic resolver
  • Three distribution types: uniform(low, high), normal(mean, std), lognormal(mu, sigma) with sign-assumption validation against SymPy variable assumptions
  • UncertainAssignment(name, distribution) pairs a registered variable name with a distribution; validated at construction
  • propagate_uncertainty(preset_or_assignments, targets, uncertain, n_samples, seed) collects per-target samples through the existing public resolve() path
  • Fast path: SymPy lambdify over the symbolic expression (200 samples in <1 ms vs ~14 s per-sample fallback)
  • UncertaintyResult / TargetUncertaintyStats result artifacts with to_dict() and echoed input specs
  • 35 tests in tests/test_uncertainty.py covering: distribution validation, sign-assumption rejection, determinism by seed, quantile ordering, analytic correctness on a hand-checkable linear case, failure-count behavior, all three distribution types, multi-target runs, and performance sanity

Test plan

  • python -m pytest tests/test_uncertainty.py -q -- 35 passed
  • python -m pytest -q -- 705 passed (670 baseline + 35 new)
  • python -m gpu_stack.cli audit --fail-on-issues -- PASS
  • End-to-end driver: cost_per_token with 3 synthetic uncertain inputs (price peak, price offpeak, cluster availability), n_samples=200, seed=42 -- mean 3.27e-6, std 1.46e-7, p5-p95 range 3.06e-6 to 3.50e-6, 0 failures
  • Code review findings fixed: removed dead _is_finite_float helper, fixed dead if not _has_numpy: pass branch and redundant import, fixed population vs sample std (now Bessel-corrected), added duplicate variable name validation, corrected return type annotation on _try_lambdify_path

https://claude.ai/code/session_01Eu2JVnPFgMQftwYTP3cGQZ
EOF
)


Generated by Claude Code

…tainty)

Adds `gpu_stack/uncertainty.py` with UncertainAssignment, three distribution
types (uniform, normal, lognormal), and `propagate_uncertainty` that resolves
targets over n_samples draws. Uses SymPy lambdify fast-path for vectorised
evaluation (200 samples in <1 ms vs ~14 s per-sample) with fallback to
per-sample resolver. Returns structured TargetUncertaintyStats with mean,
sample std, p5/p50/p95, failure count, and echoed input specs. 35 tests cover
determinism, quantile ordering, analytic correctness, failure counting, and
all three distribution types.

https://claude.ai/code/session_01Eu2JVnPFgMQftwYTP3cGQZ
@Cuuper22 Cuuper22 merged commit be6a004 into main Jun 11, 2026
0 of 6 checks passed
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