diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml new file mode 100644 index 00000000..1623ef02 --- /dev/null +++ b/.github/workflows/publish-pypi.yml @@ -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 }} diff --git a/README.md b/README.md index a14f16bd..ce226eed 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/source/usage/config.rst b/docs/source/usage/config.rst index 6654ef6f..f59b0ec2 100644 --- a/docs/source/usage/config.rst +++ b/docs/source/usage/config.rst @@ -290,6 +290,10 @@ Training settings ``NSE``, ``RMSE``, ``GMMLoss``, ``CMALLoss``, and ``UMALLoss``. New losses can be added :py:mod:`here `. +- ``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 diff --git a/docs/source/usage/quickstart.rst b/docs/source/usage/quickstart.rst index 0a2b5a2b..c5b651f5 100644 --- a/docs/source/usage/quickstart.rst +++ b/docs/source/usage/quickstart.rst @@ -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. diff --git a/neuralhydrology/__about__.py b/neuralhydrology/__about__.py index a955fdae..bc86c944 100644 --- a/neuralhydrology/__about__.py +++ b/neuralhydrology/__about__.py @@ -1 +1 @@ -__version__ = "1.2.1" +__version__ = "1.2.2" diff --git a/neuralhydrology/modelzoo/inputlayer.py b/neuralhydrology/modelzoo/inputlayer.py index 20072e92..c6cf2b13 100644 --- a/neuralhydrology/modelzoo/inputlayer.py +++ b/neuralhydrology/modelzoo/inputlayer.py @@ -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'] diff --git a/neuralhydrology/modelzoo/transformer.py b/neuralhydrology/modelzoo/transformer.py index b8650dea..56146ab6 100644 --- a/neuralhydrology/modelzoo/transformer.py +++ b/neuralhydrology/modelzoo/transformer.py @@ -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__) @@ -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 @@ -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, @@ -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 @@ -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 @@ -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: diff --git a/neuralhydrology/training/__init__.py b/neuralhydrology/training/__init__.py index 9c2e536c..01c6809d 100644 --- a/neuralhydrology/training/__init__.py +++ b/neuralhydrology/training/__init__.py @@ -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()`") diff --git a/neuralhydrology/utils/config.py b/neuralhydrology/utils/config.py index 2d6748fb..1987188e 100644 --- a/neuralhydrology/utils/config.py +++ b/neuralhydrology/utils/config.py @@ -567,7 +567,7 @@ 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 @@ -575,7 +575,7 @@ 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 diff --git a/setup.py b/setup.py index 505665e5..6fef11c7 100644 --- a/setup.py +++ b/setup.py @@ -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=[ @@ -25,7 +23,8 @@ 'Source': 'https://github.com/neuralhydrology/neuralhydrology', 'Research Blog': 'https://neuralhydrology.github.io/' }, - author='Frederik Kratzert , Daniel Klotz, Martin Gauch', + author='Frederik Kratzert, Daniel Klotz, Martin Gauch', + author_email='neuralhydrology@googlegroups.com', description='Library for training deep learning models with environmental focus', long_description=long_description, long_description_content_type='text/markdown', @@ -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',