API Reference¶
This page provides an auto-generated summary of xarray-simlab’s API. For more details and examples, refer to the relevant sections in the main part of the documentation.
Top-level functions¶
|
Create a specific setup for model runs. |
Dataset.xsimlab (xarray accessor)¶
This accessor extends xarray.Dataset
with all the methods and
properties listed below. Proper use of this accessor should be like:
>>> import xarray as xr # first import xarray
>>> import xsimlab # import xsimlab (the 'xsimlab' accessor is registered)
>>> ds = xr.Dataset() # create or load an xarray Dataset
>>> ds.xsimlab.<meth_or_prop> # access to the methods and properties listed below
Properties
Mapping from clock dimensions to |
|
Mapping from clock dimensions to lengths. |
|
Dimension used as main clock for model runs. |
|
Main clock coordinate (as a |
|
Number of simulation steps, computed from the main clock coordinate. |
|
Returns a dictionary of output variable names - in the form of |
|
Returns a dictionary of output variables grouped by clock (keys). |
Methods
|
Set or update clock coordinates. |
|
Update model input values and/or output variable names. |
|
Set or reset Dataset variables with model input default values (if any). |
|
Filter Dataset content according to Model. |
|
Run the model. |
Returns save steps for each clock as boolean values. |
Model¶
Creating a model¶
|
An immutable collection of process units that together form a computational model. |
Creating a new model from an existing one¶
Clone the Model. |
|
|
Add or replace processe(s) in this model. |
|
Drop processe(s) from this model. |
Model introspection¶
Model
implements an immutable mapping interface where keys are
process names and values are objects of Process
subclasses
(attribute-style access is also supported).
Returns all variables in the model as a list of |
|
Returns all variables in the model as a dictionary of lists of variable names grouped by process. |
|
Returns all index variables in the model as a list of |
|
Returns all index variables in the model as a dictionary of lists of variable names grouped by process. |
|
Returns all variables that require setting a value before running the model. |
|
Returns all variables that require setting a value before running the model. |
|
Returns a dictionary where keys are process names and values are lists of the names of dependent processes. |
|
|
Render the model as a graph using dot (require graphviz). |
Running a model¶
In most cases, the methods and properties listed below should not be used
directly. For running simulations, it is preferable to use the xarray extension
instead, see Dataset.xsimlab (xarray accessor). These methods might be useful though,
e.g., for using Model
objects with other interfaces.
Returns a mapping of model variables and their current value. |
|
|
Update the model’s state (only input variables) with new values. |
Returns a mapping of model variables and some of their (meta)data cached for fastpath access. |
|
|
Update the model’s cache for a given model variable. |
|
Run one stage of a simulation. |
|
Run the variable validators of all or some of the processes in the model. |
Process¶
Creating a process¶
|
A class decorator that adds everything needed to use the class as a process. |
Process introspection and variables¶
|
Concise summary of process variables and simulation stages implemented. |
|
Get detailed information about a variable. |
|
Filter the variables declared in a process. |
Variable¶
|
Create a variable. |
Singleton class to be used as a placeholder of the main clock dimension. |
|
|
Create a variable aimed at indexing data. |
|
Create a variable used to hold any arbitrary object that needs to be shared with other process classes. |
|
Create a reference to a variable that is defined in another process class. |
|
Create a reference to a variable that is defined somewhere else in a model with a unique, global name. |
|
Create a special variable which value returns an iterable of values of variables in a model that all belong to the same group. |
|
Create a special variable which value returns a mapping of variables in a model that all belong to the same group. |
|
Create a variable that is computed on demand. |
Validators¶
See also attrs’ validators. Some additional validators for common usage are
listed below. These are defined in xsimlab.validators
.
|
A validator that raises a |
|
A validator that raises a |
Model runtime monitoring¶
|
Progress bar implementation using the tqdm package. |
|
Decorator that allows to call a function or a method at one or more specific times during a simulation. |
|
Base class for advanced, stateful simulation runtime hooks. |
|
Signal controlling simulation runtime. |