Implementing Simulators with PyPhysim

Several simulators are already implemented in the “apps” package, and can be used as examples of how to implement simulators with the PyPhysim library. The best complete example is probably the “apps/simulate_psk.py” file.

In general, the simulations module provides a basic framework for implementing Monte Carlo Simulations and implementing a new simulator with PyPhysim starts by subclassing SimulationRunner and implementing the SimulationRunner._run_simulation() method with the code to simulate a single iteration for that specific simulator.

A few other classes in the simulations module complete the framework by handling simulation parameters and simulation results. The classes in the framwork consist of

For a description of how to implement Monte Carlo simulations using the clases defined in the simulations module see Implementing Monte Carlo simulations.

Getting simulation Parameters from a file

Python has the ConfigParser library (renamed to configparser in Python 3) to parse configuration parameters. You can use it in the __init__ method of your simulator class (the simulatro main class that inherits from SimulationRunner) to read the simulation parameters from a file.

Another good alternative is using the configobj library, which provides an arguable easier to use API then configparser. Another advantage of using configobj is its ability to validate the configuration file.