# milanfusco/mcframework architecture

> Architecture diagram of the GitHub repository milanfusco/mcframework, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/milanfusco/mcframework
- Repository: https://github.com/milanfusco/mcframework

## Overview

mcframework is a Python Monte Carlo simulation library. Its principal workflow is to define or register a simulation, run it with a selected execution strategy, and receive structured results with statistical summaries. The graph also preserves the built-in simulation domains, convergence validation, benchmarking, and profiling capabilities. Several backend and analytics internals are represented at their module paths; unsampled implementation details are not inferred.

Main entry points: [`src/mcframework/simulation.py`](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/simulation.py) (Simulation Runner), [`src/mcframework/backends/torch.py`](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch.py) (Torch Backend Selector), [`src/mcframework/core.py`](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/core.py) (Simulation Registry), [`src/mcframework/backends/torch_base.py`](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_base.py) (Torch Shared Utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Simulation API"]
  node_framework["Simulation Registry<br/>[core.py]"]
  node_simulation["Simulation Runner<br/>[simulation.py]"]
  node_result["Simulation Result<br/>[core.py]"]
end

subgraph group_domains["Simulation Domains"]
  node_pi["Pi Estimation<br/>[pi.py]"]
  node_blackscholes["Black-Scholes Options<br/>[black_scholes.py]"]
  node_portfolio["Portfolio Simulation<br/>[portfolio.py]"]
end

subgraph group_execution["Execution Backends"]
  node_backend_api["Backend Protocol<br/>[base.py]"]
  node_sequential["Sequential Backend<br/>[sequential.py]"]
  node_parallel["Thread and Process<br/>[parallel.py]"]
  node_torch_factory["Torch Backend Selector<br/>[torch.py]"]
  node_torch_base["Torch Shared Utilities<br/>[torch_base.py]"]
  node_torch_cpu["Torch CPU<br/>[torch_cpu.py]"]
  node_torch_cuda["Torch CUDA<br/>[torch_cuda.py]"]
  node_torch_mps["Torch MPS<br/>[torch_mps.py]"]
end

subgraph group_analysis["Analytics and Tools"]
  node_stats["Statistics Engine<br/>[stats_engine.py]"]
  node_utils["Critical Values<br/>[utils.py]"]
  node_validation["Convergence Validation<br/>[validation.py]"]
  node_benchmark["Backend Benchmarking<br/>[benchmark.py]"]
  node_profiling["Torch Profiling<br/>[profiling.py]"]
end

node_user(("Python User"))

node_user -->|"registers"| node_framework
node_user -->|"runs"| node_simulation
node_framework -->|"runs simulation"| node_simulation
node_framework -->|"stores results"| node_result
node_simulation -->|"returns"| node_result
node_simulation -->|"dispatches"| node_sequential
node_simulation -->|"dispatches"| node_parallel
node_simulation -->|"dispatches"| node_torch_factory
node_sequential -->|"implements"| node_backend_api
node_parallel -->|"implements"| node_backend_api
node_torch_factory -->|"selects device"| node_torch_cpu
node_torch_factory -->|"selects device"| node_torch_cuda
node_torch_factory -->|"selects device"| node_torch_mps
node_torch_cpu -->|"uses utilities"| node_torch_base
node_torch_cuda -->|"uses utilities"| node_torch_base
node_torch_mps -->|"uses utilities"| node_torch_base
node_simulation -->|"computes metrics"| node_stats
node_stats -->|"uses critical values"| node_utils
node_simulation -->|"validates convergence"| node_validation
node_user -->|"requests validation"| node_validation
node_user -->|"requests benchmarks"| node_benchmark
node_benchmark -.->|"runs workloads"| node_simulation
node_user -->|"profiles execution"| node_profiling
node_profiling -->|"wraps backend"| node_torch_factory
node_simulation -->|"runs simulation"| node_pi
node_simulation -->|"runs simulation"| node_blackscholes
node_simulation -->|"runs simulation"| node_portfolio

click node_framework "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/core.py"
click node_simulation "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/simulation.py"
click node_result "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/core.py"
click node_pi "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/pi.py"
click node_blackscholes "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/black_scholes.py"
click node_portfolio "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/portfolio.py"
click node_backend_api "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/base.py"
click node_sequential "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/sequential.py"
click node_parallel "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/parallel.py"
click node_torch_factory "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch.py"
click node_torch_base "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_base.py"
click node_torch_cpu "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_cpu.py"
click node_torch_cuda "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_cuda.py"
click node_torch_mps "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_mps.py"
click node_stats "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/stats_engine.py"
click node_utils "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/utils.py"
click node_validation "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/validation.py"
click node_benchmark "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/benchmark.py"
click node_profiling "https://github.com/milanfusco/mcframework/blob/main/src/mcframework/profiling.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_framework,node_simulation,node_result,node_user toneBlue
class node_pi,node_blackscholes,node_portfolio toneAmber
class node_backend_api,node_sequential,node_parallel,node_torch_factory,node_torch_base,node_torch_cpu,node_torch_cuda,node_torch_mps toneMint
class node_stats,node_utils,node_validation,node_benchmark,node_profiling toneRose
```

## Components

### Simulation API

- [Simulation Registry](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/core.py): `src/mcframework/core.py`
- [Simulation Runner](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/simulation.py): `src/mcframework/simulation.py`
- [Simulation Result](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/core.py): `src/mcframework/core.py`

### Simulation Domains

- [Pi Estimation](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/pi.py): `src/mcframework/sims/pi.py`
- [Black-Scholes Options](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/black_scholes.py): `src/mcframework/sims/black_scholes.py`
- [Portfolio Simulation](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/sims/portfolio.py): `src/mcframework/sims/portfolio.py`

### Execution Backends

- [Backend Protocol](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/base.py): `src/mcframework/backends/base.py`
- [Sequential Backend](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/sequential.py): `src/mcframework/backends/sequential.py`
- [Thread and Process](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/parallel.py): `src/mcframework/backends/parallel.py`
- [Torch Backend Selector](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch.py): `src/mcframework/backends/torch.py`
- [Torch Shared Utilities](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_base.py): `src/mcframework/backends/torch_base.py`
- [Torch CPU](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_cpu.py): `src/mcframework/backends/torch_cpu.py`
- [Torch CUDA](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_cuda.py): `src/mcframework/backends/torch_cuda.py`
- [Torch MPS](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/backends/torch_mps.py): `src/mcframework/backends/torch_mps.py`

### Analytics and Tools

- [Statistics Engine](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/stats_engine.py): `src/mcframework/stats_engine.py`
- [Critical Values](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/utils.py): `src/mcframework/utils.py`
- [Convergence Validation](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/validation.py): `src/mcframework/validation.py`
- [Backend Benchmarking](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/benchmark.py): `src/mcframework/benchmark.py`
- [Torch Profiling](https://github.com/milanfusco/mcframework/blob/main/src/mcframework/profiling.py): `src/mcframework/profiling.py`

### Other components

- **Python User**

## Connections

- Python User → Simulation Registry: registers (evidence: `README.md`)
- Python User → Simulation Runner: runs (evidence: `README.md`)
- Simulation Registry → Simulation Runner: runs simulation (evidence: `src/mcframework/core.py`)
- Simulation Registry → Simulation Result: stores results (evidence: `src/mcframework/core.py`)
- Simulation Runner → Simulation Result: returns (evidence: `README.md`)
- Simulation Runner → Sequential Backend: dispatches (evidence: `src/mcframework/simulation.py`)
- Simulation Runner → Thread and Process: dispatches (evidence: `src/mcframework/simulation.py`)
- Simulation Runner → Torch Backend Selector: dispatches (evidence: `src/mcframework/simulation.py`)
- Sequential Backend → Backend Protocol: implements (evidence: `src/mcframework/backends/__init__.py`)
- Thread and Process → Backend Protocol: implements (evidence: `src/mcframework/backends/__init__.py`)
- Torch Backend Selector → Torch CPU: selects device (evidence: `src/mcframework/backends/torch.py`)
- Torch Backend Selector → Torch CUDA: selects device (evidence: `src/mcframework/backends/torch.py`)
- Torch Backend Selector → Torch MPS: selects device (evidence: `src/mcframework/backends/torch.py`)
- Torch CPU → Torch Shared Utilities: uses utilities (evidence: `src/mcframework/backends/torch_cpu.py`)
- Torch CUDA → Torch Shared Utilities: uses utilities (evidence: `src/mcframework/backends/torch_cuda.py`)
- Torch MPS → Torch Shared Utilities: uses utilities (evidence: `src/mcframework/backends/torch_mps.py`)
- Simulation Runner → Statistics Engine: computes metrics (evidence: `src/mcframework/simulation.py`)
- Statistics Engine → Critical Values: uses critical values (evidence: `src/mcframework/stats_engine.py`)
- Simulation Runner → Convergence Validation: validates convergence (evidence: `src/mcframework/validation.py`)
- Python User → Convergence Validation: requests validation (evidence: `README.md`)
- Python User → Backend Benchmarking: requests benchmarks (evidence: `README.md`)
- Backend Benchmarking → Simulation Runner: runs workloads
- Python User → Torch Profiling: profiles execution (evidence: `README.md`)
- Torch Profiling → Torch Backend Selector: wraps backend (evidence: `src/mcframework/profiling.py`)
- Simulation Runner → Pi Estimation: runs simulation (evidence: `README.md`)
- Simulation Runner → Black-Scholes Options: runs simulation (evidence: `README.md`)
- Simulation Runner → Portfolio Simulation: runs simulation (evidence: `README.md`)
