Simulation framework

SimCraft

SimCraft is a simulation framework designed for scientific simulations, particularly in fields like astronomy or physics. It allows researchers and developers to create, test, and run simulations of complex systems (e.g., telescopes, detectors, or physical models) in a modular and extensible way.

Key Concepts

  1. Modular Design
  2. SimCraft separates the simulation core (the "brain" that runs the simulation) from the physical models (the "parts" that describe how things work, like telescopes or detectors).
  3. This separation means you can add, remove, or modify models without breaking the core simulation logic.
  4. Extensibility
  5. New models (e.g., a new type of telescope or detector) can be added easily without changing the existing codebase.
  6. Each model is a standalone "crate" (a Rust package), making it simple to plug in new functionality.
  7. Independence
  8. The core simulation logic doesn’t depend on specific models. This means the core can be tested and improved independently, and models can be swapped in/out as needed.

Architecture Overview

Here’s a diagram of how SimCraft is structured:

graph TD
    simulate_bin[simulate bin] --> simulate_lib[simulate lib]
    viewer[viewer] --> simulate_lib
    simulate_lib --> simcraft_core[simcraft-core]
    simcraft_core --> models_tel_simple[models/tel/simple]
    simcraft_core --> models_psf_gaussian[models/psf/gaussian]
    simcraft_core --> models_disp_axe[models/disp/axe]
    simcraft_core --> models_det_constant[models/det/constant]
    simcraft_core --> models_src_prof_point[models/src/prof/point]
    simcraft_core --> models_src_spc_flat[models/src/spc/flat]

Explanation:

  • Arrows indicate dependency direction (e.g., simulate lib depends on simcraft-core).
  • **simcraft-core** is the foundation, providing traits and interfaces.
  • Models (e.g., models/tel/simple, models/psf/gaussian) implement these traits and are plugged into the core.
  • **simulate bin** and **viewer** are the user-facing tools that rely on the simulate lib library.

Why This Matters

  • Flexibility: Researchers can focus on developing new models without worrying about the core logic.
  • Reusability: Models can be reused across different simulations.
  • Maintainability: The core is stable and well-tested, while models can evolve rapidly.

How to Use SimCraft

  1. Add a New Model:
  2. Create a new "crate" (package) for your model.
  3. Implement the required traits (e.g., PsfModel for a new PSF).
  4. Plug it into the simulation.
  5. Run a Simulation:
  6. Configure your simulation using a TOML file.
  7. Run the simulation and analyze the output.

Example Use Cases

  • Simulating how a telescope detects light from distant stars.
  • Testing new detector designs without building physical prototypes.
  • Comparing different models of how light disperses in space.

Code source and Documentation