Coordinator
The Coordinator is the main class in CoFMPy. It controls the blocks internally in order to ease the usage of the library. For end users, this is the only interface to start with: from a JSON configuration file, the coordinator will instantiate and monitor all the required components.
from cofmpy import Coordinator
# Instantiate the Coordinator
my_coordinator = Coordinator()
# Start the Coordinator (and all its components) from a JSON configuration file
my_coordinator.start(conf_path="my_config_file.json")
The Coordinator can then run the simulation using do_step()
or run_simulation()
.
Internally, the Master component will execute the steps of the co-simulation.
n_steps = 100
for _ in range(N):
my_coordinator.do_step(step_size=0.05)
It is then possible to get the simulation results as a Pandas dataframe :
results_df = my_coordinator.get_results()
Source code in cofmpy/coordinator.py
69 70 71 72 73 74 75 76 |
|
do_step ¶
do_step(step_size: float, save_data=False)
Perform a simulation step.
PARAMETER | DESCRIPTION |
---|---|
step_size
|
simulation step size
TYPE:
|
save_data
|
whether to save the data in the default CSV data storage. Defaults to False.
TYPE:
|
Source code in cofmpy/coordinator.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
get_causality ¶
get_causality(name: tuple) -> str
Gets the causality of the given variable.
PARAMETER | DESCRIPTION |
---|---|
name
|
variable name as (fmu_id, var_name).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
causality of the variable.
TYPE:
|
Source code in cofmpy/coordinator.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
get_results ¶
get_results() -> dict
Get the results from the simulation.
RETURNS | DESCRIPTION |
---|---|
dict
|
dataframe with the results.
TYPE:
|
Source code in cofmpy/coordinator.py
131 132 133 134 135 136 137 138 139 140 |
|
get_variable ¶
get_variable(name: tuple) -> list
Get the value of the given tuple fmu/variable.
PARAMETER | DESCRIPTION |
---|---|
name
|
variable name as (fmu_id, var_name).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list
|
value of the variable, as a list.
TYPE:
|
Source code in cofmpy/coordinator.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
|
get_variable_names ¶
get_variable_names() -> list
Get the names of all variables in the system.
RETURNS | DESCRIPTION |
---|---|
list
|
list of variable names as (fmu_id, var_name) tuples.
TYPE:
|
Source code in cofmpy/coordinator.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
get_variable_type ¶
get_variable_type(name: tuple) -> str
Get the type of the given variable.
PARAMETER | DESCRIPTION |
---|---|
name
|
variable name as (fmu_id, var_name).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
type of the variable.
TYPE:
|
Source code in cofmpy/coordinator.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
get_variables ¶
get_variables(names: list) -> dict
Get the values of the given variables.
PARAMETER | DESCRIPTION |
---|---|
names
|
list of variable names as (fmu_id, var_name) to get, e.g. [("fmu1", "var3"), ("fmu2", "var1")].
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
dictionary with the variable names and their values.
TYPE:
|
Source code in cofmpy/coordinator.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
|
load_data_storages ¶
load_data_storages(data_storages_config: dict)
Load the data storages from the given dictionary of configurations.
PARAMETER | DESCRIPTION |
---|---|
data_storages_config
|
dictionary containing the configurations for the data storages.
TYPE:
|
Source code in cofmpy/coordinator.py
206 207 208 209 210 211 212 213 214 215 216 217 |
|
load_stream_handlers ¶
load_stream_handlers(stream_handlers_config: dict)
Load the stream handlers from the given dictionary of configurations.
PARAMETER | DESCRIPTION |
---|---|
stream_handlers_config
|
dictionary containing the configurations for the stream handlers.
TYPE:
|
Source code in cofmpy/coordinator.py
193 194 195 196 197 198 199 200 201 202 203 204 |
|
parse_config ¶
parse_config(config_path: str)
Start the configuration parser to parse the given configuration file.
PARAMETER | DESCRIPTION |
---|---|
config_path
|
path to the configuration file
TYPE:
|
Source code in cofmpy/coordinator.py
142 143 144 145 146 147 148 149 150 151 |
|
run_simulation ¶
run_simulation(step_size: float, end_time: float)
Run the simulation until the given end time.
PARAMETER | DESCRIPTION |
---|---|
step_size
|
simulation step size
TYPE:
|
end_time
|
simulation end time
TYPE:
|
Source code in cofmpy/coordinator.py
253 254 255 256 257 258 259 260 261 262 263 264 265 |
|
save_results ¶
save_results(filename: str)
Save the results to a CSV file.
PARAMETER | DESCRIPTION |
---|---|
filename
|
name of the CSV file to save the results to.
TYPE:
|
Source code in cofmpy/coordinator.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
start ¶
start(
conf_path: str,
fixed_point_init=False,
fixed_point_kwargs=None,
)
Start the coordinator with the given configuration file.
PARAMETER | DESCRIPTION |
---|---|
conf_path
|
path to the configuration file.
TYPE:
|
fixed_point_init
|
whether to use the fixed-point initialization method.
TYPE:
|
fixed_point_kwargs
|
keyword arguments for the fixed point initialization method if fixed_point is set to True. Defaults to None, in which case the default values are used "solver": "fsolve", "time_step": minimum_default_step_size, and "xtol": 1e-5.
TYPE:
|
Source code in cofmpy/coordinator.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
start_graph_engine ¶
start_graph_engine(config: dict)
Start the graph engine with the given configuration.
PARAMETER | DESCRIPTION |
---|---|
config
|
configuration for the graph engine containing the FMUs, connections, and edge separation.
TYPE:
|
Source code in cofmpy/coordinator.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
start_master ¶
start_master(
config: dict,
fixed_point_init=False,
fixed_point_kwargs=None,
)
Start the master algorithm with the given configuration.
PARAMETER | DESCRIPTION |
---|---|
config
|
configuration for the master algorithm containing the FMUs, connections, sequence order, and loop method.
TYPE:
|
fixed_point_init
|
whether to use the fixed-point initialization method.
TYPE:
|
fixed_point_kwargs
|
keyword arguments for the fixed point initialization method if fixed_point is set to True. Defaults to None, in which case the default values are used "solver": "fsolve", "time_step": minimum_default_step_size, and "xtol": 1e-5.
TYPE:
|
Source code in cofmpy/coordinator.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|