Skip to content

Commit

Permalink
Merge pull request dynamicslab#72 from neuralhydrology/staging
Browse files Browse the repository at this point in the history
Auto upload to PyPI, minor bugfixes, doc updates
  • Loading branch information
kratzert committed Feb 13, 2022
2 parents b6d43b2 + 547ede2 commit 577aa32
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 19 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "build and publish to PyPI"
on:
create

jobs:
build-and-publish:
if: ${{ startsWith(github.ref, 'refs/tags') }}
name: Build and publish Python distributions to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: '3.8'
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution to PyPI
if: github.repository == 'neuralhydrology/neuralhydrology'
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ this code in our day-to-day research and will continue to integrate our new rese

# Contact

If you have any questions regarding the usage of this repository, feature requests or comments, please open an issue.
You can also reach out to Frederik Kratzert (kratzert(at)google.com) by email.
For questions or comments regarding the usage of this repository, please use the [discussion section](https://github.com/neuralhydrology/neuralhydrology/discussions) on Github. For bug reports and feature requests, please open an [issue](https://github.com/neuralhydrology/neuralhydrology/issues) on GitHub.
In special cases, you can also reach out to us by email: neuralhydrology(at)googlegroups.com
4 changes: 4 additions & 0 deletions docs/source/usage/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ Training settings
``NSE``, ``RMSE``, ``GMMLoss``, ``CMALLoss``, and ``UMALLoss``. New
losses can be added :py:mod:`here <neuralhydrology.training.loss>`.

- ``allow_subsequent_nan_losses``: Define a number of training steps for
which a loss value of ``NaN`` is ignored and no error is raised but
instead the training loop proceeds to the next iteration step.

- ``target_loss_weights``: A list of float values specifying the
per-target loss weight, when training on multiple targets at once.
Can be combined with any loss. By default, the weight of each target
Expand Down
9 changes: 7 additions & 2 deletions docs/source/usage/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ Installation
------------
There are two ways how you can install NeuralHydrology: Editable or non-editable.
If all you want to do is run experiments with existing datasets and existing models, you can use the non-editable
installation:
installation. To install the latest release from PyPI:

.. code-block::
pip install git+https://github.com/neuralhydrology/neuralhydrology.git
pip install neuralhydrology
To install the package directly from the current master branch of this repository, including any changes that are not yet part of a release, run:

.. code-block::
pip install git+https://github.com/neuralhydrology/neuralhydrology.git
If you want to try implementing your own models or datasets, you'll need an editable installation.
For this, start by downloading or cloning the repository to your local machine.
Expand Down
2 changes: 1 addition & 1 deletion neuralhydrology/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.1"
__version__ = "1.2.2"
4 changes: 2 additions & 2 deletions neuralhydrology/modelzoo/inputlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def __init__(self, cfg: Config):
self._get_embedding_net(cfg.dynamics_embedding, dynamics_input_size, 'dynamics')

if cfg.statics_embedding is None:
self.statics_embedding_p_dropout = 0.0 # if net has no statics dropout we tread is as zero
self.statics_embedding_p_dropout = 0.0 # if net has no statics dropout we treat is as zero
else:
self.statics_embedding_p_dropout = cfg.statics_embedding['dropout']
if cfg.dynamics_embedding is None:
self.dynamics_embedding_p_dropout = 0.0 # if net has no dynamics dropout we tread is as zero
self.dynamics_embedding_p_dropout = 0.0 # if net has no dynamics dropout we treat is as zero
else:
self.dynamics_embedding_p_dropout = cfg.dynamics_embedding['dropout']

Expand Down
11 changes: 6 additions & 5 deletions neuralhydrology/modelzoo/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from neuralhydrology.modelzoo.inputlayer import InputLayer
from neuralhydrology.modelzoo.head import get_head
from neuralhydrology.modelzoo.basemodel import BaseModel
from neuralhydrology.utils.config import Config

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -41,7 +42,7 @@ class Transformer(BaseModel):
# specify submodules of the model that can later be used for finetuning. Names must match class attributes
module_parts = ['embedding_net', 'encoder', 'head']

def __init__(self, cfg: Dict):
def __init__(self, cfg: Config):
super(Transformer, self).__init__(cfg=cfg)

# embedding net before transformer
Expand All @@ -61,7 +62,7 @@ def __init__(self, cfg: Dict):
elif self._positional_encoding_type.lower() == 'sum':
encoder_dim = self.embedding_net.output_size
else:
raise RuntimeError(f"Unrecognized positional encoding type: {self.positional_encoding_type}")
raise RuntimeError(f"Unrecognized positional encoding type: {self._positional_encoding_type}")
self.positional_encoder = _PositionalEncoding(embedding_dim=self.embedding_net.output_size,
dropout=cfg.transformer_positional_dropout,
position_type=cfg.transformer_positional_encoding_type,
Expand Down Expand Up @@ -106,7 +107,7 @@ def forward(self, data: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
Returns
-------
Dict[str, torch.Tensor]
Model outputs and intermediate states as a dictionary.
Model outputs and intermediate states as a dictionary.
- `y_hat`: model predictions of shape [batch size, sequence length, number of target variables].
"""
# pass dynamic and static inputs through embedding layers, then concatenate them
Expand Down Expand Up @@ -173,7 +174,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
----------
x : torch.Tensor
Dimension is ``[sequence length, batch size, embedding output dimension]``.
Data that is to be the input to a transformer encoder after including positional encoding.
Data that is to be the input to a transformer encoder after including positional encoding.
Typically this will be output from an embedding layer.
Returns
Expand All @@ -182,7 +183,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
Dimension is ``[sequence length, batch size, encoder input dimension]``.
The encoder input dimension is either equal to the embedding output dimension (if ``position_type == sum``)
or twice the embedding output dimension (if ``position_type == concatenate``).
Encoder input augmented with positional encoding.
Encoder input augmented with positional encoding.
"""
if self._concatenate:
Expand Down
2 changes: 1 addition & 1 deletion neuralhydrology/training/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_optimizer(model: torch.nn.Module, cfg: Config) -> torch.optim.Optimizer:
torch.optim.Optimizer
Optimizer object that can be used for model training.
"""
if cfg.optimizer == "Adam":
if cfg.optimizer.lower() == "adam":
optimizer = torch.optim.Adam(model.parameters(), lr=cfg.learning_rate[0])
else:
raise NotImplementedError(f"{cfg.optimizer} not implemented or not linked in `get_optimizer()`")
Expand Down
4 changes: 2 additions & 2 deletions neuralhydrology/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,15 +567,15 @@ def transformer_dim_feedforward(self) -> int:
return self._get_value_verbose("transformer_dim_feedforward")

@property
def transformer_positional_dropout(self) -> int:
def transformer_positional_dropout(self) -> float:
return self._get_value_verbose("transformer_positional_dropout")

@property
def transformer_dropout(self) -> float:
return self._get_value_verbose("transformer_dropout")

@property
def transformer_nheads(self) -> float:
def transformer_nheads(self) -> int:
return self._get_value_verbose("transformer_nheads")

@seed.setter
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
with open("neuralhydrology/__about__.py", "r") as fp:
exec(fp.read(), about)

# TODO: Add Classifier, License and update Authors etc.

setup(name='neuralhydrology',
version=about["__version__"],
packages=[
Expand All @@ -25,7 +23,8 @@
'Source': 'https://github.com/neuralhydrology/neuralhydrology',
'Research Blog': 'https://neuralhydrology.github.io/'
},
author='Frederik Kratzert <[email protected]>, Daniel Klotz, Martin Gauch',
author='Frederik Kratzert, Daniel Klotz, Martin Gauch',
author_email='[email protected]',
description='Library for training deep learning models with environmental focus',
long_description=long_description,
long_description_content_type='text/markdown',
Expand All @@ -35,7 +34,7 @@
'nh-results-ensemble=neuralhydrology.utils.nh_results_ensemble:_main'
]
},
python_requires='>=3.6',
python_requires='>=3.7',
install_requires=[
'matplotlib',
'numba',
Expand Down

0 comments on commit 577aa32

Please sign in to comment.