From 7f48bfcf2389d21d751bf7d1b2a9c9401350b845 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Mon, 25 Sep 2023 20:55:00 +0200 Subject: [PATCH 01/21] change num_workers to 1 instead of 10 --- examples/01_icetray/02_compare_sqlite_and_parquet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/01_icetray/02_compare_sqlite_and_parquet.py b/examples/01_icetray/02_compare_sqlite_and_parquet.py index 252f1a346..91bbe6f1d 100644 --- a/examples/01_icetray/02_compare_sqlite_and_parquet.py +++ b/examples/01_icetray/02_compare_sqlite_and_parquet.py @@ -34,7 +34,7 @@ def convert_data() -> None: I3FeatureExtractorIceCube86(PULSEMAP), ], outdir=OUTPUT_DIR, - workers=10, + workers=1, ) # Run data converters. From c6ee6b37c58b6c7758f8ac9aeceec1ac5bd20afd Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Mon, 25 Sep 2023 21:07:41 +0200 Subject: [PATCH 02/21] remove redundant import --- examples/01_icetray/01_convert_i3_files.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/01_icetray/01_convert_i3_files.py b/examples/01_icetray/01_convert_i3_files.py index 495c9a13c..40b304327 100644 --- a/examples/01_icetray/01_convert_i3_files.py +++ b/examples/01_icetray/01_convert_i3_files.py @@ -8,7 +8,6 @@ I3FeatureExtractorIceCube86, I3RetroExtractor, I3TruthExtractor, - I3GenericExtractor, ) from graphnet.data.dataconverter import DataConverter from graphnet.data.parquet import ParquetDataConverter From 124f67a81b01f10e43ca445576b166c20b05daa4 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Mon, 25 Sep 2023 22:08:31 +0200 Subject: [PATCH 03/21] add unit tests for examples, add default args. --- .github/workflows/build.yml | 6 +++--- examples/02_data/01_read_dataset.py | 8 +++++++- examples/04_training/01_train_dynedge.py | 2 +- examples/04_training/02_train_tito_model.py | 2 +- examples/04_training/03_train_dynedge_from_config.py | 2 +- .../04_training/04_train_multiclassifier_from_configs.py | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 080146149..589afb9b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest tests/ + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=05_pisa coverage xml -o coverage.xml - name: Work around permission issue run: | @@ -88,7 +88,7 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray --ignore=examples/05_pisa coverage report -m build-macos: @@ -108,5 +108,5 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray --ignore=examples/05_pisa coverage report -m diff --git a/examples/02_data/01_read_dataset.py b/examples/02_data/01_read_dataset.py index be913e190..de8fecb18 100644 --- a/examples/02_data/01_read_dataset.py +++ b/examples/02_data/01_read_dataset.py @@ -113,7 +113,13 @@ def main(backend: str) -> None: """ ) - parser.add_argument("backend", choices=["sqlite", "parquet"]) + parser.add_argument( + "backend", + choices=["sqlite", "parquet"], + default="sqlite", + const="sqlite", + nargs="?", + ) args = parser.parse_args() diff --git a/examples/04_training/01_train_dynedge.py b/examples/04_training/01_train_dynedge.py index 58e513ec2..f9af11998 100644 --- a/examples/04_training/01_train_dynedge.py +++ b/examples/04_training/01_train_dynedge.py @@ -213,7 +213,7 @@ def main( parser.with_standard_arguments( "gpus", - ("max-epochs", 5), + ("max-epochs", 1), "early-stopping-patience", ("batch-size", 16), "num-workers", diff --git a/examples/04_training/02_train_tito_model.py b/examples/04_training/02_train_tito_model.py index ee3d89760..f3d60d553 100644 --- a/examples/04_training/02_train_tito_model.py +++ b/examples/04_training/02_train_tito_model.py @@ -223,7 +223,7 @@ def main( parser.with_standard_arguments( "gpus", - ("max-epochs", 5), + ("max-epochs", 1), ("early-stopping-patience", 2), ("batch-size", 16), "num-workers", diff --git a/examples/04_training/03_train_dynedge_from_config.py b/examples/04_training/03_train_dynedge_from_config.py index 9a6df73dd..1dec95961 100644 --- a/examples/04_training/03_train_dynedge_from_config.py +++ b/examples/04_training/03_train_dynedge_from_config.py @@ -138,7 +138,7 @@ def main( "dataset-config", "model-config", "gpus", - ("max-epochs", 5), + ("max-epochs", 1), "early-stopping-patience", ("batch-size", 16), "num-workers", diff --git a/examples/04_training/04_train_multiclassifier_from_configs.py b/examples/04_training/04_train_multiclassifier_from_configs.py index 6937b01b1..6385c010c 100644 --- a/examples/04_training/04_train_multiclassifier_from_configs.py +++ b/examples/04_training/04_train_multiclassifier_from_configs.py @@ -175,7 +175,7 @@ def main( ), ), "gpus", - ("max-epochs", 5), + ("max-epochs", 1), "early-stopping-patience", ("batch-size", 16), "num-workers", From 496215bcff4d8d0d2aa22afbaf1f196a931601c9 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Mon, 25 Sep 2023 22:49:28 +0200 Subject: [PATCH 04/21] update build.yml --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 589afb9b3..5339d6d10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=05_pisa + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=examples/05_pisa/ coverage xml -o coverage.xml - name: Work around permission issue run: | @@ -88,7 +88,7 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray --ignore=examples/05_pisa + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray/ --ignore=examples/05_pisa/ coverage report -m build-macos: @@ -108,5 +108,5 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray --ignore=examples/05_pisa + coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray/ --ignore=examples/05_pisa/ coverage report -m From 55cdf515231ce97dda6801a5eeeaf0109d45d2e9 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 10:17:38 +0200 Subject: [PATCH 05/21] cmon pytest --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5339d6d10..8fa657cd2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=examples/05_pisa/ + coverage run --source=graphnet -m pytest examples/ --ignore=examples/05_pisa/ coverage xml -o coverage.xml - name: Work around permission issue run: | From 122f99852f5888a1773fa4bfadf51345a72ddff0 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 11:45:04 +0200 Subject: [PATCH 06/21] add unit tests --- .../01_icetray/test_icetray_examples.py | 32 +++++++++++++++++++ tests/examples/02_data/test_data_examples.py | 30 +++++++++++++++++ .../03_weights/test_weights_examples.py | 16 ++++++++++ .../04_training/test_training_examples.py | 30 +++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 tests/examples/01_icetray/test_icetray_examples.py create mode 100644 tests/examples/02_data/test_data_examples.py create mode 100644 tests/examples/03_weights/test_weights_examples.py create mode 100644 tests/examples/04_training/test_training_examples.py diff --git a/tests/examples/01_icetray/test_icetray_examples.py b/tests/examples/01_icetray/test_icetray_examples.py new file mode 100644 index 000000000..538a67d36 --- /dev/null +++ b/tests/examples/01_icetray/test_icetray_examples.py @@ -0,0 +1,32 @@ +"""Test for examples in 01_icetray.""" +import runpy +import os +from graphnet.constants import GRAPHNET_ROOT_DIR + +EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/01_icetray") + + +def test_01_convert_i3_files() -> None: + """Test for 01_convert_i3_files.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "01_convert_i3_files.py")) + + +def test_02_compare_sqlite_and_parquet() -> None: + """Test for 02_compare_sqlite_and_parquet.""" + runpy.run_path( + os.path.join(EXAMPLE_PATH, "02_compare_sqlite_and_parquet.py") + ) + + +def test_03_i3_deployer_example() -> None: + """Test for 03_i3_deployer_example.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "03_i3_deployer_example.py")) + + +def test_04_i3_module_in_native_icetray_example() -> None: + """Test for 04_i3_module_in_native_icetray_example.""" + runpy.run_path( + os.path.join( + EXAMPLE_PATH, "04_i3_module_in_naticve_icetray_example.py" + ) + ) diff --git a/tests/examples/02_data/test_data_examples.py b/tests/examples/02_data/test_data_examples.py new file mode 100644 index 000000000..ba7f4a072 --- /dev/null +++ b/tests/examples/02_data/test_data_examples.py @@ -0,0 +1,30 @@ +"""Tests for examples in 02_data.""" +import runpy +import os +from graphnet.constants import GRAPHNET_ROOT_DIR + +EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/02_data") + + +def test_01_read_dataset() -> None: + """Test for 01_read_dataset.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "01_read_dataset.py")) + + +def test_02_plot_feature_distribution() -> None: + """Test for 02_plot_feature_distribution.""" + runpy.run_path( + os.path.join(EXAMPLE_PATH, "02_plot_feature_distribution.py") + ) + + +def test_03_convert_parquet_to_sqlite() -> None: + """Test for 03_convert_parquet_to_sqlite.""" + runpy.run_path( + os.path.join(EXAMPLE_PATH, "03_convert_parquet_to_sqlite.py") + ) + + +def test_04_ensemble_dataset() -> None: + """Test for 04_ensemble_dataset.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py")) diff --git a/tests/examples/03_weights/test_weights_examples.py b/tests/examples/03_weights/test_weights_examples.py new file mode 100644 index 000000000..8715fefc6 --- /dev/null +++ b/tests/examples/03_weights/test_weights_examples.py @@ -0,0 +1,16 @@ +"""Test for examples in 03_weights.""" +import runpy +import os +from graphnet.constants import GRAPHNET_ROOT_DIR + +EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/03_weights") + + +def test_01_fit_uniform_weights() -> None: + """Test for 01_fit_uniform_weights.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "01_fit_uniform_weights.py")) + + +def test_02_fit_bjoern_low_weights() -> None: + """Test for 02_fit_bjoern_low_weights.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py")) diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py new file mode 100644 index 000000000..3c049e6bb --- /dev/null +++ b/tests/examples/04_training/test_training_examples.py @@ -0,0 +1,30 @@ +"""Test for examples in 04_training.""" +import runpy +import os +from graphnet.constants import GRAPHNET_ROOT_DIR + +EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/04_data") + + +def test_01_train_dynedge() -> None: + """Test for 01_train_dynedge.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "01_train_dynedge.py")) + + +def test_02_train_tito_model() -> None: + """Test for 02_train_tito_model.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, "02_train_tito_model.py")) + + +def test_03_train_dynedge_from_config() -> None: + """Test for 03_train_dynedge_from_config.""" + runpy.run_path( + os.path.join(EXAMPLE_PATH, "03_train_dynedge_from_config.py") + ) + + +def test_04_train_multiclassifier_from_configs() -> None: + """Test for 04_train_multiclassifier_from_configs.""" + runpy.run_path( + os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py") + ) From 494e1146d9f111935bb218b91b8098346a4287cc Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 11:46:55 +0200 Subject: [PATCH 07/21] update build.yml --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8fa657cd2..6998ce22f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,7 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest examples/ --ignore=examples/05_pisa/ + coverage run --source=graphnet -m pytest tests/ coverage xml -o coverage.xml - name: Work around permission issue run: | @@ -88,7 +88,7 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray/ --ignore=examples/05_pisa/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ coverage report -m build-macos: @@ -108,5 +108,5 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ examples/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=examples/01_icetray/ --ignore=examples/05_pisa/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/01_icetray/ coverage report -m From 069314c984bc21cea9870e36c23c074d6f9eefdf Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 11:56:21 +0200 Subject: [PATCH 08/21] fix unit test paths --- tests/examples/02_data/test_data_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/02_data/test_data_examples.py b/tests/examples/02_data/test_data_examples.py index ba7f4a072..2d076151a 100644 --- a/tests/examples/02_data/test_data_examples.py +++ b/tests/examples/02_data/test_data_examples.py @@ -14,7 +14,7 @@ def test_01_read_dataset() -> None: def test_02_plot_feature_distribution() -> None: """Test for 02_plot_feature_distribution.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_plot_feature_distribution.py") + os.path.join(EXAMPLE_PATH, "02_plot_feature_distributions.py") ) From 4b24ed5e45b07c5c63b23626c7da1acc688022f0 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 11:56:50 +0200 Subject: [PATCH 09/21] fix unit test paths --- tests/examples/04_training/test_training_examples.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py index 3c049e6bb..086f0fed7 100644 --- a/tests/examples/04_training/test_training_examples.py +++ b/tests/examples/04_training/test_training_examples.py @@ -3,7 +3,7 @@ import os from graphnet.constants import GRAPHNET_ROOT_DIR -EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/04_data") +EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/04_training") def test_01_train_dynedge() -> None: From 6774e1e7cd9ae9125683311ec3c25434adfcdd07 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 12:11:55 +0200 Subject: [PATCH 10/21] remove _common_icetray --- examples/01_icetray/03_i3_deployer_example.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/01_icetray/03_i3_deployer_example.py b/examples/01_icetray/03_i3_deployer_example.py index 5180fc7b7..c7c5358cf 100644 --- a/examples/01_icetray/03_i3_deployer_example.py +++ b/examples/01_icetray/03_i3_deployer_example.py @@ -23,7 +23,17 @@ I3InferenceModule, ) -from _common_icetray import ERROR_MESSAGE_MISSING_ICETRAY +ERROR_MESSAGE_MISSING_ICETRAY = ( + "This example requires IceTray to be installed, which doesn't seem to be " + "the case. Please install IceTray; run this example in the GraphNeT " + "Docker container which comes with IceTray installed; or run an example " + "script in one of the other folders:" + "\n * examples/02_data/" + "\n * examples/03_weights/" + "\n * examples/04_training/" + "\n * examples/05_pisa/" + "\nExiting." +) # Constants features = FEATURES.UPGRADE From 40b36eff90b64fb65d98392751867cd166294901 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 12:12:34 +0200 Subject: [PATCH 11/21] add error message --- examples/01_icetray/01_convert_i3_files.py | 12 +++++++++++- .../04_i3_module_in_native_icetray_example.py | 12 +++++++++++- examples/01_icetray/_common_icetray.py | 11 ----------- tests/examples/01_icetray/test_icetray_examples.py | 4 +--- 4 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 examples/01_icetray/_common_icetray.py diff --git a/examples/01_icetray/01_convert_i3_files.py b/examples/01_icetray/01_convert_i3_files.py index 40b304327..9d9f80033 100644 --- a/examples/01_icetray/01_convert_i3_files.py +++ b/examples/01_icetray/01_convert_i3_files.py @@ -16,7 +16,17 @@ from graphnet.utilities.imports import has_icecube_package from graphnet.utilities.logging import Logger -from _common_icetray import ERROR_MESSAGE_MISSING_ICETRAY +ERROR_MESSAGE_MISSING_ICETRAY = ( + "This example requires IceTray to be installed, which doesn't seem to be " + "the case. Please install IceTray; run this example in the GraphNeT " + "Docker container which comes with IceTray installed; or run an example " + "script in one of the other folders:" + "\n * examples/02_data/" + "\n * examples/03_weights/" + "\n * examples/04_training/" + "\n * examples/05_pisa/" + "\nExiting." +) CONVERTER_CLASS = { "sqlite": SQLiteDataConverter, diff --git a/examples/01_icetray/04_i3_module_in_native_icetray_example.py b/examples/01_icetray/04_i3_module_in_native_icetray_example.py index 730eb5bc1..957fb108d 100644 --- a/examples/01_icetray/04_i3_module_in_native_icetray_example.py +++ b/examples/01_icetray/04_i3_module_in_native_icetray_example.py @@ -26,7 +26,17 @@ GraphNeTI3Module, ) -from _common_icetray import ERROR_MESSAGE_MISSING_ICETRAY +ERROR_MESSAGE_MISSING_ICETRAY = ( + "This example requires IceTray to be installed, which doesn't seem to be " + "the case. Please install IceTray; run this example in the GraphNeT " + "Docker container which comes with IceTray installed; or run an example " + "script in one of the other folders:" + "\n * examples/02_data/" + "\n * examples/03_weights/" + "\n * examples/04_training/" + "\n * examples/05_pisa/" + "\nExiting." +) def apply_to_files( diff --git a/examples/01_icetray/_common_icetray.py b/examples/01_icetray/_common_icetray.py deleted file mode 100644 index c1d3b10a0..000000000 --- a/examples/01_icetray/_common_icetray.py +++ /dev/null @@ -1,11 +0,0 @@ -ERROR_MESSAGE_MISSING_ICETRAY = ( - "This example requires IceTray to be installed, which doesn't seem to be " - "the case. Please install IceTray; run this example in the GraphNeT " - "Docker container which comes with IceTray installed; or run an example " - "script in one of the other folders:" - "\n * examples/02_data/" - "\n * examples/03_weights/" - "\n * examples/04_training/" - "\n * examples/05_pisa/" - "\nExiting." -) diff --git a/tests/examples/01_icetray/test_icetray_examples.py b/tests/examples/01_icetray/test_icetray_examples.py index 538a67d36..ddd99423e 100644 --- a/tests/examples/01_icetray/test_icetray_examples.py +++ b/tests/examples/01_icetray/test_icetray_examples.py @@ -26,7 +26,5 @@ def test_03_i3_deployer_example() -> None: def test_04_i3_module_in_native_icetray_example() -> None: """Test for 04_i3_module_in_native_icetray_example.""" runpy.run_path( - os.path.join( - EXAMPLE_PATH, "04_i3_module_in_naticve_icetray_example.py" - ) + os.path.join(EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py") ) From 67621c087e8a248d0db8bf6ea8cd6ba287fc36bb Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 12:17:56 +0200 Subject: [PATCH 12/21] add error message to 02 --- examples/01_icetray/02_compare_sqlite_and_parquet.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/01_icetray/02_compare_sqlite_and_parquet.py b/examples/01_icetray/02_compare_sqlite_and_parquet.py index 91bbe6f1d..75d6c18ba 100644 --- a/examples/01_icetray/02_compare_sqlite_and_parquet.py +++ b/examples/01_icetray/02_compare_sqlite_and_parquet.py @@ -16,7 +16,17 @@ from graphnet.utilities.imports import has_icecube_package from graphnet.utilities.logging import Logger -from _common_icetray import ERROR_MESSAGE_MISSING_ICETRAY +ERROR_MESSAGE_MISSING_ICETRAY = ( + "This example requires IceTray to be installed, which doesn't seem to be " + "the case. Please install IceTray; run this example in the GraphNeT " + "Docker container which comes with IceTray installed; or run an example " + "script in one of the other folders:" + "\n * examples/02_data/" + "\n * examples/03_weights/" + "\n * examples/04_training/" + "\n * examples/05_pisa/" + "\nExiting." +) OUTPUT_DIR = f"{EXAMPLE_OUTPUT_DIR}/compare_sqlite_and_parquet" PULSEMAP = "SRTInIcePulses" From 9d2eb14695965569cede9fc4d4cb5b8270320cbb Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 12:29:13 +0200 Subject: [PATCH 13/21] add func calls to new unit tests --- tests/examples/01_icetray/test_icetray_examples.py | 7 +++++++ tests/examples/02_data/test_data_examples.py | 7 +++++++ tests/examples/03_weights/test_weights_examples.py | 5 +++++ tests/examples/04_training/test_training_examples.py | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/tests/examples/01_icetray/test_icetray_examples.py b/tests/examples/01_icetray/test_icetray_examples.py index ddd99423e..613e90bf9 100644 --- a/tests/examples/01_icetray/test_icetray_examples.py +++ b/tests/examples/01_icetray/test_icetray_examples.py @@ -28,3 +28,10 @@ def test_04_i3_module_in_native_icetray_example() -> None: runpy.run_path( os.path.join(EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py") ) + + +if __name__ == "__main__": + test_01_convert_i3_files() + test_02_compare_sqlite_and_parquet() + test_03_i3_deployer_example() + test_04_i3_module_in_native_icetray_example() diff --git a/tests/examples/02_data/test_data_examples.py b/tests/examples/02_data/test_data_examples.py index 2d076151a..434e60e23 100644 --- a/tests/examples/02_data/test_data_examples.py +++ b/tests/examples/02_data/test_data_examples.py @@ -28,3 +28,10 @@ def test_03_convert_parquet_to_sqlite() -> None: def test_04_ensemble_dataset() -> None: """Test for 04_ensemble_dataset.""" runpy.run_path(os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py")) + + +if __name__ == "__main__": + test_01_read_dataset() + test_02_plot_feature_distribution() + test_03_convert_parquet_to_sqlite() + test_04_ensemble_dataset() diff --git a/tests/examples/03_weights/test_weights_examples.py b/tests/examples/03_weights/test_weights_examples.py index 8715fefc6..a810d0236 100644 --- a/tests/examples/03_weights/test_weights_examples.py +++ b/tests/examples/03_weights/test_weights_examples.py @@ -14,3 +14,8 @@ def test_01_fit_uniform_weights() -> None: def test_02_fit_bjoern_low_weights() -> None: """Test for 02_fit_bjoern_low_weights.""" runpy.run_path(os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py")) + + +if __name__ == "__main__": + test_01_fit_uniform_weights() + test_02_fit_bjoern_low_weights() diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py index 086f0fed7..0fbaee52c 100644 --- a/tests/examples/04_training/test_training_examples.py +++ b/tests/examples/04_training/test_training_examples.py @@ -28,3 +28,10 @@ def test_04_train_multiclassifier_from_configs() -> None: runpy.run_path( os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py") ) + + +if __name__ == "__main__": + test_01_train_dynedge() + test_02_train_tito_model() + test_03_train_dynedge_from_config() + test_04_train_multiclassifier_from_configs() From 1ca3e879421e6a11193570da2b996ed849170423 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 12:48:45 +0200 Subject: [PATCH 14/21] set run_name to __main__ for runpy --- .../01_icetray/test_icetray_examples.py | 18 ++++++++++++++---- tests/examples/02_data/test_data_examples.py | 15 +++++++++++---- .../03_weights/test_weights_examples.py | 10 ++++++++-- .../04_training/test_training_examples.py | 15 +++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/tests/examples/01_icetray/test_icetray_examples.py b/tests/examples/01_icetray/test_icetray_examples.py index 613e90bf9..630f43f6f 100644 --- a/tests/examples/01_icetray/test_icetray_examples.py +++ b/tests/examples/01_icetray/test_icetray_examples.py @@ -8,25 +8,35 @@ def test_01_convert_i3_files() -> None: """Test for 01_convert_i3_files.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "01_convert_i3_files.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "01_convert_i3_files.py"), + run_name="__main__", + ) def test_02_compare_sqlite_and_parquet() -> None: """Test for 02_compare_sqlite_and_parquet.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_compare_sqlite_and_parquet.py") + os.path.join(EXAMPLE_PATH, "02_compare_sqlite_and_parquet.py"), + run_name="__main__", ) def test_03_i3_deployer_example() -> None: """Test for 03_i3_deployer_example.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "03_i3_deployer_example.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "03_i3_deployer_example.py"), + run_name="__main__", + ) def test_04_i3_module_in_native_icetray_example() -> None: """Test for 04_i3_module_in_native_icetray_example.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py") + os.path.join( + EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py" + ), + run_name="__main__", ) diff --git a/tests/examples/02_data/test_data_examples.py b/tests/examples/02_data/test_data_examples.py index 434e60e23..4e1a9b40e 100644 --- a/tests/examples/02_data/test_data_examples.py +++ b/tests/examples/02_data/test_data_examples.py @@ -8,26 +8,33 @@ def test_01_read_dataset() -> None: """Test for 01_read_dataset.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "01_read_dataset.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "01_read_dataset.py"), run_name="__main__" + ) def test_02_plot_feature_distribution() -> None: """Test for 02_plot_feature_distribution.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_plot_feature_distributions.py") + os.path.join(EXAMPLE_PATH, "02_plot_feature_distributions.py"), + run_name="__main__", ) def test_03_convert_parquet_to_sqlite() -> None: """Test for 03_convert_parquet_to_sqlite.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "03_convert_parquet_to_sqlite.py") + os.path.join(EXAMPLE_PATH, "03_convert_parquet_to_sqlite.py"), + run_name="__main__", ) def test_04_ensemble_dataset() -> None: """Test for 04_ensemble_dataset.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py"), + run_name="__main__", + ) if __name__ == "__main__": diff --git a/tests/examples/03_weights/test_weights_examples.py b/tests/examples/03_weights/test_weights_examples.py index a810d0236..7ab580502 100644 --- a/tests/examples/03_weights/test_weights_examples.py +++ b/tests/examples/03_weights/test_weights_examples.py @@ -8,12 +8,18 @@ def test_01_fit_uniform_weights() -> None: """Test for 01_fit_uniform_weights.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "01_fit_uniform_weights.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "01_fit_uniform_weights.py"), + run_name="__main__", + ) def test_02_fit_bjoern_low_weights() -> None: """Test for 02_fit_bjoern_low_weights.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py"), + run_name="__main__", + ) if __name__ == "__main__": diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py index 0fbaee52c..4df5ba636 100644 --- a/tests/examples/04_training/test_training_examples.py +++ b/tests/examples/04_training/test_training_examples.py @@ -8,25 +8,32 @@ def test_01_train_dynedge() -> None: """Test for 01_train_dynedge.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "01_train_dynedge.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "01_train_dynedge.py"), run_name="__main__" + ) def test_02_train_tito_model() -> None: """Test for 02_train_tito_model.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, "02_train_tito_model.py")) + runpy.run_path( + os.path.join(EXAMPLE_PATH, "02_train_tito_model.py"), + run_name="__main__", + ) def test_03_train_dynedge_from_config() -> None: """Test for 03_train_dynedge_from_config.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "03_train_dynedge_from_config.py") + os.path.join(EXAMPLE_PATH, "03_train_dynedge_from_config.py"), + run_name="__main__", ) def test_04_train_multiclassifier_from_configs() -> None: """Test for 04_train_multiclassifier_from_configs.""" runpy.run_path( - os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py") + os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py"), + run_name="__main__", ) From 2b22ce78bc8f82990bfd2c27c22932b8cbdc3faa Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 13:23:46 +0200 Subject: [PATCH 15/21] simplify unit tests --- .../01_icetray/test_icetray_examples.py | 46 ++++--------------- tests/examples/02_data/test_data_examples.py | 44 ++++-------------- .../03_weights/test_weights_examples.py | 25 +++------- .../04_training/test_training_examples.py | 42 ++++------------- 4 files changed, 31 insertions(+), 126 deletions(-) diff --git a/tests/examples/01_icetray/test_icetray_examples.py b/tests/examples/01_icetray/test_icetray_examples.py index 630f43f6f..cbdf470fd 100644 --- a/tests/examples/01_icetray/test_icetray_examples.py +++ b/tests/examples/01_icetray/test_icetray_examples.py @@ -1,47 +1,17 @@ """Test for examples in 01_icetray.""" import runpy import os +import pytest +from glob import glob + from graphnet.constants import GRAPHNET_ROOT_DIR EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/01_icetray") - -def test_01_convert_i3_files() -> None: - """Test for 01_convert_i3_files.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "01_convert_i3_files.py"), - run_name="__main__", - ) - - -def test_02_compare_sqlite_and_parquet() -> None: - """Test for 02_compare_sqlite_and_parquet.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_compare_sqlite_and_parquet.py"), - run_name="__main__", - ) - - -def test_03_i3_deployer_example() -> None: - """Test for 03_i3_deployer_example.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "03_i3_deployer_example.py"), - run_name="__main__", - ) - - -def test_04_i3_module_in_native_icetray_example() -> None: - """Test for 04_i3_module_in_native_icetray_example.""" - runpy.run_path( - os.path.join( - EXAMPLE_PATH, "04_i3_module_in_native_icetray_example.py" - ), - run_name="__main__", - ) +examples = glob(EXAMPLE_PATH + "/*.py") -if __name__ == "__main__": - test_01_convert_i3_files() - test_02_compare_sqlite_and_parquet() - test_03_i3_deployer_example() - test_04_i3_module_in_native_icetray_example() +@pytest.mark.parametrize("example", examples) +def test_script_execution(example: str) -> None: + """Test function that executes example.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, example)) diff --git a/tests/examples/02_data/test_data_examples.py b/tests/examples/02_data/test_data_examples.py index 4e1a9b40e..8faaca5c0 100644 --- a/tests/examples/02_data/test_data_examples.py +++ b/tests/examples/02_data/test_data_examples.py @@ -1,44 +1,16 @@ """Tests for examples in 02_data.""" import runpy import os +import pytest +from glob import glob + from graphnet.constants import GRAPHNET_ROOT_DIR EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/02_data") +examples = glob(EXAMPLE_PATH + "/*.py") -def test_01_read_dataset() -> None: - """Test for 01_read_dataset.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "01_read_dataset.py"), run_name="__main__" - ) - - -def test_02_plot_feature_distribution() -> None: - """Test for 02_plot_feature_distribution.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_plot_feature_distributions.py"), - run_name="__main__", - ) - - -def test_03_convert_parquet_to_sqlite() -> None: - """Test for 03_convert_parquet_to_sqlite.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "03_convert_parquet_to_sqlite.py"), - run_name="__main__", - ) - - -def test_04_ensemble_dataset() -> None: - """Test for 04_ensemble_dataset.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "04_ensemble_dataset.py"), - run_name="__main__", - ) - - -if __name__ == "__main__": - test_01_read_dataset() - test_02_plot_feature_distribution() - test_03_convert_parquet_to_sqlite() - test_04_ensemble_dataset() +@pytest.mark.parametrize("example", examples) +def test_script_execution(example: str) -> None: + """Test function that executes example.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, example)) diff --git a/tests/examples/03_weights/test_weights_examples.py b/tests/examples/03_weights/test_weights_examples.py index 7ab580502..5dddee264 100644 --- a/tests/examples/03_weights/test_weights_examples.py +++ b/tests/examples/03_weights/test_weights_examples.py @@ -2,26 +2,15 @@ import runpy import os from graphnet.constants import GRAPHNET_ROOT_DIR +from glob import glob +import pytest EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/03_weights") +examples = glob(EXAMPLE_PATH + "/*.py") -def test_01_fit_uniform_weights() -> None: - """Test for 01_fit_uniform_weights.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "01_fit_uniform_weights.py"), - run_name="__main__", - ) - -def test_02_fit_bjoern_low_weights() -> None: - """Test for 02_fit_bjoern_low_weights.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_fit_bjoern_low_weights.py"), - run_name="__main__", - ) - - -if __name__ == "__main__": - test_01_fit_uniform_weights() - test_02_fit_bjoern_low_weights() +@pytest.mark.parametrize("example", examples) +def test_script_execution(example: str) -> None: + """Test function that executes example.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, example)) diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py index 4df5ba636..87cb955e4 100644 --- a/tests/examples/04_training/test_training_examples.py +++ b/tests/examples/04_training/test_training_examples.py @@ -1,44 +1,18 @@ """Test for examples in 04_training.""" import runpy import os +from glob import glob +import pytest + from graphnet.constants import GRAPHNET_ROOT_DIR EXAMPLE_PATH = os.path.join(GRAPHNET_ROOT_DIR, "examples/04_training") -def test_01_train_dynedge() -> None: - """Test for 01_train_dynedge.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "01_train_dynedge.py"), run_name="__main__" - ) - - -def test_02_train_tito_model() -> None: - """Test for 02_train_tito_model.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "02_train_tito_model.py"), - run_name="__main__", - ) - - -def test_03_train_dynedge_from_config() -> None: - """Test for 03_train_dynedge_from_config.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "03_train_dynedge_from_config.py"), - run_name="__main__", - ) - - -def test_04_train_multiclassifier_from_configs() -> None: - """Test for 04_train_multiclassifier_from_configs.""" - runpy.run_path( - os.path.join(EXAMPLE_PATH, "04_train_multiclassifier_from_configs.py"), - run_name="__main__", - ) +examples = glob(EXAMPLE_PATH + "/*.py") -if __name__ == "__main__": - test_01_train_dynedge() - test_02_train_tito_model() - test_03_train_dynedge_from_config() - test_04_train_multiclassifier_from_configs() +@pytest.mark.parametrize("example", examples) +def test_script_execution(example: str) -> None: + """Test function that executes example.""" + runpy.run_path(os.path.join(EXAMPLE_PATH, example)) From d3e34fd96a78ddf3be9f36868361cf532179aeb9 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 13:57:06 +0200 Subject: [PATCH 16/21] parse only known args in examples --- examples/01_icetray/01_convert_i3_files.py | 2 +- examples/01_icetray/02_compare_sqlite_and_parquet.py | 2 +- examples/01_icetray/03_i3_deployer_example.py | 2 +- examples/01_icetray/04_i3_module_in_native_icetray_example.py | 2 +- examples/02_data/01_read_dataset.py | 2 +- examples/02_data/02_plot_feature_distributions.py | 2 +- examples/02_data/03_convert_parquet_to_sqlite.py | 2 +- examples/02_data/04_ensemble_dataset.py | 1 + examples/03_weights/01_fit_uniform_weights.py | 2 +- examples/03_weights/02_fit_bjoern_low_weights.py | 2 +- examples/04_training/01_train_dynedge.py | 2 +- examples/04_training/02_train_tito_model.py | 2 +- examples/04_training/03_train_dynedge_from_config.py | 2 +- examples/04_training/04_train_multiclassifier_from_configs.py | 2 +- tests/examples/04_training/test_training_examples.py | 2 +- 15 files changed, 15 insertions(+), 14 deletions(-) diff --git a/examples/01_icetray/01_convert_i3_files.py b/examples/01_icetray/01_convert_i3_files.py index 9d9f80033..88dcf714a 100644 --- a/examples/01_icetray/01_convert_i3_files.py +++ b/examples/01_icetray/01_convert_i3_files.py @@ -99,7 +99,7 @@ def main_icecube_upgrade(backend: str) -> None: "detector", choices=["icecube-86", "icecube-upgrade"] ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() # Run example script if args.detector == "icecube-86": diff --git a/examples/01_icetray/02_compare_sqlite_and_parquet.py b/examples/01_icetray/02_compare_sqlite_and_parquet.py index 75d6c18ba..99250d4b0 100644 --- a/examples/01_icetray/02_compare_sqlite_and_parquet.py +++ b/examples/01_icetray/02_compare_sqlite_and_parquet.py @@ -95,7 +95,7 @@ def load_data() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() # Run example script(s) convert_data() diff --git a/examples/01_icetray/03_i3_deployer_example.py b/examples/01_icetray/03_i3_deployer_example.py index c7c5358cf..f55aa769c 100644 --- a/examples/01_icetray/03_i3_deployer_example.py +++ b/examples/01_icetray/03_i3_deployer_example.py @@ -93,7 +93,7 @@ def main() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() # Run example script main() diff --git a/examples/01_icetray/04_i3_module_in_native_icetray_example.py b/examples/01_icetray/04_i3_module_in_native_icetray_example.py index 957fb108d..74da5e499 100644 --- a/examples/01_icetray/04_i3_module_in_native_icetray_example.py +++ b/examples/01_icetray/04_i3_module_in_native_icetray_example.py @@ -126,7 +126,7 @@ def main() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() # Run example script main() diff --git a/examples/02_data/01_read_dataset.py b/examples/02_data/01_read_dataset.py index de8fecb18..77d7c1438 100644 --- a/examples/02_data/01_read_dataset.py +++ b/examples/02_data/01_read_dataset.py @@ -121,6 +121,6 @@ def main(backend: str) -> None: nargs="?", ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main(args.backend) diff --git a/examples/02_data/02_plot_feature_distributions.py b/examples/02_data/02_plot_feature_distributions.py index b46be0623..ac08ae9fb 100644 --- a/examples/02_data/02_plot_feature_distributions.py +++ b/examples/02_data/02_plot_feature_distributions.py @@ -66,6 +66,6 @@ def main() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main() diff --git a/examples/02_data/03_convert_parquet_to_sqlite.py b/examples/02_data/03_convert_parquet_to_sqlite.py index 12a33d181..5757bb5c9 100644 --- a/examples/02_data/03_convert_parquet_to_sqlite.py +++ b/examples/02_data/03_convert_parquet_to_sqlite.py @@ -57,6 +57,6 @@ def main(parquet_path: str, mc_truth_table: str) -> None: default="truth", ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main(args.parquet_path, args.mc_truth_table) diff --git a/examples/02_data/04_ensemble_dataset.py b/examples/02_data/04_ensemble_dataset.py index 13998c3e7..f1cc9de68 100644 --- a/examples/02_data/04_ensemble_dataset.py +++ b/examples/02_data/04_ensemble_dataset.py @@ -88,4 +88,5 @@ def main() -> None: Combine multiple Datasets using EnsembleDataset. """ ) + args, unknown = parser.parse_known_args() main() diff --git a/examples/03_weights/01_fit_uniform_weights.py b/examples/03_weights/01_fit_uniform_weights.py index 629e8497b..e2f68487a 100644 --- a/examples/03_weights/01_fit_uniform_weights.py +++ b/examples/03_weights/01_fit_uniform_weights.py @@ -37,6 +37,6 @@ def main() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main() diff --git a/examples/03_weights/02_fit_bjoern_low_weights.py b/examples/03_weights/02_fit_bjoern_low_weights.py index cde075812..4d54e8c7d 100644 --- a/examples/03_weights/02_fit_bjoern_low_weights.py +++ b/examples/03_weights/02_fit_bjoern_low_weights.py @@ -45,6 +45,6 @@ def main() -> None: """ ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main() diff --git a/examples/04_training/01_train_dynedge.py b/examples/04_training/01_train_dynedge.py index f9af11998..7cde873b2 100644 --- a/examples/04_training/01_train_dynedge.py +++ b/examples/04_training/01_train_dynedge.py @@ -225,7 +225,7 @@ def main( help="If True, Weights & Biases are used to track the experiment.", ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main( args.path, diff --git a/examples/04_training/02_train_tito_model.py b/examples/04_training/02_train_tito_model.py index f3d60d553..735dea055 100644 --- a/examples/04_training/02_train_tito_model.py +++ b/examples/04_training/02_train_tito_model.py @@ -235,7 +235,7 @@ def main( help="If True, Weights & Biases are used to track the experiment.", ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main( args.path, diff --git a/examples/04_training/03_train_dynedge_from_config.py b/examples/04_training/03_train_dynedge_from_config.py index 1dec95961..4b4db17f8 100644 --- a/examples/04_training/03_train_dynedge_from_config.py +++ b/examples/04_training/03_train_dynedge_from_config.py @@ -157,7 +157,7 @@ def main( help="If True, Weights & Biases are used to track the experiment.", ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main( args.dataset_config, diff --git a/examples/04_training/04_train_multiclassifier_from_configs.py b/examples/04_training/04_train_multiclassifier_from_configs.py index 6385c010c..e71813b24 100644 --- a/examples/04_training/04_train_multiclassifier_from_configs.py +++ b/examples/04_training/04_train_multiclassifier_from_configs.py @@ -188,7 +188,7 @@ def main( default=None, ) - args = parser.parse_args() + args, unknown = parser.parse_known_args() main( args.dataset_config, diff --git a/tests/examples/04_training/test_training_examples.py b/tests/examples/04_training/test_training_examples.py index 87cb955e4..e97b4bb3c 100644 --- a/tests/examples/04_training/test_training_examples.py +++ b/tests/examples/04_training/test_training_examples.py @@ -15,4 +15,4 @@ @pytest.mark.parametrize("example", examples) def test_script_execution(example: str) -> None: """Test function that executes example.""" - runpy.run_path(os.path.join(EXAMPLE_PATH, example)) + runpy.run_path(os.path.join(EXAMPLE_PATH, example), run_name="__main__") From 6e1cf3c8959b459fe0495caee6cf9c1a901cf4b6 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 14:17:50 +0200 Subject: [PATCH 17/21] fix multiclassification config --- configs/models/dynedge_PID_classification_example.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/configs/models/dynedge_PID_classification_example.yml b/configs/models/dynedge_PID_classification_example.yml index 4b2fd0246..57fec3e88 100644 --- a/configs/models/dynedge_PID_classification_example.yml +++ b/configs/models/dynedge_PID_classification_example.yml @@ -38,6 +38,7 @@ arguments: - ModelConfig: arguments: nb_outputs: 3 # number of classes + prediction_labels: ['noise', 'muon', 'neutrino'] hidden_size: 128 loss_function: ModelConfig: From 4376fb049b406434c20f233c3973a75d2f01b55e Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 14:25:58 +0200 Subject: [PATCH 18/21] Comment out save_config statement in 02_train_tito --- examples/04_training/02_train_tito_model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/04_training/02_train_tito_model.py b/examples/04_training/02_train_tito_model.py index 735dea055..f586b0581 100644 --- a/examples/04_training/02_train_tito_model.py +++ b/examples/04_training/02_train_tito_model.py @@ -182,7 +182,8 @@ def main( # Save model config and state dict - Version safe save method. model.save_state_dict(f"{path}/state_dict.pth") - model.save_config(f"{path}/model_config.yml") + # model.save_config(f"{path}/model_config.yml") + # Pending https://github.com/graphnet-team/graphnet/issues/606 if __name__ == "__main__": From 123831a17c5c3c86dc37349bcb042ecb493cdb33 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 14:50:57 +0200 Subject: [PATCH 19/21] seperate coverage run for utilities --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6998ce22f..988f6a4e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,7 +55,8 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest tests/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities + coverage run --source=graphnet -m pytest tests/utilities coverage xml -o coverage.xml - name: Work around permission issue run: | @@ -88,7 +89,8 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ + coverage run --source=graphnet -m pytest tests/utilities coverage report -m build-macos: @@ -108,5 +110,6 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/01_icetray/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ + coverage run --source=graphnet -m pytest tests/utilities coverage report -m From 9f912a682c83fb487e96edfe8a14883dff3c003f Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 15:08:50 +0200 Subject: [PATCH 20/21] change run priorities --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 988f6a4e9..465c1bc1b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -55,8 +55,8 @@ jobs: editable: true - name: Run unit tests and generate coverage report run: | - coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities - coverage run --source=graphnet -m pytest tests/utilities + coverage run --source=graphnet -m pytest tests/ --ignore=tests/examples + coverage run --source=graphnet -m pytest tests/examples/01_icetray coverage xml -o coverage.xml - name: Work around permission issue run: | @@ -89,7 +89,7 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/01_icetray/ coverage run --source=graphnet -m pytest tests/utilities coverage report -m @@ -110,6 +110,6 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/01_icetray/ + coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/01_icetray/ coverage run --source=graphnet -m pytest tests/utilities coverage report -m From 5a5317bc21868d2ceaf318fb8be22b6c561b6138 Mon Sep 17 00:00:00 2001 From: Rasmus Oersoe Date: Tue, 26 Sep 2023 15:43:49 +0200 Subject: [PATCH 21/21] remove unit tests of examples for macos. --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 465c1bc1b..001b8bed4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -110,6 +110,5 @@ jobs: - name: Run unit tests and generate coverage report run: | set -o pipefail # To propagate exit code from pytest - coverage run --source=graphnet -m pytest tests/ --ignore=tests/utilities --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/01_icetray/ - coverage run --source=graphnet -m pytest tests/utilities + coverage run --source=graphnet -m pytest tests/ --ignore=tests/data/ --ignore=tests/deployment/ --ignore=tests/examples/ coverage report -m