Model Architecture#
Table of Contents#
Main classes#
We have already mentioned the hierarchy of the four most important classes which, ffrom the point of view of function, could be expressed as: Model > Simulation > Experiment > Engine.
Modelclass expresses the model specification, most important part of which is passed throught the parametersinitial_state,state_update_blocks=state_update_blocks,params. Below is an example of an instance from the Model class:
model = Model(initial_state=initial_state,
state_update_blocks=state_update_blocks,
params=params)
Simulationis a class used for simulating aModel. It extends the classExecutableand contains nan implemetnation of the methodrun, most other elements are inherited from the classExecutable. Example of initiating the simulation:
simulation = Simulation(model=model, timesteps=100_000, runs=1)
result = simulation.run()
df = pd.DataFrame(result)
Experimentconsists of one or moreSimulationsnd is sldo an extension of the classExecutable. Example of initiating an experiment consisting of one or more ofSimulation:
experiment = Experiment([simulation_1, simulation_2, simulation_3])
result = experiment.run()
df = pd.DataFrame(result)
Engine- class that handles configuration and execution of experiments and simulations. It is a method first defined for the classExecutableand then inherited by classesSimulationandExperiment.
Additional Classes#
Configuration#
SimulationExecutionSpecification- a data class that prepares some of the elements of simulation specification that are common for most experiments, in particular the organisation into blocks, steps and substeps.SimulationExecution- extendsSimulationExecutionSpecificationand defines various properties and functions needed to execute the simulation.Executable- instances of classExecutablecontain all information about the model specification and simulation configuration and can be passed to eitherSimulation(for a single simulation) or toExperiment(for multiple simulations).Econtains a methodrunwhich is not implemented, as that implementation takes place at the level of eitherSimulationorExperiment.
Serial or Parallel Processes#
All the classes below extend the Executor and provide an implementation of the execute_runs method. Refer to Selecting single or multi-process modes.
- ExecutorSingleProcess - simulation will be executed using single (serial) process
- ExecutorMultiprocessing - simulation will be executed using multiple processes with
multiprocessinglibrary, the number of parallel processes used is set up to the number of system CPUs less one - ExecutorPathos - simulation will be executed using multiple processes; Pathos re-writes the core code in Python rather than C, for ease of maintenance at cost of performance, see: pathos.multiprocessing
- ExecutorRay - multiprocessing backend based on Ray, run locally.
- ExecutorRayRemote - multiprocessing backend based on Ray, run remotely.
Helper classes#
Dataclass- used to ascertain that something is adataclassfrom moduledataclasses,Context- mutable context passed to simulation hooks.Backend- codes which backend to use, current options: single process, multiprocessing, Pathos, Ray and Ray remote, with Pathos being the default.Executor- class that defines the template for executing runs, but itself doesn't provide any implementation for the backend run execution, see: Single or Parallel Process.
Extensions#
For cadCAD compatibility mode:#
In radcad/compat/cadCAD/engine the class Executor is used to extend the cadCAD class Executor from cadcad/engine. Jump here to read more about the cadCAD compatibility mode.
For remote cluster execution (using Ray)#
In radcad/extensions/backends the classes ExecutorRay and ExecutorRayRemote are used to extend the standard radCAD class Executor. Jump here to read more about using the remote cluster execution.
All modules, automated documentation#
radCAD model model software architecture (structural and configuration modules)
In this package:
core- data classes for simulation configuration (SimulationExecutionSpecification,SimulationExecution)engine- configuration and execution of experiments and simulations (engine)types- helper functions for input/data processingDataclass,Contextutils- various utility functions for data or variable processingwrappers- the main classes needed to specify the model and simulation specification (Model,Executable,Simulation,Experiment)