Skip to content

Commit

Permalink
Merge pull request #299 from JamesPHoughton/new_components
Browse files Browse the repository at this point in the history
PySD 2.0.0
  • Loading branch information
enekomartinmartinez authored Nov 8, 2021
2 parents 5885d62 + 86160d5 commit e3f445e
Show file tree
Hide file tree
Showing 49 changed files with 6,573 additions and 5,166 deletions.
18 changes: 18 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

python:
version: 3.7
install:
- method: pip
path: .
extra_requirements:
- docs
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This project is a simple library for running [System Dynamics](http://en.wikiped

**The current version needs to run at least Python 3.7. If you need support for Python 2, please use the release here: https://github.com/JamesPHoughton/pysd/releases/tag/LastPy2**

**table2py feature was dropped in version 2.0.0, please use the release here if you want to build PySD model from a tabular file: https://github.com/JamesPHoughton/pysd/releases/tag/v1.11.0**

### Resources
See the [project documentation](http://pysd.readthedocs.org/) for information about:

Expand Down
14 changes: 10 additions & 4 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ Once the regression model is fit, we write a wrapper function for its predict me
room_temp = model.components.room_temperature()
return regression.predict([room_temp, tea_temp])[0]

We can substitute this function directly for the heat_loss_to_room model component::
In order to substitute this function directly for the heat_loss_to_room model component using the :py:func:`set_component()` method::

model.components.heat_loss_to_room = new_heatflow_function
model.set_components({'heat_loss_to_room': new_heatflow_function})

If you want to replace a subscripted variable, you need to ensure that the output from the new function is the same as the previous one. You can check the current coordinates and dimensions of a component by using :py:data:`.get_coords(variable_name)` as it is explained in :doc:`basic usage <../basic_usage>`.

.. note::
Alternatively, you can also set a model component directly::

model.components.heat_loss_to_room = new_heatflow_function

However, this will only accept the python name of the model component. While for the :py:func:`set_component()` method, the original name can be also used.

Splitting Vensim views in separate Python files (modules)
---------------------------------------------------------
Expand Down Expand Up @@ -68,15 +74,15 @@ In a Vensim model with three separate views (e.g. `view_1`, `view_2` and `view_3
.. note ::
Often, modelers wish to organise views further. To that end, a common practice is to include a particular character in the View name to indicate that what comes after it is the name of the subview. For instance, we could name one view as `ENERGY.Supply` and another one as `ENERGY.Demand`.
In that particular case, setting the `subview_sep` kwarg equal to `["."]`, as in the code below, would name the translated views as `demand.py` and `supply.py` and place them inside the `ENERGY` folder::
read_vensim("many_views_model.mdl", split_views=True, subview_sep=["."])
If macros are present, they will be self-contained in files named as the macro itself. The macro inner variables will be placed inside the module that corresponds with the view in which they were defined.


Starting simulations from an end-state of another simulation
------------------------------------------------------------
The current state of a model can be saved in a pickle file using the :py:data:`.export()`method::
The current state of a model can be saved in a pickle file using the :py:data:`.export()` method::

import pysd
model1 = pysd.read_vensim("my_model.mdl")
Expand Down
10 changes: 7 additions & 3 deletions docs/basic_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Setting simulation initial conditions
-------------------------------------
Finally, we can set the initial conditions of our model in several ways. So far, we’ve been using the default value for the initial_condition keyword argument, which is ‘original’. This value runs the model from the initial conditions that were specified originally by the model file. We can alternately specify a tuple containing the start time and a dictionary of values for the system’s stocks. Here we start the model with the tea at just above freezing::

model.run(initial_condition=(0, {'Teacup Temperature':33}))
model.run(initial_condition=(0, {'Teacup Temperature': 33}))

The new value setted can be a *xarray.DataArray* as it is explained in the previous section.

Expand All @@ -172,9 +172,13 @@ There are times when we may choose to overwrite a stock with a constant value (i

Querying current values
-----------------------
We can easily access the current value of a model component by calling its associated method (using python safe names) in the components subclass. For instance, to find the temperature of the teacup, we simply call::
We can easily access the current value of a model component using curly brackets. For instance, to find the temperature of the teacup, we simply call::

model.components.teacup_temperature()
model['Teacup Temperature']

If you try to get the current values of a lookup variable the previous method will fail as lookup variables take arguments. However, it is possible to get the full series of a lookup or data object with :py:func:`.get_series_data` method::

model.get_series_data('Growth lookup')

Supported functions
-------------------
Expand Down
1 change: 0 additions & 1 deletion docs/command_line_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ will set the initial time to 2005, the final time to 2010 and the time step to 1




Modify model variables
^^^^^^^^^^^^^^^^^^^^^^
In order to modify the values of model variables they can be passed after the model file:
Expand Down
Loading

0 comments on commit e3f445e

Please sign in to comment.