Development¶
Environment¶
A local virtual environment is expected at .venv.
python3 -m venv --system-site-packages .venv
source .venv/bin/activate
pip install -e '.[dev]'
Test Commands¶
Because this environment may run offline, tests can be executed via unittest directly:
source .venv/bin/activate
PYTHONPATH=src python -m unittest discover -s tests -v
Coverage:
source .venv/bin/activate
PYTHONPATH=src python -m coverage run -m unittest discover -s tests
python -m coverage report -m
Coverage policy:
- Keep overall coverage at or above
95%.
If pytest is available:
source .venv/bin/activate
PYTHONPATH=src pytest
Docstring Policy¶
This repository enforces Google-style docstrings through ruff (D rules with
pydocstyle convention google) and an AST contract test.
Rules:
- Public classes, functions, and interfaces must include full Google docstrings.
- Private/technical helpers must always include a summary line.
- If a callable has parameters other than
self/cls, include anArgs:section. - If a callable returns a non-
Nonevalue, include aReturns:section. - If a callable intentionally raises domain/validation errors, include
Raises:. - Keep units explicit for physics-facing values (
m/s,m/s^2,1/m,rad,W).
Example:
def lateral_speed_limit(curvature: float, lateral_accel_limit: float, max_speed: float) -> float:
"""Compute speed limit from curvature and lateral acceleration capability.
Args:
curvature: Signed path curvature [1/m].
lateral_accel_limit: Available lateral acceleration magnitude [m/s^2].
max_speed: Global hard speed cap [m/s].
Returns:
Maximum feasible speed [m/s] under curvature and lateral limits.
"""
Parameter Layering¶
Keep parameter domains separate:
- Physical model inputs:
VehicleParametersPacejkaParameters/AxleTireParametersSingleTrackPhysics- Numerical/discretization controls:
NumericsConfigSingleTrackNumerics- Simulation runtime controls (non-physical scenario bounds):
RuntimeConfig
Avoid mixing fixed-point tolerances, iteration limits, and numerical floors into physical parameter dataclasses.
Defaulting guidance:
- Numerical controls may include stable defaults to keep quick-start simulations
robust (
NumericsConfig,SingleTrackNumerics). - Physical parameter classes should stay explicit and scenario-specific.
Vehicle Model Architecture¶
The solver contract is represented at two levels:
VehicleModel(Protocol) insrc/apexsim/simulation/model_api.pykeeps the simulation pipeline structurally open for external backends.VehicleModelBaseplusEnvelopeVehicleModelinsrc/apexsim/vehicle/_model_base.pyprovides inheritance-based code organization for built-in backends.
Built-in models (SingleTrackModel, PointMassModel) inherit the same base class
to share validation layering, friction-circle scaling, and net
drag/grade-corrected longitudinal limits.
For backend-enabled models, keep backend adapters out of the physics layer:
PointMassModelcomposes private mixins fromsrc/apexsim/vehicle/_point_mass_physics.pyandsrc/apexsim/vehicle/_point_mass_backends.py.- Physics equations stay backend-agnostic.
- Backend-specific methods (
numba,torch) stay isolated in adapter mixins. SingleTrackModelcomposessrc/apexsim/vehicle/_single_track_physics.py, which extendsPointMassPhysicalMixinto reuse the shared physical core.- Single-track backend adapters live in
src/apexsim/vehicle/_single_track_backends.pyand mirror the point-mass backend adapter structure. - Single-track-specific dynamics/supporting components live in
src/apexsim/vehicle/single_track/(for exampledynamics.py,load_transfer.py) to keep model-specific code grouped together.
Refreshing Spa Data¶
source .venv/bin/activate
python scripts/import_spa_from_tumftm.py