Skip to content

Commit

Permalink
commit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankrb committed Jul 10, 2024
1 parent cc68fdf commit 5e505f9
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/anemoi/registry/entry/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions tests/dataset_recipe.yaml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 5e505f9

Please sign in to comment.