omnetpypy.simulation
This module contains a set of global configuration variables for the simulation, such as the engine to use, and a set of functions to make the configuration more user-friendly.
- class omnetpypy.simulation.Experiment(config_file)[source]
Bases:
object
This class is used to run a set of independent simulations using the same YAML configuration files. An instance of this class takes care of reading the configuration file, parsing it, running the simulations, and dumping the recorded metrics in the output files.
- Parameters:
- config_filestr
The path to the configuration file, absolute or relative to the working directory. The configuration file is a YAML file with a rigid structure (see
config
attribute).
Examples
>>> exp = Experiment(config_file="config.yaml") >>> exp.run_simulations()
- Attributes:
- seed_setslist of lists of int
The seed sets for each repetition. Each repetition has a seed set of length “rngs_per_rep” from the configuration file.
- configdict
The configuration dictionary, directly parsed from the YAML configuration file. The dictionary has the following keys:
- engine (
str
), optional: The simulation engine to use. Only “simpy” is supported at the moment. Defaults to “simpy”.
- engine (
- repetitions (
int
), optional: The number of independent repetitions to run. Defaults to 1.
- repetitions (
- metrics (list of
FutureMetric
), optional: The list of metrics to collect. Defaults to an empty list.
- metrics (list of
- yaml_directory (
str
), optional: The path to the directory containing the yaml files to set the simulation. Relative to the configuration file directory. Defaults to “./” .
- yaml_directory (
- simulate_until (
float
or None), optional: The time until which the simulation will run. If None, simulation runs as long as there are events. Defaults to None.
- simulate_until (
- time_unit (
str
), optional: The time unit for the simulation. Defaults to “us” (microseconds).
- time_unit (
- log_level (
int
orstr
), optional: The log level for the simulation. See
set_log_level()
. Defaults tologging.INFO
- log_level (
- output_dir (
str
or None), optional: The output directory for the simulation, relative to the configuration file directory. Defaults to None, in which case no data will be stored.
- output_dir (
- simulations_paramslist of tuples
The list of simulation parameters for each repetition. Each element of the list is a tuple with the following parameters:
- engine (
str
): The simulation engine to use.
- engine (
- seed_set (list of int):
The seed set for the repetition.
- repetition (
int
): The repetition index.
- repetition (
- metrics (list of
FutureMetric
): The list of metrics to collect.
- metrics (list of
- yaml_directory (
str
): The path to the directory containing the yaml files to set the simulation.
- yaml_directory (
- until (
float
or None): The time until which the simulation will run. If None, simulation runs as long as there are events.
- until (
- log_level (
int
orstr
): The log level for the simulation. See
set_log_level()
.
- log_level (
- time_unit (
str
): The time unit for the simulation.
- time_unit (
- output_dir (
str
or None): The output directory for the simulation.
- output_dir (
- global_params (dict):
A dictionary of global parameters. These parameters are available to all the entities in the simulation.
- output_dirstr or None
The output directory for the simulation. If None, no data is stored.
- class omnetpypy.simulation.Simulation(engine, seed_set, repetition, metrics, yaml_directory, until, log_level, time_unit, output_dir, global_params)[source]
Bases:
object
This class is used to run a single simulation using the specified configuration. It takes care of reading the running the simulation and returning the recorded metrics. Users should not instantiate this class directly, but use the
Experiment
to manage multiple simulations.All parameters are also stored as attributes.
- Parameters:
- enginestr
The simulation engine to use. Only “simpy” is implemented at the moment.
- seed_setlist of int
The seed set for the repetition.
- repetitionint
The repetition index.
- metricslist of
FutureMetric
The list of metrics to collect.
- yaml_directorystr
The path of the directory that contains all the yaml files.
- untilint or float
The time until which the simulation will run.
- log_levelstr
The log level for the simulation. See
log_to_console()
.- time_unitstr
The time unit for the simulation. See
time_unit_factor()
.- output_dirstr
The output directory for the simulation.
- global_paramsdict
A dictionary of global parameters. These parameters are available to all the entities in the simulation.
- Raises:
- NotImplementedError
If the passed
engine
is not implemented.
- Attributes:
- rng
MultiRandom
The random number generator for this simulation, already initialized. It is made available to all the entities in the simulation through the
Connector
.- connector
Connector
The connector to the simulation engine. Its subclass depends on the chosen engine.
- network
CompoundModule
The network to simulate, parsed from the YAML file “network.yaml”.
- rng
- start()[source]
start the simulation and collect the metrics.
- Returns:
- dict
A dictionary of dictionaries with the collected metrics.
- time()[source]
Return the current simulation time.
- Returns:
- int or float
The current simulation time.
- property time_unit_factor
The factor to convert the simulation time unit to seconds.
- Returns:
- int or float
The factor to convert the time unit to seconds.
See also