simple_montecarlo

Architecture & Design

Class Hierarchy

MONTE_CARLO_EXPERIMENT
  └─ uses → TRIAL_OUTCOME (N copies, one per trial)
       └─ contains → MEASUREMENT (multiple per outcome)
  
MONTE_CARLO_EXPERIMENT
  └─ produces → SIMULATION_STATISTICS (aggregated)

Data Flow

User defines trial logic agent
         ↓
MONTE_CARLO_EXPERIMENT runs N trials
         ↓
Each trial invokes user's logic agent
         ↓
Agent returns TRIAL_OUTCOME with MEASUREMENTS
         ↓
Experiment collects all outcomes
         ↓
Extract all measurements from all outcomes
         ↓
Compute statistics (mean, std_dev, CIs)
         ↓
Return SIMULATION_STATISTICS to user

Design Decisions

Type-Safe Measurements

MEASUREMENT distinguishes observed values from probabilities, preventing category errors in scientific code.

Semantic API

Uses business domain terminology (Experiment, Trial, Outcome) rather than mathematical terminology, making the library accessible to engineers.

Agent-Based Trial Logic

Flexible approach lets users define trial behavior inline without inheritance or complex factory patterns.

Sequential (for now)

Current phase uses sequential trial execution. SCOOP-based parallelization planned for v2.0.

Performance