Version: v1.2.3 | Status: Active | Last Updated: March 2026
The simulation module provides the core simulation engine for Codomyrmex. It enables step-based simulation execution with configurable parameters, supporting agent-based modeling and system dynamics use cases. The module manages simulation lifecycle (initialization, stepping, completion) and result collection.
- Decoupled Engine: The
Simulatorclass is independent of specific simulation models; logic is injected via subclassing or theparamsdictionary. - Configurable:
SimulationConfigdataclass separates configuration from execution.
- Structured Logging: All simulation events (init, start, step errors, completion) are logged via
logging_monitoring. - Consistent Results:
get_results()returns a standardized dictionary format regardless of simulation type.
- Minimal Interface: Three public methods (
run(),step(),get_results()) and one configuration class. - Sensible Defaults: Works out of the box with
Simulator()and no configuration.
- Step Loop:
run()executesstep()in a loop untilmax_stepsor early termination. - Reproducibility: Optional
seedparameter for deterministic simulation runs. - Error Recovery: Exceptions during
step()are logged with step context and re-raised;_runningstate is always cleaned up viafinally.
graph TD
subgraph sg_b332c3492d [Configuration]
Config[SimulationConfig]
end
subgraph sg_15b51ea489 [Core Engine]
Sim[Simulator]
Run[run()]
Step[step()]
Results[get_results()]
end
subgraph sg_ce0cff719a [Infrastructure]
Logger[logging_monitoring]
end
Config --> Sim
Sim --> Run
Run --> Step
Run --> Results
Sim --> Logger
- Simulation Execution: Run simulations to completion via
run()or incrementally viastep(). - Configuration: Accept simulation parameters through
SimulationConfig(name, max_steps, seed, params). - Result Collection: Return structured results including steps completed, configuration name, and status.
- Lifecycle Management: Track running state and step count; clean up on completion or failure.
- Type hints on all public methods and configuration fields
- Structured logging for all lifecycle events
- Exception safety with proper state cleanup
Simulator(config: SimulationConfig | None = None)- Initialize the simulator engine.Simulator.run() -> dict[str, Any]- Execute the full simulation loop.Simulator.step() -> None- Execute a single simulation step.Simulator.get_results() -> dict[str, Any]- Return current simulation results.SimulationConfig(name, max_steps, seed, params)- Configuration dataclass.
- Internal:
codomyrmex.logging_monitoring(structured logging viaget_logger).
- Create a
SimulationConfigwith desired parameters - Instantiate
Simulatorwith the config - Call
run()for full execution orstep()for incremental control - Retrieve results via
get_results()or the return value ofrun()
- Subclass
Simulatorand overridestep()to implement custom simulation logic - Use
paramsdictionary inSimulationConfigfor model-specific parameters
- Human Documentation: README.md
- Technical Documentation: AGENTS.md
- Package Root: ../README.md
- Package SPEC: ../SPEC.md