Simulations¶
This is the Simulation module. The Simulation layer takes of creating output variables, writing data to disk, iterating over data and calculations at each interval in the simulation and setting any parameters required to perform the simulation. It gets all its info from the model, which in turn gets it from each layer which gets info from the layers’ sources.
Simulations Parameter¶
-
class
simkit.core.simulations.
SimParameter
(*args, **kwargs)[source]¶ See
Simulation
attributes for list of parameter arguments.
Simulations¶
-
class
simkit.core.simulations.
Simulation
(simfile=None, settings=None, **kwargs)[source]¶ A class for simulations.
- Parameters
simfile (str) – Filename of simulation configuration file.
settings – keyword name of simulation parameter to use for settings
Simulation attributes can be passed directly as keyword arguments directly to
Simulation
or in a JSON file or as class attributes in a subclass or a combination of all 3 methods.To get a list of
Simulation
attributes and defaults get theattrs
attribute.Any additional settings provided as keyword arguments will override settings from file.
Attribute defaults are given in square brackets if not specified.
-
attrs
¶ class attributes and their defaults
-
ID
¶ ID for this particular simulation, used for path & file names, defaults to hyphenation of the class name and date/time in ISO format.
-
path
¶ path where SimKit simulation files are stored, defaults to SimKit/Simulations in the $HOME directory
-
commands
¶ list of commands corresponding to methods exposed to model, defaults to [‘start’, ‘pause’]
-
data
¶ dictionary of batch data to simulate [None]
-
thresholds
¶ thresholds for dynamic calculations as a dictionary of maximum and minimum limits for each data, eg: {‘DNI’: [0, 1400]} will limit DNI between zero and the solar constant [None]
-
interval
¶ length of each interval [1-hour]
-
sim_length
¶ simulation length [1-year]
-
display_frequency
¶ frequency output is displayed, default is every interval
-
display_fields
¶ fields displayed, default is None which displays all fields
-
write_frequency
¶ frequency output is saved, default to
number_intervals
-
write_fields
¶ fields written to disk, default is None which writes all fields
-
calc_order
= None¶ order of calculations
-
check_data
(data)[source]¶ Check if data loaded for all sources in data layer.
- Parameters
data (
Data
) – data layer from model- Returns
dictionary of data sources and objects or None if not loaded
-
cmd_queue
= None¶ command queue
-
idx_iter
= None¶ index iterator
-
initialize
(calc_reg)[source]¶ Initialize the simulation. Organize calculations by dependency.
- Parameters
calc_reg (
CalcRegistry
) – Calculation registry.
-
interval_idx
= None¶ interval index, start at zero
-
property
is_data_loaded
¶ Data loaded property, read only. True if data loaded.
-
property
iscomplete
¶ Completion property, read only. True if finished.
-
property
isinitialized
¶ Initialization property, read only. True if initialized.
-
property
ispaused
¶ Pause property, read only. True if paused.
-
number_intervals
= None¶ total number of intervals simulated
-
param_file
= None¶ parameter file
-
parameters
= None¶ simulation parameters from keyword arguments
-
pause
(progress_hook=None)[source]¶ Pause the simulation. How is this different from stopping it? Maintain info sufficient to restart simulation. Sets
is_paused
to True. Will this state allow analysis? changing parameters? What can you do with a paused simulation? Should be capable of saving paused simulation for loading/resuming later, that is the main usage. EG: someone else need computer, or power goes out, so on battery backup quickly pause simulation, and save. Is save automatic? Should there be a parameter for auto save changed?
-
settings
= None¶ name of sim settings used for parameters
-
start
(model, progress_hook=None)[source]¶ Start the simulation from time zero.
- Parameters
model – Model with layers and registries containing parameters
progress_hook (function) – A function that receives either a string or a list containing the index followed by tuples of the data or outputs names and values specified by
write_fields
in the simfile.
- Type
The model registries should contain the following layer registries: *
DataRegistry
, *FormulaRegistry
, *OutputRegistry
, *CalcRegistry