Running Multiple Models
Example file: docs/examples/api/parallel_runs_manual.py
One of the easiest applications of the GridLAB-D™ API is its use in running multiple models in parrallel. Prior to the implementation of the GridLAB-D™ API, this was typically achieved through manually instantiating GridLAB-D™ multiple times, each time referencing a different model.
Simple Implementation
The most straight-foward way of using GridLAB-D™ to run multiple models in paralle is to write unique models and place them in unique locations in the file hiearchy to avoid any name-space problems (e.g. one model overwriting the results of another because they both define a recorder that writes to the same file name). The example we've written provides this implementation. To achieve parallel operation, our example uses Python's "multiprocessing" library which executes each model in its own thread, allowing them to be run in parallel.
Advanced Implementation
A more advanced version of this example (not implemented) could achieve similar results using more of the functionality provided by the API. Instead of creating unique models for each scenario to be run, the API can be used to load a single base model and modify it to meet the specifications of a given scenario. This modified model can then be run in its own thread in parallel to all of the other models that have been created in the same way. (We walk through how to use the API to modify a model later in this section.)
Programmatically modifying the models before running offers the advantage of not having to use disk space to hold each version of the model that is being run; only the base model exists on disk. This is particularly helpful if the number of scenarios is very large (hundreds or thousands) where the burden of managing all those files is significant. The drawback of programmatic modificatio is that there is no file on disk as an artifact of the model that was run for a given scenario. To understand, say, what model parameters were changed for scenario six, you have to evaluate the code that does the model modification. For most people, this requires more effort than just looking at the model file directly or running a "diff" on the base and scenario-specific model.
Dependent Simulations (Workflows)
The ability to modify the model programmatically also opens the possiblity of defining a sequence of model runs where the output of the simulation with one model defines the scenario used in building the next model. This kind of sequencing is effective when trying to adjust one or more parameters to tune the output of the model (e.g. doing something like a binary search or a genetic algorithm). This effectively creates an advanced workflow which would be much more difficult to implement without the GridLAB-D™ API.