From 80507f26d57fda0b4c8898aeb007575072b8af78 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 May 2023 21:57:05 +0000 Subject: [PATCH 01/15] Bump pandas from 1.5.2 to 2.2.3 Bumps [pandas](https://github.com/pandas-dev/pandas) from 1.5.2 to 2.2.3. - [Release notes](https://github.com/pandas-dev/pandas/releases) - [Commits](https://github.com/pandas-dev/pandas/compare/v1.5.2...v2.2.3) --- updated-dependencies: - dependency-name: pandas dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 81c0afa6..bd822828 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ tensorflow==2.11.0 -pandas==1.5.2 +pandas==2.2.3 scikit-learn==1.3.2 matminer==0.9.2 numpy>=1.25 From af34c8ebff1a19998c861af02c9f4f2c04b1bfb7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 21:02:47 +0000 Subject: [PATCH 02/15] Bump actions/setup-python from 4 to 5 Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 18db3e03..b194fa5b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up Python 3.10 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.10' @@ -48,7 +48,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' From ed81ca039cdb9017036b7afcc20e7f9d409e6dfa Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 26 Oct 2024 15:17:36 +0200 Subject: [PATCH 03/15] Use `pip` cache for linting step --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b194fa5b..53f7e3a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: '3.10' + cache: pip + cache-dependency-path: | + **/requirements*.txt - name: Install pre-commit run: | From aa1e0a437c9c89d07625e1e341acec08145cb3e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 21:37:16 +0000 Subject: [PATCH 04/15] Bump actions/checkout from 3 to 4 Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 53f7e3a3..1cbec06e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python 3.10 uses: actions/setup-python@v5 @@ -48,7 +48,7 @@ jobs: steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 From 80ad9e9668ff325319ed3a3c655ee75f1409b04c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Apr 2024 15:38:59 +0000 Subject: [PATCH 05/15] Bump tensorflow from 2.11.0 to 2.16.1 Bumps [tensorflow](https://github.com/tensorflow/tensorflow) from 2.11.0 to 2.16.1. - [Release notes](https://github.com/tensorflow/tensorflow/releases) - [Changelog](https://github.com/tensorflow/tensorflow/blob/v2.16.1/RELEASE.md) - [Commits](https://github.com/tensorflow/tensorflow/compare/v2.11.0...v2.16.1) --- updated-dependencies: - dependency-name: tensorflow dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- setup.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index bd822828..158bf22a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -tensorflow==2.11.0 +tensorflow==2.16.1 pandas==2.2.3 scikit-learn==1.3.2 matminer==0.9.2 diff --git a/setup.py b/setup.py index 28781da1..6e4f6700 100644 --- a/setup.py +++ b/setup.py @@ -32,12 +32,12 @@ include_package_data=True, packages=setuptools.find_packages(), install_requires=[ - "pandas~=1.5", - "tensorflow~=2.10,<2.12", - "pymatgen>=2023", - "matminer~=0.9", - "numpy>=1.24", - "scikit-learn~=1.3", + "pandas <= 1.5, < 3", + "tensorflow ~= 2.10, < 2.17", + "pymatgen >= 2023", + "matminer ~= 0.9", + "numpy >= 1.24", + "scikit-learn ~= 1.3", ], tests_require=tests_require, test_suite="modnet.tests", From c0af72cd4923403478b7feb58b793fe4b29f76e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 21:39:16 +0000 Subject: [PATCH 06/15] Bump scikit-learn from 1.3.2 to 1.5.2 Bumps [scikit-learn](https://github.com/scikit-learn/scikit-learn) from 1.3.2 to 1.5.2. - [Release notes](https://github.com/scikit-learn/scikit-learn/releases) - [Commits](https://github.com/scikit-learn/scikit-learn/compare/1.3.2...1.5.2) --- updated-dependencies: - dependency-name: scikit-learn dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 158bf22a..fb507172 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,8 @@ tensorflow==2.16.1 pandas==2.2.3 -scikit-learn==1.3.2 +tensorflow==2.11.0 +pandas==1.5.2 +scikit-learn==1.5.0 matminer==0.9.2 numpy>=1.25 pymatgen==2024.3.1 -scikit-learn==1.3.2 From fe8918510fdf7bfbf5d0e94668438f293d52cfe6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 1 Jun 2024 21:39:07 +0000 Subject: [PATCH 07/15] Bump pymatgen from 2024.3.1 to 2024.5.31 Bumps [pymatgen](https://github.com/materialsproject/pymatgen) from 2024.3.1 to 2024.5.31. - [Release notes](https://github.com/materialsproject/pymatgen/releases) - [Changelog](https://github.com/materialsproject/pymatgen/blob/master/docs/CHANGES.md) - [Commits](https://github.com/materialsproject/pymatgen/compare/v2024.3.1...v2024.5.31) --- updated-dependencies: - dependency-name: pymatgen dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index fb507172..a7c636ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,6 @@ tensorflow==2.16.1 pandas==2.2.3 -tensorflow==2.11.0 -pandas==1.5.2 scikit-learn==1.5.0 matminer==0.9.2 numpy>=1.25 -pymatgen==2024.3.1 +pymatgen==2024.5.31 From f33ee6b37d1f1673a84410886d25cd433931ee07 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 26 Oct 2024 15:51:40 +0200 Subject: [PATCH 08/15] Remove deprecated Bayesian model tests from CI run --- .github/workflows/ci.yml | 6 +++--- modnet/tests/test_model.py | 3 +++ pytest.ini | 1 + setup.py | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1cbec06e..37b62ee1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -U setuptools wheel - pip install .[dev,bayesian] + pip install .[dev] - name: Run pre-commit run: | @@ -62,9 +62,9 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install .[test,dev,bayesian] + pip install .[test,dev] - name: Run tests with pytest run: | # run tests with pytest, reporting coverage and timings - pytest -m "not slow" -rs -vvv --durations=0 --cov=./modnet/ + pytest -m "not slow" -m "not deprecated" -rs -vvv --durations=0 --cov=./modnet/ diff --git a/modnet/tests/test_model.py b/modnet/tests/test_model.py index c4853e07..1742b466 100644 --- a/modnet/tests/test_model.py +++ b/modnet/tests/test_model.py @@ -142,6 +142,7 @@ def test_model_integration(subset_moddata, tf_session): assert not np.isnan(model.evaluate(data)) +@pytest.mark.deprecated def test_train_small_bayesian_single_target(subset_moddata, tf_session): """Tests the single target training.""" from modnet.models import BayesianMODNetModel @@ -165,6 +166,7 @@ def test_train_small_bayesian_single_target(subset_moddata, tf_session): assert not np.isnan(model.evaluate(data)) +@pytest.mark.deprecated def test_train_small_bayesian_single_target_classif(subset_moddata, tf_session): """Tests the single target training.""" from modnet.models import BayesianMODNetModel @@ -196,6 +198,7 @@ def is_metal(egap): assert not np.isnan(model.evaluate(data)) +@pytest.mark.deprecated def test_train_small_bayesian_multi_target(subset_moddata, tf_session): """Tests the multi-target training.""" from modnet.models import BayesianMODNetModel diff --git a/pytest.ini b/pytest.ini index 76178536..c382c881 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] markers = slow: marks tests as slow (deselect with '-m "not slow"') + deprecated: mark tests as deprecated (deselect with -m "not deprecated") diff --git a/setup.py b/setup.py index 6e4f6700..9ed48722 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ tests_require=tests_require, test_suite="modnet.tests", extras_require={ - "bayesian": ["tensorflow-probability==0.18"], + "bayesian": ["tensorflow-probability==0.18", "tensorflow == 2.11.*"], "test": tests_require, "dev": dev_require, }, From 4b31560dde2a342f26728fddabbf1ead13d72314 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 26 Oct 2024 16:34:05 +0200 Subject: [PATCH 09/15] Add CI debug print of installed versions --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37b62ee1..dbbd67a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,10 @@ jobs: pip install -r requirements.txt pip install .[test,dev] + - name: List installed versions + run: | + pip list + - name: Run tests with pytest run: | # run tests with pytest, reporting coverage and timings From ed08b698786d00ee9ba4d7712980418faa1fc615 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 26 Oct 2024 16:40:01 +0200 Subject: [PATCH 10/15] Downgrade tensorflow to avoid needing keras downgrade --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index a7c636ba..24046bcd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -tensorflow==2.16.1 +tensorflow==2.15.1 pandas==2.2.3 scikit-learn==1.5.0 matminer==0.9.2 diff --git a/setup.py b/setup.py index 9ed48722..849a3396 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ packages=setuptools.find_packages(), install_requires=[ "pandas <= 1.5, < 3", - "tensorflow ~= 2.10, < 2.17", + "tensorflow ~= 2.10, < 2.16", "pymatgen >= 2023", "matminer ~= 0.9", "numpy >= 1.24", From c63084237c0cfd49aaff76c3a78fc95970e379f9 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sat, 26 Oct 2024 17:00:16 +0200 Subject: [PATCH 11/15] Try to deprecate 'learning_rate' again --- modnet/models/vanilla.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modnet/models/vanilla.py b/modnet/models/vanilla.py index 56ebd7f6..6eb8b4ff 100644 --- a/modnet/models/vanilla.py +++ b/modnet/models/vanilla.py @@ -1343,6 +1343,9 @@ def fit( } fit_params.update(fit_params_kw) + if "learning_rate" in fit_params: + fit_params.pop("learning_rate") + warnings.warn("learning_rate is deprecated, use lr instead.") if loss is None: loss = "mse" From 96fb84d4d5a25be62e2efec6e660a4ee52b882df Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Sun, 17 Nov 2024 13:06:23 +0000 Subject: [PATCH 12/15] Take all models from ensemble when refitting in `fit_preset` No idea how this wasn't triggered in the tests previously... --- modnet/models/ensemble.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modnet/models/ensemble.py b/modnet/models/ensemble.py index 880d09e9..dc2fce8e 100644 --- a/modnet/models/ensemble.py +++ b/modnet/models/ensemble.py @@ -438,7 +438,7 @@ def fit_preset( for i in range(n_splits): best_5_idx = np.argsort(val_losses[:, i])[:5] for idx in best_5_idx: - final_models += models[idx][i].model + final_models.extend(models[idx][i].models) self.__init__(modnet_models=final_models) os.environ["TF_CPP_MIN_LOG_LEVEL"] = "0" # reset From 0d09c57d5ccb3b1170fff9301aece2ee2c441601 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 25 Nov 2024 10:55:31 +0000 Subject: [PATCH 13/15] Add test for ensemble multi-target with custom loss --- modnet/tests/test_model.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/modnet/tests/test_model.py b/modnet/tests/test_model.py index 1742b466..646b94d4 100644 --- a/modnet/tests/test_model.py +++ b/modnet/tests/test_model.py @@ -303,6 +303,41 @@ def test_train_small_bootstrap_multi_target(small_moddata, tf_session): model.predict(data, return_unc=True) +def test_train_small_bootstrap_custom_loss_multi_target(small_moddata, tf_session): + """Tests a multi-target ensemble model with a custom loss per target, + modified from Hao Wu's example. + + """ + from modnet.models import EnsembleMODNetModel + import tensorflow as tf + + def custom_loss(y_true, y_pred): + loss1 = y_pred - y_true + return tf.reduce_mean( + tf.math.abs( + tf.boolean_mask(loss1, tf.reduce_all(~tf.math.is_nan(loss1), axis=1)) + ) + ) + + data = small_moddata + # set 'optimal' features manually + data.optimal_features = [ + col for col in data.df_featurized.columns if col.startswith("ElementProperty") + ] + + model = EnsembleMODNetModel( + [[["eform", "egap"]]], + weights={"eform": 1, "egap": 1}, + num_neurons=[[16], [8], [8], [4]], + n_feat=10, + n_models=3, + bootstrap=True, + ) + + model.fit(data, loss=[custom_loss, custom_loss], epochs=2) + model.predict(data, return_unc=True) + + @pytest.mark.slow def test_train_small_bootstrap_presets(small_moddata, tf_session): """Tests the `fit_preset()` method.""" From f602fb37a2ef496f6b4ede7b8c2308e01d4e2553 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 25 Nov 2024 10:55:45 +0000 Subject: [PATCH 14/15] Add test for GA with mulit-target + custom loss --- modnet/tests/test_hyper_opt.py | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/modnet/tests/test_hyper_opt.py b/modnet/tests/test_hyper_opt.py index dc117b74..7c4ed851 100644 --- a/modnet/tests/test_hyper_opt.py +++ b/modnet/tests/test_hyper_opt.py @@ -29,3 +29,41 @@ def test_ga(small_moddata, tf_session): assert type(model) is EnsembleMODNetModel assert len(model.models) == 1 + + +def test_ga_multi_target(small_moddata, tf_session): + """Tests the modnet.hyper_opt.FitGenetic algorithm.""" + from modnet.hyper_opt import FitGenetic + + data = small_moddata + # set 'optimal' features manually + data.optimal_features = [ + col for col in data.df_featurized.columns if col.startswith("ElementProperty") + ] + + def custom_loss(y_true, y_pred): + import tensorflow as tf + loss1 = y_pred - y_true + return tf.reduce_mean( + tf.math.abs( + tf.boolean_mask(loss1, tf.reduce_all(~tf.math.is_nan(loss1), axis=1)) + ) + ) + + ga = FitGenetic(data) + model = ga.run( + size_pop=2, + num_generations=2, + prob_mut=0.5, + nested=2, + n_jobs=2, + early_stopping=2, + refit=1, + loss=[custom_loss, custom_loss], + fast=True, + ) + + from modnet.models import EnsembleMODNetModel + + assert type(model) is EnsembleMODNetModel + assert len(model.models) == 1 From 32868505a9720dee928288b7ae72365c66f6df00 Mon Sep 17 00:00:00 2001 From: Matthew Evans Date: Mon, 25 Nov 2024 12:41:57 +0000 Subject: [PATCH 15/15] Add test case for simple model with custom loss --- modnet/tests/test_model.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modnet/tests/test_model.py b/modnet/tests/test_model.py index 646b94d4..1bcd4464 100644 --- a/modnet/tests/test_model.py +++ b/modnet/tests/test_model.py @@ -75,6 +75,38 @@ def test_train_small_model_multi_target(subset_moddata, tf_session): model.predict(data) assert not np.isnan(model.evaluate(data)) +def test_train_small_model_multi_target_custom_loss(subset_moddata, tf_session): + """Tests the multi-target training.""" + from modnet.models import MODNetModel + from functools import partial + import tensorflow as tf + + data = subset_moddata + # set 'optimal' features manually + data.optimal_features = [ + col for col in data.df_featurized.columns if col.startswith("ElementProperty") + ] + + def custom_loss(y_true, y_pred, rescale=1): + loss1 = y_pred - y_true + return rescale * tf.reduce_mean( + tf.math.abs( + tf.boolean_mask(loss1, tf.reduce_all(~tf.math.is_nan(loss1), axis=1)) + ) + ) + + model = MODNetModel( + [[["eform", "egap"]]], + weights={"eform": 1, "egap": 1}, + num_neurons=[[16], [8], [8], [4]], + n_feat=10, + ) + + model.fit(data, loss=[partial(custom_loss, rescale=10), custom_loss], epochs=2) + model.predict(data) + breakpoint() + assert not np.isnan(model.evaluate(data)) + def test_train_small_model_presets(subset_moddata, tf_session): """Tests the `fit_preset()` method."""