Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PySD 2.0.0 #299

Merged
merged 27 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f17411a
Include __getitem__ get_series_data
enekomartinmartinez Sep 20, 2021
59030fd
Start creating dependencies dict
enekomartinmartinez Sep 21, 2021
d73f50e
Merge branch 'multiple_view_separators' into getitem
enekomartinmartinez Sep 27, 2021
bf45c2c
Merge branch 'getitem' into dependencies_dict
enekomartinmartinez Sep 27, 2021
3076dae
Continue building deps
enekomartinmartinez Sep 28, 2021
0173438
Merge branch 'add_forecast' into getitem
enekomartinmartinez Sep 28, 2021
8a9e96f
Merge branch 'getitem' into dependencies_dict
enekomartinmartinez Sep 28, 2021
d73a91d
Create dependencies dict
enekomartinmartinez Sep 29, 2021
be26181
Break functions and other improvements
enekomartinmartinez Sep 29, 2021
87285f2
Add assign cache type function
enekomartinmartinez Sep 29, 2021
c54c650
Add dependencies json for split models
enekomartinmartinez Sep 29, 2021
50feb89
Improve xrmerge
enekomartinmartinez Sep 29, 2021
7e26ad0
Initialize stateful elements using the dependencies dict
enekomartinmartinez Sep 30, 2021
e4bffba
Update cache
enekomartinmartinez Oct 1, 2021
74b59b2
Clean and testing
enekomartinmartinez Oct 6, 2021
0bc73ec
Improve time managing
enekomartinmartinez Oct 8, 2021
0058509
Merge branch 'master' into dependencies_dict
enekomartinmartinez Oct 14, 2021
3c0ce70
Clean control_vars and solve TODOs
enekomartinmartinez Oct 18, 2021
bf1e78f
Improve make_flat_df
enekomartinmartinez Oct 18, 2021
f773033
Update documentation
enekomartinmartinez Oct 18, 2021
23fc322
Avoid double initialization of external objects
enekomartinmartinez Oct 22, 2021
d281fdd
Update components managing
enekomartinmartinez Oct 25, 2021
544abdb
Correct scientific notation parsing
enekomartinmartinez Nov 8, 2021
0af72d1
Merge branch 'pysd2.0.0-dev' into new_components
enekomartinmartinez Nov 8, 2021
ebf22d2
Update docs and tests for new components class
enekomartinmartinez Nov 8, 2021
9126289
Update sphinx vesion to make it compatible with RTD
enekomartinmartinez Nov 8, 2021
86160d5
Spell check
enekomartinmartinez Nov 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 busing 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