diff --git a/src/anemoi/registry/entry/experiment.py b/src/anemoi/registry/entry/experiment.py index 56481c1..456f8c5 100644 --- a/src/anemoi/registry/entry/experiment.py +++ b/src/anemoi/registry/entry/experiment.py @@ -66,7 +66,7 @@ def _add_one_plot_or_artefact(self, kind, path, **kwargs): upload(path, target, overwrite=True) dic = dict(url=target, name=basename, path=path) - self.rest_item.patch([{"op": "add", "path": "/{kind}s/-", "value": dic}]) + self.rest_item.patch([{"op": "add", "path": f"/{kind}s/-", "value": dic}]) def _add_one_weights(self, path, **kwargs): weights = WeightCatalogueEntry(path=path) diff --git a/tests/dataset_recipe.yaml b/tests/dataset_recipe.yaml new file mode 100644 index 0000000..6e96a27 --- /dev/null +++ b/tests/dataset_recipe.yaml @@ -0,0 +1,43 @@ +common: + mars_request: &mars_request + expver: "0001" + class: ea + grid: 20./20. + +dates: + start: 2020-12-30 00:00:00 + end: 2021-01-03 12:00:00 + frequency: 12h + +input: + join: + - mars: + <<: *mars_request + param: [2t] + levtype: sfc + stream: oper + type: an + + - mars: + <<: *mars_request + param: [q, t] + levtype: pl + level: [50, 100] + stream: oper + type: an + + - accumulations: + <<: *mars_request + levtype: sfc + param: [cp, tp] + # accumulation_period: 6h + + - forcings: + template: ${input.join.0.mars} + param: + - cos_latitude + +naming_scheme: "{param}_{levelist}{level_units}_{accumultion_period}" + +statistics: + end: 2021 diff --git a/tests/test_all.py b/tests/test_all.py new file mode 100644 index 0000000..90b6099 --- /dev/null +++ b/tests/test_all.py @@ -0,0 +1,78 @@ +import os +import subprocess + +TEST_DATASET_INPUT = "aifs-ea-an-oper-0001-mars-20p0-1979-1979-6h-v0-testing" + +pid = os.getpid() +TMP_DATASET = f"{TEST_DATASET_INPUT}-{pid}" + +TMP_DATASET_PATH = f"./data/{TMP_DATASET}.zarr" + + +def run(*args): + print(" ".join(args)) + try: + subprocess.check_call(args) + except Exception as e: + e.add_note = f"Command failed: {' '.join(args)}" + + raise + + +def setup_module(): + run("anemoi-datasets", "create", "dataset_recipe.yaml", TMP_DATASET_PATH, "--overwrite") + assert os.path.exists(TMP_DATASET_PATH) + + +# def teardown_module(): +# run("anemoi-registry", "datasets", TMP_DATASET, "--unregister") +# os.remove(TMP_DATASET_PATH) + + +def test_datasets(): + run("anemoi-registry", "datasets", TMP_DATASET_PATH, "--register") + # assert run("anemoi-registry", "datasets", TMP_DATASET) == 1 + run("anemoi-registry", "datasets", TMP_DATASET) + run("anemoi-registry", "datasets", TMP_DATASET, "--add-recipe", "./data/recipe.yaml") + run("anemoi-registry", "datasets", TMP_DATASET, "--set-status", "testing") + run("anemoi-registry", "datasets", TMP_DATASET, "--add-location", "/the/dataset/path", "--platform", "atos") + run( + "anemoi-registry", + "datasets", + TMP_DATASET, + "--add-location", + "/the/dataset/path/other", + "--platform", + "leonardo", + ) + + +def test_weights(): + run("anemoi-registry", "weights", "a5275e04-0000-0000-a0f6-be19591b09fe", "--unregister") + # assert run("anemoi-registry", "weights", "a5275e04-0000-0000-a0f6-be19591b09fe") == 1 + run("anemoi-registry", "weights", "./data/test-checkpoint.ckpt", "--register") + run("anemoi-registry", "weights", "a5275e04-0000-0000-a0f6-be19591b09fe") + run( + "anemoi-registry", + "weights", + "./data/test-checkpoint.ckpt", + "--add-location", + "s3://ml-weights/a5275e04-0000-0000-a0f6-be19591b09fe.ckpt", + "--platform", + "ewc", + ) + + +def test_experiments(): + run("anemoi-registry", "experiments", "./data/config.yaml", "--unregister") + # assert run("anemoi-registry", "experiments", "i4df") == 1 + run("anemoi-registry", "experiments", "./data/config.yaml", "--register") + run("anemoi-registry", "experiments", "i4df") + run("anemoi-registry", "experiments", "i4df", "--add-plots", "./data/quaver.pdf") + run("anemoi-registry", "experiments", "i4df", "--add-weights", "./data/test-checkpoint.ckpt") + + +def test_list_commands(): + run("anemoi-registry", "list", "experiments", ">", "e.txt") + run("anemoi-registry", "list", "weights", ">", "w.txt") + run("anemoi-registry", "list", "datasets", ">", "d.txt")