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

Processes classes and variable attributes as attr extension, stores, and way too much!! #33

Merged
merged 97 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9519b92
implement variable and process using attr
benbovy Mar 6, 2018
2598f0c
add docstrings for variable factory functions + rename derived
benbovy Mar 7, 2018
fc4ff6d
add checkers for variable arguments
benbovy Mar 8, 2018
775ed3c
no fastpath access (store) for on-demand and read-only variables
benbovy Mar 8, 2018
5456420
avoid error when attr.ib are added to process class
benbovy Mar 8, 2018
4f5dae3
add process docstrings
benbovy Mar 8, 2018
418b35a
allow intent to in, out or inout and maybe set read-only properties
benbovy Mar 8, 2018
705babb
better variable properties + rename AttrType to VarType
benbovy Mar 9, 2018
b28b58f
rename get_variables to filter_variables + add func argument
benbovy Mar 9, 2018
7643840
minor tweaks
benbovy Mar 9, 2018
34c13ed
start writing what's new entries
benbovy Mar 9, 2018
1b361c2
detect cycles when looking for target variable (maybe remove later)
benbovy Mar 11, 2018
b668248
perform more sanity checks when creating variable properties
benbovy Mar 11, 2018
92bae94
rename __xsimlab_keys__ to __xsimlab_store_keys__ + fix group keys
benbovy Mar 11, 2018
35801e5
docstrings tweaks
benbovy Mar 11, 2018
1dc85a9
change default intent from 'inout' to 'in' for variable and foreign
benbovy Mar 11, 2018
df7bae9
WIP refactor Model (add _ModelBuilder class)
benbovy Mar 11, 2018
72653e8
fix handling of on-demand variables in get_input_variables
benbovy Mar 11, 2018
421cb4e
use Enum for variable intent
benbovy Mar 11, 2018
3fd166f
WIP model builder (process dependencies and sorting)
benbovy Mar 11, 2018
fbd606e
change intent rules for foreign variables
benbovy Mar 12, 2018
335b6a0
complete ModelBuilder implementation
benbovy Mar 12, 2018
e461452
fix variable group
benbovy Mar 29, 2018
f15ef9b
update Model input variables API
benbovy Mar 29, 2018
55ce033
some docstring tweaks
benbovy Mar 29, 2018
4b554f3
fix process deps when a variable involves more than 2 processes
benbovy Mar 29, 2018
5840463
identify which processes have to be executed at each simulation stage
benbovy Mar 29, 2018
f9521cb
update whats new with some enhancements
benbovy Mar 29, 2018
4e69823
add sanity checks for arg passed to Model constructor
benbovy Mar 30, 2018
acb70c3
temp solution before attr 1.8 (attr.fields_dict)
benbovy Mar 30, 2018
c5a3933
update Model repr (and move code to formatting module)
benbovy Mar 30, 2018
1de6f62
(wip) update process repr
benbovy Mar 30, 2018
1e06da3
(wip) add process_info and variable_info helper functions
benbovy Mar 30, 2018
bab4e39
bind model instance to processes + simplify on-demand keys
benbovy Mar 30, 2018
c278aa6
better error msg when a dependent process is missing in model
benbovy Mar 30, 2018
8289351
update process repr and variable inline summary
benbovy Apr 5, 2018
df732e4
update whats new
benbovy Apr 5, 2018
26aca42
remove Model.is_input
benbovy Apr 5, 2018
8bddcad
show variable details
benbovy Apr 5, 2018
fe01432
add description to foreign and group variables
benbovy Apr 5, 2018
5f66f34
add docstrings for variable-related properties in process classes
benbovy Apr 5, 2018
05c5b63
update what's new
benbovy Apr 5, 2018
baeebe6
add Model.dependent_processes property
benbovy Apr 5, 2018
1004162
update model visualization (dot)
benbovy Apr 5, 2018
96c067c
rename snapshot_vars to output_vars
benbovy Apr 5, 2018
539bc99
update what's new
benbovy Apr 5, 2018
ed91005
rename self._obj to self._ds
benbovy Apr 5, 2018
5fa752f
create a graph builder class
benbovy Apr 6, 2018
ca24948
remove combomethod decorator (not used anymore)
benbovy Apr 6, 2018
5c08211
(wip) refactor dataset/model interface as simulation drivers
benbovy Apr 6, 2018
de2366c
rename xr_interface module to drivers (simulation drivers)
benbovy Apr 6, 2018
0ea32a5
(wip) create a 'stores' module and add InMemoryOutputStore
benbovy Apr 6, 2018
40337cc
fully implement xarray simulation driver and in-memory output store
benbovy Apr 16, 2018
6de2a82
add Model.all_vars and Model.all_vars_dict properties
benbovy Apr 16, 2018
f8ce648
misc fixes
benbovy Apr 16, 2018
81ca36a
update xarray SimlabAccessor
benbovy Apr 16, 2018
9c200a8
use InMemoryOutputStore
benbovy Apr 16, 2018
c89a6b4
ensure invalid dims are ordered by ndim in error msg
benbovy Apr 18, 2018
037d3bc
improve some error messages
benbovy Apr 18, 2018
944b5ec
intent=inout not supported by foreign (ambiguous process ordering)
benbovy Apr 18, 2018
341f273
ignore attr.Attribute objects that are not xsimlab-specific
benbovy Apr 18, 2018
68acd37
(wip) update tests
benbovy Apr 18, 2018
f0213b9
add attrs as dependency
benbovy Apr 20, 2018
b8efce5
fix read-only process class properties
benbovy Apr 20, 2018
5f0b41a
(wip) update tests
benbovy Apr 20, 2018
57608b0
fix property for group variables including on-demand targets
benbovy Apr 23, 2018
be1ba82
don't need to check if foreign targeting on-demand have intent='in'
benbovy Apr 23, 2018
c8fb545
wip update tests
benbovy Apr 23, 2018
036d177
wip update tests
benbovy Apr 23, 2018
5c8a743
fix group variable targeting on_demand variables
benbovy Apr 23, 2018
1425d4f
fix process dependencies
benbovy Apr 23, 2018
d9dfac2
wip update tests
benbovy Apr 23, 2018
99bd625
clean up
benbovy Apr 23, 2018
ea8084c
wip update tests (moved fixtures in separate modules)
benbovy Apr 24, 2018
4542e4c
update tests for dot module
benbovy Apr 24, 2018
4d2ec9e
update what's new
benbovy Apr 24, 2018
ca8f1da
fix BaseSimulationDriver and test variable
benbovy Apr 30, 2018
ab5202b
wip update tests
benbovy May 2, 2018
0c8ea35
update tests
benbovy May 3, 2018
cf93f49
fix tests and increase coverage
benbovy May 3, 2018
b7488ab
fix tests for python < 3.6 (dict order)
benbovy May 3, 2018
ef92931
drop py34 support and require xarray >= 0.10.0
benbovy May 3, 2018
a9267db
update travis conf (add xarray and attrs dev to test matrix)
benbovy May 3, 2018
f83d2d0
fix travis conf
benbovy May 3, 2018
3886cbd
fix travis take 2 (fix conda env name in dev tests)
benbovy May 3, 2018
536f083
update doc (framework and api)
benbovy May 4, 2018
2c5ca50
add line return at the end of all repr
benbovy May 6, 2018
cb5e2d6
fix xarray simulation driver (avoid xarray objects for time steps)
benbovy May 6, 2018
7143027
wip update doc (update all user guide sections)
benbovy May 6, 2018
8a6ae4e
doc add some content
benbovy May 6, 2018
c454c87
try build docs in test matrix (travis)
benbovy May 6, 2018
86aa886
doc build in travis: build docs instead of running tests
benbovy May 6, 2018
b54b316
try fix doc build in travis 2
benbovy May 6, 2018
1510d4f
disable push build on PRs (push build only on master)
benbovy May 7, 2018
366fc36
simplify doc conf (rtd theme)
benbovy May 7, 2018
f70da01
require attrs >= 18.1.0 (use fields_dict internally)
benbovy May 7, 2018
6f0f8be
doc update examples
benbovy May 7, 2018
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
36 changes: 30 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ language: python
sudo: false # use container based build
notifications:
email: false
branches:
only:
- master

matrix:
fast_finish: True
include:
- python: 3.4
env: CONDA_ENV=py34
- python: 3.5
env: CONDA_ENV=py35
- python: 3.6
env: CONDA_ENV=py36
- python: 3.6
env: CONDA_ENV=py36-xarray-dev
- python: 3.6
env: CONDA_ENV=py36-attrs-dev
- python: 3.5
env: CONDA_ENV=docs
allow_failures:
- python: 3.6
env: CONDA_ENV=py36-xarray-dev
- python: 3.6
env: CONDA_ENV=py36-attrs-dev

before_install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
Expand All @@ -29,12 +41,24 @@ before_install:
- conda info -a

install:
- conda env create --file ci/requirements-$CONDA_ENV.yml
- source activate test_env_$CONDA_ENV
- python setup.py install
- if [[ "$CONDA_ENV" == "docs" ]]; then
conda env create -n test_env --file doc/environment.yml;
else
conda env create -n test_env --file ci/requirements-$CONDA_ENV.yml;
fi
- source activate test_env
- conda list
- pip install --no-deps -e .

script:
- py.test xsimlab --cov=xsimlab --cov-report term-missing
- python -OO -c "import xsimlab"
- if [[ "$CONDA_ENV" == "docs" ]]; then
conda install -c conda-forge sphinx_rtd_theme;
cd doc;
sphinx-build -n -j auto -b html -d _build/doctrees . _build/html;
else
py.test xsimlab --cov=xsimlab --cov-report term-missing --verbose;
fi

after_success:
- coveralls
1 change: 1 addition & 0 deletions ci/requirements-py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: test_env_py35
channels:
- conda-forge
dependencies:
- attrs>=18.1.0
- python=3.5
- pytest
- numpy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: test_env_py34
name: test_env_py36-attrs-dev
channels:
- conda-forge
dependencies:
- python=3.4
- python=3.6
- pytest
- numpy
- xarray
- pip:
- git+https://github.com/python-attrs/attrs.git
- coveralls
- pytest-cov
12 changes: 12 additions & 0 deletions ci/requirements-py36-xarray-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: test_env_py36-xarray-dev
channels:
- conda-forge
dependencies:
- attrs>=18.1.0
- python=3.6
- pytest
- numpy
- pip:
- git+https://github.com/pydata/xarray.git
- coveralls
- pytest-cov
1 change: 1 addition & 0 deletions ci/requirements-py36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: test_env_py36
channels:
- conda-forge
dependencies:
- attrs>=18.1.0
- python=3.6
- pytest
- numpy
Expand Down
128 changes: 18 additions & 110 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ properties listed below. Proper use of this accessor should be like:

Dataset.xsimlab.clock_coords
Dataset.xsimlab.master_clock_dim
Dataset.xsimlab.snapshot_vars
Dataset.xsimlab.output_vars

**Methods**

Expand Down Expand Up @@ -79,14 +79,17 @@ 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).
process names and values are objects of ``Process`` subclasses
(attribute-style access is also supported).

.. autosummary::
:toctree: _api_generated/

Model.all_vars
Model.all_vars_dict
Model.input_vars
Model.is_input
Model.input_vars_dict
Model.dependent_processes
Model.visualize

Running a model
Expand All @@ -109,126 +112,31 @@ interfaces.
Process
=======

Note: ``Process`` is a base class that should be subclassed.
Creating a process
------------------

.. autosummary::
:toctree: _api_generated/

Process
process

Clone a process
---------------

.. autosummary::
:toctree: _api_generated/

Process.clone

Process interface and introspection
Process introspection and variables
-----------------------------------

``Process`` implements an immutable mapping interface where keys are
variable names and values are Variable objects (attribute-style
access is also supported).

.. autosummary::
:toctree: _api_generated/

Process.variables
Process.meta
Process.name
Process.info

Process "abstract" methods
--------------------------

Subclasses of ``Process`` usually implement at least some of the methods below.

.. autosummary::
:toctree: _api_generated/

Process.validate
Process.initialize
Process.run_step
Process.finalize_step
Process.finalize
process_info
variable_info
filter_variables

Variable
========

Base variable class
-------------------

Although it has the same name, this class is different from
:py:class:`xarray.Variable`.

.. autosummary::
:toctree: _api_generated/

Variable

**Attributes**

.. autosummary::
:toctree: _api_generated/

Variable.value
Variable.state
Variable.rate
Variable.change

**Methods**

.. autosummary::
:toctree: _api_generated/

Variable.to_xarray_variable

Derived variable classes
------------------------

These classes inherit from ``Variable``.

.. autosummary::
:toctree: _api_generated/

NumberVariable
FloatVariable
IntegerVariable

Foreign variable
----------------

.. autosummary::
:toctree: _api_generated/

ForeignVariable

**Attributes**

.. autosummary::
:toctree: _api_generated/

ForeignVariable.ref_process
ForeignVariable.ref_var
ForeignVariable.value
ForeignVariable.state
ForeignVariable.rate
ForeignVariable.change

Diagnostic variable
-------------------

.. autosummary::
:toctree: _api_generated/

diagnostic

Collections of variables
------------------------

.. autosummary::
:toctree: _api_generated/

VariableList
VariableGroup
variable
foreign
group
on_demand
16 changes: 7 additions & 9 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
print("numpy: %s, %s" % (numpy.__version__, numpy.__file__))
except ImportError:
print("no numpy")
try:
import attr
print("attr: %s, %s" % (attr.__version__, attr.__file__))
except ImportError:
print("no attr")
try:
import xarray
print("xarray: %s, %s" % (xarray.__version__, xarray.__file__))
Expand Down Expand Up @@ -120,15 +125,7 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#

# on_rtd is whether we are on readthedocs.org, this line of code grabbed from
# docs.readthedocs.org
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_theme = 'sphinx_rtd_theme'

# otherwise, readthedocs.org uses their theme by default, so no need
# to specify it
Expand Down Expand Up @@ -205,6 +202,7 @@
intersphinx_mapping = {
'python': ('https://docs.python.org/3.6/', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'attr': ('http://www.attrs.org/en/stable/', None),
'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', None),
'xarray': ('http://xarray.pydata.org/en/stable/', None)
}
Expand Down
Loading