Skip to content

Commit b58f293

Browse files
authored
Merge pull request #54 from mhpi/dev
Update to package nomenclature
2 parents 4d6992c + a7f7404 commit b58f293

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+612
-407
lines changed

.github/workflows/lint.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- master
7-
- dmg_dev
7+
- dev
88
pull_request:
99
branches:
1010
- master
@@ -19,15 +19,15 @@ jobs:
1919

2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@v4.2.2
2323

2424
- name: Set up Python
25-
uses: actions/setup-python@v5
25+
uses: actions/setup-python@v5.6.0
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828

2929
- name: Cache pip
30-
uses: actions/cache@v4
30+
uses: actions/cache@v4.2.3
3131
with:
3232
path: ~/.cache/pip
3333
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}

.github/workflows/pytest.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches:
66
- master
7-
- dmg_dev
7+
- dev
88
pull_request:
99
branches:
1010
- master
@@ -18,15 +18,15 @@ jobs:
1818
python-version: ['3.12', '3.13']
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- uses: actions/checkout@v4.2.2
2222

2323
- name: Set up Python ${{ matrix.python-version }}
24-
uses: actions/setup-python@v5
24+
uses: actions/setup-python@v5.6.0
2525
with:
2626
python-version: ${{ matrix.python-version }}
2727

2828
- name: Cache uv
29-
uses: actions/cache@v4
29+
uses: actions/cache@v4.2.3
3030
with:
3131
path: ~/.cache/uv
3232
key: ${{ runner.os }}-uv-${{ hashFiles('**/pyproject.toml', '**/uv.lock') }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,6 @@ tmp/
178178
# Other Directories
179179
archive/
180180
validation/
181+
182+
# Model optimization config with RayTune
183+
!tune/

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
exclude: "mkdocs.*\\.yml$" # Exclude mkdocs YAML files
9+
- id: debug-statements
10+
11+
- repo: https://github.com/astral-sh/ruff-pre-commit
12+
rev: v0.1.5 # Use whatever version you're currently using
13+
hooks:
14+
- id: ruff
15+
args: [--fix]
16+
exclude: "hooks/.*\\.py$" # Exclude the hooks directory from ruff
17+
- id: ruff-format

README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ This work is mantained by [MHPI](http://water.engr.psu.edu/shen/) and advised by
4040

4141
To install 𝛿MG, clone the repo and install in developer mode with [Astral UV](https://docs.astral.sh/uv/):
4242

43-
```bash
44-
git clone [email protected]:mhpi/generic_deltamodel.git
45-
uv pip install -e ./generic_deltamodel
46-
```
43+
```bash
44+
git clone [email protected]:mhpi/generic_deltamodel.git
45+
uv pip install -e ./generic_deltamodel
46+
```
4747

4848
Pip and Conda are also supported, though UV is recommended. See [setup](./docs/setup.md) for further details.
4949

@@ -55,49 +55,49 @@ See [how to run](./docs/how_to_run.md).
5555

5656
**Example -- Differentiable Parameter Learning**: Use an LSTM to learn parameters for the [HBV](https://en.wikipedia.org/wiki/HBV_hydrology_model) hydrological model.
5757

58-
```python
59-
from hydroDL2.models.hbv.hbv import HBV
58+
```python
59+
from hydrodl2.models.hbv.hbv import Hbv
6060

61-
from dMG.core.data.loaders import HydroLoader
62-
from dMG.core.utils import load_nn_model, print_config, set_randomseed
63-
from dMG.models.delta_models import DplModel
64-
from example import load_config, take_data_sample
61+
from dmg.core.data.loaders import HydroLoader
62+
from dmg.core.utils import load_nn_model, print_config, set_randomseed
63+
from dmg.models.delta_models import DplModel
64+
from example import load_config, take_data_sample
6565

66-
CONFIG_PATH = '../example/conf/config_dhbv_1_0.yaml'
66+
CONFIG_PATH = '../example/conf/config_dhbv_1_0.yaml'
6767

6868

69-
# Model configuration
70-
config = load_config(CONFIG_PATH)
69+
# Model configuration
70+
config = load_config(CONFIG_PATH)
7171

72-
# Initialize physical model and NN.
73-
phy_model = HBV(config['delta_model']['phy_model'])
74-
nn = load_nn_model(phy_model, config['delta_model'])
72+
# Initialize physical model and NN.
73+
phy_model = Hbv(config['delta_model']['phy_model'])
74+
nn = load_nn_model(phy_model, config['delta_model'])
7575

76-
# Create differentiable model dHBV: a torch.nn.Module that describes how
77-
# the NN is linked to the physical model HBV.
78-
dpl_model = DplModel(phy_model=phy_model, nn_model=nn)
76+
# Create differentiable model dHBV: a torch.nn.Module that describes how
77+
# the NN is linked to the physical model HBV.
78+
dpl_model = DplModel(phy_model=phy_model, nn_model=nn)
7979

80-
# Load dataset of NN and HBV inputs.
81-
dataset = HydroLoader(config).dataset
82-
dataset_sample = take_data_sample(config, dataset, days=730, basins=100)
80+
# Load dataset of NN and HBV inputs.
81+
dataset = HydroLoader(config).dataset
82+
dataset_sample = take_data_sample(config, dataset, days=730, basins=100)
8383

84-
output = dpl_model(dataset_sample)
85-
```
84+
output = dpl_model(dataset_sample)
85+
```
8686

8787
This exposes a key characteristic of the differentiable model `DplModel`: composition of a physical model, `phy_model`, and a neural network, `nn`. Internally, `DplModel` looks like
8888

89-
```python
90-
# NN forward
91-
parameters = self.nn_model(dataset_sample['xc_nn_norm'])
89+
```python
90+
# NN forward
91+
parameters = self.nn_model(dataset_sample['xc_nn_norm'])
9292

93-
# Physics model forward
94-
predictions = self.phy_model(
95-
dataset_sample,
96-
parameters,
97-
)
98-
```
93+
# Physics model forward
94+
predictions = self.phy_model(
95+
dataset_sample,
96+
parameters,
97+
)
98+
```
9999

100-
Check out [examples](https://github.com/mhpi/generic_deltamodel/tree/master/example/hydrology) to see model training/testing/simulation in detail. We recommend starting [here](./example/hydrology/example_dhbv_1_0.ipynb), which is a continuation of the above. A [Colab Notebook](https://colab.research.google.com/drive/19PRLrI-L7cGeYzkk2tOetULzQK8s_W7v?usp=sharing) for this δHBV example is also available.
100+
Check out [examples](https://github.com/mhpi/generic_deltamodel/tree/master/example/hydrology) to see model training/testing/simulation in detail. We recommend starting with the [δHBV 1.0 tutorial](./example/hydrology/example_dhbv_1_0.ipynb), which can also be run in a [Colab Notebook](https://colab.research.google.com/drive/19PRLrI-L7cGeYzkk2tOetULzQK8s_W7v?usp=sharing) to leverage online compute.
101101

102102
</br>
103103

@@ -129,7 +129,7 @@ Currently in development. Find more details and results in [Aboelyazeed et al. (
129129

130130
## Ecosystem Integration
131131

132-
- **HydroDL 2.0 ([`hydroDL2`](https://github.com/mhpi/hydroDL2))**: Home to MHPI's suite of process-based hydrology models and differentiable model augmentations.
132+
- **HydroDL 2.0 ([`hydrodl2`](https://github.com/mhpi/hydrodl2))**: Home to MHPI's suite of process-based hydrology models and differentiable model augmentations.
133133
<!-- - **HydroData ([`hydro_data_dev`](https://github.com/mhpi/hydro_data_dev))**: Data extraction, processing, and management tools optimized for geospatial datasets. (In development) -->
134134
<!-- - **Config GUI ([`GUI-Config-builder`](https://mhpi-spatial.s3.us-east-2.amazonaws.com/mhpi-release/config_builder_gui/Config+Builder+GUI.zip))([Source](https://github.com/mhpi/GUI-Config-builder))**: An intuitive, user-friendly tool designed to simplify the creation and editing of configuration files for model setup and development. -->
135135
- **Differentiable Ecosystem Modeling ([`diffEcosys (dev version only)`](https://github.com/hydroPKDN/diffEcosys/))**: A physics-informed machine learning system for ecosystem modeling, demonstrated using the photosynthesis process representation within the Functionally Assembled Terrestrial Ecosystem Simulator (FATES) model. This model is coupled to NNs that learn parameters from observations of photosynthesis rates.
@@ -151,8 +151,8 @@ Currently in development. Find more details and results in [Aboelyazeed et al. (
151151

152152
```text
153153
.
154-
├── src/dMG/
155-
│ ├── __main__.py # Runs 𝛿MG; models, experiments
154+
├── src/dmg/
155+
│ ├── __main__.py # Runs dMG; models, experiments
156156
│ ├── core/
157157
│ │ ├── calc/ # Calculation utilities
158158
│ │ ├── data/ # Data loaders and samplers

conf/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def validate_dataset_times(cls, values):
148148
class Config(BaseModel):
149149
"""Configuration class for the model."""
150150
mode: ModeEnum = Field(default=ModeEnum.train_test)
151+
do_tune: bool = False
151152
multimodel_type: str = 'none'
152153
random_seed: int = 0
153154
device: str = 'cpu'
@@ -242,7 +243,7 @@ def check_device(cls, values):
242243
'learning_rate': 1.0,
243244
'forcings': ['x1_var', 'x2_var'],
244245
'attributes': ['attr1', 'attr2'],
245-
}
246+
},
246247
},
247248
observations={
248249
'name': 'example',

conf/hydra/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ help:
1313
job:
1414
chdir: False # Changes working dir to run.dir below.
1515
run:
16-
dir: ../output/logs/${now:%Y-%m-%d_%H-%M-%S}
16+
dir: ./output/logs/${now:%Y-%m-%d_%H-%M-%S}
1717
sweep:
1818
dir: multirun
1919
subdir: ${hydra.job.override_dirname}

conf/tune/raytune.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Basic config for model tuning.
2+
# Tuning options and search space rules belong here. Keys should match those in
3+
# master config.
4+
name: raytune
5+
6+
metric: mean_accuracy # val_loss, mean_accuracy
7+
mode: min
8+
num_samples: 20
9+
scheduler: ASHAScheduler
10+
search_alg: OptunaSearch
11+
search_alg_params:
12+
n_trials: 10
13+
time_budget: 60
14+
metric: mean_accuracy
15+
mode: min
16+
17+
save_epoch: 1
18+
19+
rules:
20+
delta_model:
21+
nn_model:
22+
hidden_size: [128, 256, 512]
23+
learning_rate: [1.0, 0.5]

docs/configuration_files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ If you wish to use additional configuration files to store distinguished setting
5757

5858
Configuration file managment is handled by the Hydra config manager (see above). Essentially, at the start of a model experiment, Hydra will load configs into a single Python dictionary object of all settings that can be accessed throughout the framework.
5959

60-
You can see this demonstrated in the main dMG run file, `./generic_deltamodel/src/dMG/__main__.py`, at the start of the main function we call the decorator
60+
You can see this demonstrated in the main dMG run file, `./generic_deltamodel/src/dmg/__main__.py`, at the start of the main function we call the decorator
6161

6262
```python
6363
@hydra.main(

docs/configuration_glossary.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ The settings are broken down as they appear in the YAML configuration files, wit
5050

5151
**gpu_id**: [0] If `device = cuda`, the index of the GPU in your system to run models on. Index 0 will always be available.
5252

53-
**data_loader**: Class name of the data loader to use. E.g., *HydroLoader* located in `./generic_deltamodel/src/dMG/core/data/loaders/hydro_loader.py`. Note class name must be Camel-case w/o spaces corresponding to the file name.
53+
**data_loader**: Class name of the data loader to use. E.g., *HydroLoader* located in `./generic_deltamodel/src/dmg/core/data/loaders/hydro_loader.py`. Note class name must be Camel-case w/o spaces corresponding to the file name.
5454

55-
**data_sampler**: Class name of the data sampler used in training/inference. E.g., *HydroSampler* located in `./generic_deltamodel/src/dMG/core/data/samplers/hydro_sampler.py`. Follows same convention as data_loader.
55+
**data_sampler**: Class name of the data sampler used in training/inference. E.g., *HydroSampler* located in `./generic_deltamodel/src/dmg/core/data/samplers/hydro_sampler.py`. Follows same convention as data_loader.
5656

57-
**trainer**: Class name of the trainer used in training/inference. E.g., *Trainer* located in `./generic_deltamodel/src/dMG/trainers/trainer.py`. Follows same convention as data_loader.
57+
**trainer**: Class name of the trainer used in training/inference. E.g., *Trainer* located in `./generic_deltamodel/src/dmg/trainers/trainer.py`. Follows same convention as data_loader.
5858

5959
**save_path**: [./output] root path to which model weights, outputs, statistics, and metrics will be saved.
6060

@@ -116,7 +116,7 @@ The settings are broken down as they appear in the YAML configuration files, wit
116116

117117
**loss_function**:
118118

119-
- **model**: [KgeBatchLoss, KgeNormBatchLoss, MseLoss, NseBatchLoss, NseSqrtBatchLoss, RmseCombLoss, RmseLoss] Loss function for training. See `./generic_deltamodel/src/dMG/models/criterion/` for all available loss functions. You can add custom criterion, but they must follow Class-File convention as illustrated for `data_loader`, etc.
119+
- **model**: [KgeBatchLoss, KgeNormBatchLoss, MseLoss, NseBatchLoss, NseSqrtBatchLoss, RmseCombLoss, RmseLoss] Loss function for training. See `./generic_deltamodel/src/dmg/models/criterion/` for all available loss functions. You can add custom criterion, but they must follow Class-File convention as illustrated for `data_loader`, etc.
120120

121121
</br>
122122

@@ -132,7 +132,7 @@ The settings are broken down as they appear in the YAML configuration files, wit
132132
- `HBV_adj`: δHBV with adjoint method.
133133
- `HBV_1_1p`: δHBV 1.1p
134134
- `HBV_2_0`: δHBV 2.0
135-
- `custom_model`: If you create and add a physical to [phy_model/](../src/dMG/models/phy_models/), this will be the class name. Note it must follow the Class-File convention as illustrated for `data_loader`, etc.
135+
- `custom_model`: If you create and add a physical to [phy_model/](../src/dmg/models/phy_models/), this will be the class name. Note it must follow the Class-File convention as illustrated for `data_loader`, etc.
136136

137137
- *nmul*: Number of parallel parameter sets to use. These will be averaged for single physical model output.
138138

@@ -214,7 +214,7 @@ The settings are broken down as they appear in the YAML configuration files, wit
214214

215215
- *scaling_function*: [sigmoid, softmax] Method to use for scaling learned weights.
216216

217-
- *loss_function*: [KgeBatchLoss, KgeNormBatchLoss, MseLoss, NseBatchLoss, NseSqrtBatchLoss, RmseCombLoss, RmseLoss] Loss function for training. See `./generic_deltamodel/src/dMG/models/criterion/` for all available loss functions. You can add custom criterion, but they must follow Class-File convention as illustrated for `data_loader`, etc.
217+
- *loss_function*: [KgeBatchLoss, KgeNormBatchLoss, MseLoss, NseBatchLoss, NseSqrtBatchLoss, RmseCombLoss, RmseLoss] Loss function for training. See `./generic_deltamodel/src/dmg/models/criterion/` for all available loss functions. You can add custom criterion, but they must follow Class-File convention as illustrated for `data_loader`, etc.
218218

219219
- *use_rb_loss*: [bool] If True, include range-bound loss regularization. Penalize learned weights when their sum exceeds specific bounds.
220220

0 commit comments

Comments
 (0)