How natlabrockies/fastsim works
1. What this repo is
- FASTSim-3 is a vehicle energy and powertrain simulation system centered on a Rust core, with Python bindings and a small CLI.
- The main architectural goal is to simulate a vehicle over a drive cycle and return cumulative and optionally time-resolved results, with stronger model modularity than FASTSim-2.
2. Top-level layering
- fastsim-core is the simulation engine and domain model library.
- fastsim-py and python/fastsim expose the Rust engine to Python users.
- fastsim-cli provides a command-line entry point.
- The rest of the repo is support code: validation/calibration, benchmarks, docs, and CI/release automation.
3. Core simulation boundary
- fastsim-core contains the actual physics/model logic: vehicle behavior, drive-cycle handling, road load, energy conversion, and result tracking.
- The runtime flow is: vehicle definition + drive cycle + model parameters → simulation step loop → cumulative outputs and optional saved history.
- The README’s save_interval behavior is reflected in the architecture: the engine can retain every timestep, every Nth timestep, or only the final cumulative state for speed and memory savings.
4. Vehicle model subsystem
- fastsim-core/src/vehicle is the main domain boundary for model types.
- It is organized into component-centric models such as conv (conventional), hev, bev, cabin, hvac, chassis, and powertrain.
- Powertrain internals are split further into electric_machine, fuel_converter, fuel_storage, reversible_energy_storage, and transmission, which supports the repo’s “component-specific vehicle models” design.
- vehicle_model and vehicle_utils provide higher-level assembly and compatibility logic, including FASTSim-2 interop.
5. Drive cycle and motion inputs
- fastsim-core/src/drive_cycle and resources/cycles define the motion profile inputs, with CSV cycle resources such as udds.csv and hwfet.csv.
- This subsystem includes cycle manipulation and maneuver utilities, indicating the engine can transform or augment raw cycle data before simulation.
- simdrive is the operational layer that combines vehicle + cycle + road load to produce results.
6. Results, state, and interpolation
- utils/interp.rs, tracked_state.rs, and traits suggest a reusable infrastructure for interpolation, state tracking, and polymorphic model behavior.
- simdrivelabel and longparams.json appear to define standardized output labels/parameter naming for simulation results.
- resources/interpolators holds YAML-defined interpolation tables, which is important because the repo emphasizes more accurate interpolation and flexible model interfacing.
7. Compile-time extensibility
- fastsim-core/fastsim-proc-macros is a separate proc-macro crate used to derive common behavior such as serde support, Python API helpers, cycle-related traits, and history vector handling.
- This is a meaningful architectural boundary: runtime simulation lives in fastsim-core, while repetitive interface/serialization code is generated at compile time.
8. Python integration layer
- fastsim-py is the Rust crate that builds the Python extension module.
- python/fastsim is the user-facing Python package, with typed stubs (fastsim.pyi), utilities, demos, and tests.
- The Python layer is not the simulation engine itself; it is a wrapper and convenience API around the Rust core, which is what enables the high-performance Python experience described in the README.
9. User-facing Python workflows
- python/fastsim/demos contains scenario scripts for conventional, HEV, BEV, thermal, stop-start, trace-miss, and CAVS-style workflows.
- python/fastsim/tests validates serialization, resource loading, utilities, and performance-related behavior.
- python/fastsim/utils and copy_stub_docstrings.py support packaging quality and API ergonomics, not core simulation logic.
10. CLI and executable entry points
- fastsim-cli/src/main.rs is the standalone command-line application layer.
- fastsim-core/src/bin/... includes at least one Rust binary example for running a specific simulation scenario directly from the core crate.
- These entry points sit on top of the same domain engine used by Python, so diagrammatically they are alternative front doors into the same simulation core.
11. Calibration and validation pipeline
- cal_and_val contains a substantial validation harness, including f2-to-f3 translation tests and thermal validation for BEV/HEV models.
- The f2-vehicles and f3-vehicles directories provide paired FASTSim-2 and FASTSim-3 vehicle definitions for regression/comparison.
- cal_and_val/thermal adds BEV/HEV thermal calibration/validation scripts and dyno data handling, showing that the repo includes model verification as a first-class workflow rather than a separate project.
12. Benchmarking and performance focus
- benchmarks includes Python benchmark scripts and test harnesses, which aligns with the README’s emphasis on speed and memory reduction.
- The performance axis is part of the architecture: the engine is designed to support different levels of output retention, and the benchmark suite measures those tradeoffs.
13. Data and asset model
- The repository is data-driven: vehicles, cycles, interpolators, and validation fixtures are stored as YAML/CSV/JSON resources alongside code.
- This separation matters architecturally because many simulations are parameterized by resource files rather than hardcoded model instances.
- The core crate’s resources/vehicles and src/vehicle/*.yaml show both packaged examples and regression fixtures for expected model behavior.
14. Build, docs, and release plumbing
- GitHub Actions workflows cover build/test, release, and docs deployment.
- docs is an mdBook-style documentation site, likely used as the hosted product documentation referenced in the README.
- Cargo.toml, pyproject.toml, MANIFEST.in, and lockfiles show the repo is a mixed Rust/Python package with coordinated packaging and release steps.
15. How to draw the architecture
- Put Rust core simulation in the center.
- Feed it with vehicle definitions, cycle inputs, and interpolator/resource files.
- Show two primary consumers: Python package/bindings and CLI/binary entry points.
- Surround the core with validation/calibration, benchmarks, and docs/CI, which are not runtime dependencies but are essential supporting subsystems.
Main entry points: src/lib.rs Core engine · simdrive.rs SimDrive · f2-validation.py Validation · src/lib.rs Py bindings
Components 20
Rust core
Simulation engine, domain model, and compile-time extension layer.
- Core engine · Main simulation library and domain model boundary.
fastsim-core/src/lib.rs - SimDrive · Combines vehicle, cycle, and road load to produce results.
fastsim-core/src/simdrive.rs - Vehicle model · High-level vehicle composition and FASTSim-2 compatibility layer.
fastsim-core/src/vehicle/vehicle_model.rs - Powertrain · Electric, fuel, storage, and transmission submodels.
fastsim-core/src/vehicle/powertrain/mod.rs - Drive cycle · Cycle handling, manipulation, and maneuver utilities.
fastsim-core/src/drive_cycle.rs - Road load · Road-load calculations used during the simulation step loop.
fastsim-core/src/simdrive/roadload.rs - Results state · Tracked state, interpolation, and labeled cumulative outputs.
fastsim-core/src/utils/tracked_state.rs - Interpolation · Reusable interpolation helpers and lookup behavior.
fastsim-core/src/utils/interp.rs - Shared traits · Common trait interfaces and serde-related behavior.
fastsim-core/src/traits.rs - Proc macros · Derives and helpers for serde, Python, cycle, and history behavior.
fastsim-core/fastsim-proc-macros/src/lib.rs - Resources · Packaged vehicles, cycles, and interpolation tables.
fastsim-core/resources/cycles/udds.csv
Python layer
Bindings, package API, demos, and Python-side utilities.
- Py bindings · Rust crate that builds the Python extension module.
fastsim-py/src/lib.rs - Python package · User-facing Python API and type stubs.
python/fastsim/__init__.py - Demos · Scenario scripts for vehicle and thermal workflows.
python/fastsim/demos/demo_conv.py
Supporting workflows
Validation, benchmarking, docs, and release automation.
- CLI · Standalone command-line entry point.
fastsim-cli/src/main.rs - Validation · FASTSim-2/3 regression, translation, and thermal validation.
cal_and_val/f2-validation.py - Benchmarks · Python benchmarks used to measure runtime and save-interval tradeoffs.
benchmarks/f3-save-int-none.py - Docs · Documentation site and release notes content.
docs/src/intro.md - CI / release · Workflow automation for build, test, docs, and release.
.github/workflows/build_and_test.yaml
Other components
- fastsim · Mixed Rust/Python repository for vehicle energy simulation.
Connections 27
- fastsim → Core engine: contains · Repository includes the Rust simulation core.
- fastsim → Py bindings: contains · Repository includes the Python extension crate.
- fastsim → Python package: contains · Repository includes the user-facing Python package.
- fastsim → CLI: contains · Repository includes the command-line entry point.
- fastsim → Validation: contains · Repository includes calibration and validation workflows.
- fastsim → Benchmarks: contains · Repository includes benchmark scripts.
- fastsim → Docs: contains · Repository includes documentation sources.
- fastsim → CI / release: contains · Repository includes workflow automation.
- Core engine → SimDrive: orchestrates · Core library centers the simulation loop.
- SimDrive → Vehicle model: uses · Simulation loop consumes vehicle definitions and assembly.
- SimDrive → Drive cycle: uses · Simulation loop consumes drive-cycle inputs.
- SimDrive → Road load: computes · Road-load model feeds the stepwise energy demand.
- Vehicle model → Powertrain: composes · Vehicle model is built from component-centric powertrain models.
- SimDrive → Results state: emits · Simulation produces cumulative and optional time-resolved outputs.
- Results state → Interpolation: relies on · Output/state handling uses interpolation helpers.
- Core engine → Shared traits: defines · Core library exposes shared abstractions and behavior contracts.
- Core engine → Proc macros: augmented by · Compile-time macros generate repetitive API and serialization code.
- Core engine → Resources: loads · Core simulation is parameterized by packaged resource files.
- Py bindings → Core engine: wraps · Python extension exposes the Rust core.
- Python package → Py bindings: imports · Package API sits on top of the extension module.
- Demos → Python package: uses · Demos exercise the Python API.
- CLI → Core engine: invokes · CLI is an alternate front door into the same core engine.
- Validation → Core engine: compares · Validation checks FASTSim-2/3 behavior against the core.
- Validation → Resources: uses · Validation relies on paired vehicle and thermal fixtures.
- Benchmarks → Core engine: measures · Benchmarks quantify runtime and save-interval behavior.
- Docs → Core engine: documents · Docs describe the simulation engine and workflows.
- CI / release → fastsim: automates · Workflows build, test, publish, and deploy documentation.