ModelManager API¶
ModelManager runs as an extension to the Orca task orchestrator. ModelManager can register template-based model steps with the orchestrator, save them to disk, and automatically reload them for future sessions.
The recommended way to load ModelManager is like this:
from urbansim_templates import modelmanager
modelmanager.initialize()
Core operations¶
-
urbansim_templates.modelmanager.
get_step
(name)[source]¶ Return the class representation of a registered step, by name.
- Parameters
name (str) –
- Returns
- Return type
instance of a template class
-
urbansim_templates.modelmanager.
initialize
(path='configs')[source]¶ Load saved model steps from disk. Each file in the directory will be checked for compliance with the ModelManager YAML format and then loaded into memory.
If run multiple times, steps will be cleared from memory and re-loaded.
- Parameters
path (str) – Path to config directory, either absolute or relative to the Python working directory
-
urbansim_templates.modelmanager.
list_steps
()[source]¶ Return a list of registered steps, with name, template, and tags for each.
- Returns
- Return type
list of dicts, ordered by name
-
urbansim_templates.modelmanager.
register
(step, save_to_disk=True)[source]¶ Register a model step with ModelManager and Orca. This includes saving it to disk, optionally, so it can be automatically loaded in the future.
Registering a step will overwrite any previously loaded step with the same name. If a name has not yet been assigned, one will be generated from the template name and a timestamp.
If the model step includes an attribute ‘autorun’ that’s set to True, the step will run after being registered.
- Parameters
step (object) –
- Returns
- Return type
None
Internal functionality¶
These functions are the building blocks of ModelManager. You probably won’t need to use them directly, but they could be useful for debugging or for extending ModelManager’s functionality.
-
urbansim_templates.modelmanager.
build_step
(d)[source]¶ Build a model step object from a saved dictionary. This includes loading supplemental objects from disk.
- Parameters
d (dict) – Representation of a model step.
- Returns
- Return type
object
-
urbansim_templates.modelmanager.
get_config_dir
()[source]¶ Return the config directory, for other services that need to interoperate.
- Returns
- Return type
str
-
urbansim_templates.modelmanager.
load_supplemental_object
(step_name, name, content_type, required=True)[source]¶ Load a supplemental object from disk.
- Parameters
step_name (str) – Name of the associated model step.
name (str) – Name of the supplemental object.
content_type (str) – Currently supports ‘pickle’.
required (bool, optional) – Whether the supplemental object is required (not yet supported).
- Returns
- Return type
object
-
urbansim_templates.modelmanager.
remove_supplemental_object
(step_name, name, content_type)[source]¶ Remove a supplemental object from disk.
- Parameters
step_name (str) – Name of the associated model step.
name (str) – Name of the supplemental object.
content_type (str) – Currently supports ‘pickle’.
-
urbansim_templates.modelmanager.
save_step_to_disk
(step)[source]¶ Save a model step to disk, over-writing the previous file. The file will be named ‘model-name.yaml’ and will be saved to the initialization directory.
-
urbansim_templates.modelmanager.
save_supplemental_object
(step_name, name, content, content_type, required=True)[source]¶ Save a supplemental object to disk.
- Parameters
step_name (str) – Name of the associated model step.
name (str) – Name of the supplemental object.
content (obj) – Object to save.
content_type (str) – Currently supports ‘pickle’.
required (bool, optional) – Whether the supplemental object is required (not yet supported).