Skip to content

Add partitioned parallel simulation (ParallelSimulation)#102

Open
adamfilli wants to merge 2 commits into
mainfrom
dev/parallel-simulation
Open

Add partitioned parallel simulation (ParallelSimulation)#102
adamfilli wants to merge 2 commits into
mainfrom
dev/parallel-simulation

Conversation

@adamfilli

Copy link
Copy Markdown
Owner

Summary

  • Introduces ParallelSimulation — a partitioned parallel execution mode where users declare independent entity groups that run as separate Simulation instances on a thread pool
  • Converts the parallel.py module into a parallel/ package, preserving the existing ParallelRunner (process-based sweeps/replicas) alongside the new thread-based partitioned simulation
  • Adds two-layer safety validation: static cross-partition reference detection at init + runtime event target guard in the simulation loop
  • Converts _active_code_debugger from a module global to contextvars.ContextVar for thread safety
  • Adds _event_validator hook to Simulation (zero overhead when unused, excluded from fast path)

New types

Type Description
SimulationPartition Declares a group of entities, sources, and probes to run together
ParallelSimulation Orchestrator that builds N Simulation instances and runs them on ThreadPoolExecutor
ParallelSimulationSummary Aggregated results with per-partition breakdown, speedup, and efficiency metrics

Test plan

  • 20 unit tests: partition construction, validation (duplicates, cross-refs via attrs/lists/dicts), entity ID set building, summary formatting
  • 12 integration tests: single/multi/unbalanced partitions, generator processes, runtime cross-partition detection, schedule API, from_groups factory
  • Full test suite passes: 2984 tests, 0 failures, 0 regressions

🤖 Generated with Claude Code

Adam and others added 2 commits February 16, 2026 22:16
…eparate threads

Introduces a partitioned parallel execution mode where users declare independent
entity groups (partitions) that run as separate Simulation instances on a thread pool.
Enables near-linear speedup for workloads with natural parallelism (fleet nodes,
regional deployments, sharded systems) on free-threaded Python 3.13t+.

Key changes:
- Convert parallel.py module to parallel/ package, moving existing ParallelRunner
  to parallel/runner.py
- New ParallelSimulation, SimulationPartition, and ParallelSimulationSummary types
- Two-layer partition validation: static attribute walking at init + runtime
  event target guard in the simulation loop
- Convert _active_code_debugger from module global to contextvars.ContextVar
  for thread safety
- Add _event_validator hook to Simulation (zero overhead when unused)
- 32 new tests (20 unit, 12 integration), all 2984 tests pass

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Describes extending ParallelSimulation with PartitionLink declarations
and windowed execution so partitions can exchange cross-partition events
while maintaining time synchronization via barrier-based coordination.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@adamfilli

Copy link
Copy Markdown
Owner Author

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.

1 participant