fmdtools.define
The define package provides the building blocks to develop a simulation. Simulations are defined in the sub-classes of the Simulable
class (in the block
and architecture
subpackages), as shown below:
Aside from their internal methods defining behavior, events/indicators, and results, Simulations are additionally composed of internal containers (or sub-attributes) of the class which are defined in their own class.
Submodule Links
fmdtools.define.base
Common methods and data structures are kept in base
.
Description: A module for methods used commonly in model definition constructs.
Functions contained in this module:
get_var()
:Gets the variable value of the objectset_var()
:Sets variable of the object to a given valueis_iter()
: Checks whether a data type should be interpreted as an iterable or not.t_key()
:Used to generate keys for a given (float) time that is queryable as an attribute of an object/dict
- fmdtools.define.base.eq_units(rateunit, timeunit)
Find conversion factor from rateunit (str) to timeunit (str).
Options for units are: ‘sec’, ‘min’, ‘hr’, ‘day’, ‘wk’, ‘month’, and ‘year’.
- fmdtools.define.base.get_var(obj, var)
Get the variable value of the object.
- Parameters:
var (str/list) – list specifying the attribute (or sub-attribute of the object
- Returns:
var_value – value of the variable
- Return type:
any
- fmdtools.define.base.is_iter(data)
Check whether a data type should be interpreted as an iterable or not.
Returned as a single value or tuple/array.
- fmdtools.define.base.nest_dict(dic, levels=inf, separator='.')
Nest a dictionary a certain number of levels by separator.
- Parameters:
dict (dict) – Dictionary to nest. e.g. {‘a.b’: 1.0}
levels (int, optional) – DESCRIPTION. The default is float(‘inf’).
separator (str) – Saparator to nest by. The default is “.”
- Returns:
newhist – Nested dictionary. e.g. {‘a’: {‘b’: 1.0}}
- Return type:
dict
- fmdtools.define.base.round_float(number, res=1.0, min_r=7)
Round floats to a given resolution (avoiding fp errors).
- fmdtools.define.base.set_arg_as_type(true_type, new_arg)
Set a given argument as the type true_type.
- Parameters:
true_type (class/type) – Class/type to set to
new_arg (value) – Value to set as.
- Returns:
new_arg – Value with correct type (if possible).
- Return type:
value
- fmdtools.define.base.set_var(obj, var, val)
Set variable of the object to a given value.
- Parameters:
var (list/tuple of strings) – list of nested attributes
val (attr) – attribute to set the value to
- Returns:
flowdict – dict of flows indexed by flownames
- Return type:
dict
- fmdtools.define.base.t_key(time)
Generate keys for a given (float) time in a queryable format.
e.g. endresults.t10p0, the result at time t=10.0
fmdtools.define.environment
Module for creating environments.
- class fmdtools.define.environment.Environment(name='', glob=[], p={}, s={}, r={}, c={}, ga={}, track='default')
Bases:
CommsFlow
Class for representing environments (in development).
Environments are CommsFlows in order to readily enable perception as well as sending and recieving of information. In addition to having normal flow properties, they also contain the roles:
TODO: Properly expand create_local, update, send, recieve, etc to use ga and coords.
- c: Coords
Representation of gridworld properties
- r: Rand
Representaiton of random variables/rng
- ga: GeomArch
Representaion of shapes/forms
Examples
>>> class ExampleEnvironment(Environment): ... coords_c = ExampleCoords ... arch_ga = ExGeomArch >>> env = ExampleEnvironment('env') >>> env.create_hist([1.0]) c.r.probdens: array(1) c.st: array(1) ga.points.ex_point: array(1) ga.lines.ex_line: array(1) ga.polys.ex_poly: array(1)
- arch_ga
alias of
GeomArchitecture
- copy(glob=[], p={}, s={})
Copy the Environment.
Examples
Copies should be identical but independent after copying, e.g.:
>>> e = ExampleEnvironment("env") >>> e.ga.points['ex_point'].s.occupied = True >>> e.c.st[0, 0] = 1
Given these changes, the copy should have the same states (and not default):
>>> d = e.copy() >>> d.ga.points['ex_point'].s.occupied True >>> d.c.st[0, 0] 1.0
It should also be independent, meaning changes don’t effect the original:
>>> d.c.st[0, 1] = 1.0 >>> e.c.st[0, 1] 0.0 >>> d.ga.lines['ex_line'].s.occupied = True >>> e.ga.lines['ex_line'].s.occupied False
- reset()
Reset the flow to the initial state.
- return_mutables()
Return mutable properties of the flow.
- status()
Return a dict with the current states of the flow.