Skip to content

Commit 531e2ad

Browse files
b8raoultHCookie
andauthored
feat: plugin support (#187)
Support plugins in inference Co-authored-by: Harrison Cook <[email protected]>
1 parent f444c52 commit 531e2ad

File tree

10 files changed

+47
-78
lines changed

10 files changed

+47
-78
lines changed

docs/conf.py

+11
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112
"https://anemoi-transform.readthedocs.io/en/latest/",
113113
("../../anemoi-transform/docs/_build/html/objects.inv", None),
114114
),
115+
"anemoi-plugins": (
116+
"https://anemoi-plugins.readthedocs.io/en/latest/",
117+
("../../anemoi-plugins/docs/_build/html/objects.inv", None),
118+
),
115119
}
116120

117121

@@ -148,3 +152,10 @@
148152
autodoc_pydantic_model_show_json = True
149153
autodoc_pydantic_model_show_field_summary = False
150154
autodoc_pydantic_model_member_order = "bysource"
155+
156+
html_context = {
157+
"display_github": True,
158+
"github_user": "ecmwf",
159+
"github_repo": "anemoi-inference",
160+
"github_version": "main/docs/",
161+
}

docs/index.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ You may also have to install pandoc on MacOS:
8484
8585
brew install pandoc
8686
87-
*****************
88-
Anemoi packages
89-
*****************
87+
***********************
88+
Other Anemoi packages
89+
***********************
9090

9191
- :ref:`anemoi-utils <anemoi-utils:index-page>`
9292
- :ref:`anemoi-transform <anemoi-transform:index-page>`
@@ -96,6 +96,7 @@ You may also have to install pandoc on MacOS:
9696
- :ref:`anemoi-training <anemoi-training:index-page>`
9797
- :ref:`anemoi-inference <anemoi-inference:index-page>`
9898
- :ref:`anemoi-registry <anemoi-registry:index-page>`
99+
- :ref:`anemoi-plugins <anemoi-plugins:index-page>`
99100

100101
*********
101102
License

pyproject.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
# nor does it submit to any jurisdiction.
99

1010
[build-system]
11+
build-backend = "setuptools.build_meta"
12+
1113
requires = [ "setuptools>=60", "setuptools-scm>=8" ]
1214

1315
[project]
@@ -42,7 +44,7 @@ classifiers = [
4244

4345
dynamic = [ "version" ]
4446
dependencies = [
45-
"anemoi-transform>=0.1.3",
47+
"anemoi-transform>=0.1.4",
4648
"anemoi-utils[text,provenance]>=0.4.16",
4749
"aniso8601",
4850
"anytree",
@@ -86,9 +88,18 @@ entry-points."ai_models.model".anemoi = "anemoi.inference.plugin:AIModelPlugin"
8688
[tool.setuptools.package-data]
8789
"anemoi.inference.grib.templates" = [ "*.yaml" ]
8890

91+
[tool.setuptools.packages.find]
92+
where = [ "src" ]
93+
8994
[tool.setuptools_scm]
9095
version_file = "src/anemoi/inference/_version.py"
9196

97+
[tool.pytest.ini_options]
98+
markers = [
99+
"skip_on_hpc: mark a test that should not be run on HPC",
100+
]
101+
testpaths = "tests"
102+
92103
[tool.mypy]
93104
exclude = [ "docs/" ]
94105
strict = false

src/anemoi/inference/post_processors/backward_transform_filter.py

+4
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@
1414
from anemoi.transform.filters import filter_registry
1515

1616
from anemoi.inference.context import Context
17+
from anemoi.inference.decorators import main_argument
1718
from anemoi.inference.types import State
1819

1920
from ..processor import Processor
21+
from . import post_processor_registry
2022
from .earthkit_state import unwrap_state
2123
from .earthkit_state import wrap_state
2224

2325
LOG = logging.getLogger(__name__)
2426

2527

28+
@post_processor_registry.register("backward_transform_filter")
29+
@main_argument("filter")
2630
class BackwardTransformFilter(Processor):
2731
"""A processor that applies a backward transform filter to a given state.
2832

src/anemoi/inference/post_processors/cos_sin_mean_wave_direction.py

-36
This file was deleted.

src/anemoi/inference/pre_processors/cos_sin_mean_wave_direction.py

-36
This file was deleted.

src/anemoi/inference/pre_processors/forward_transform_filter.py

+5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@
1414
import earthkit.data as ekd
1515
from anemoi.transform.filters import filter_registry
1616

17+
from anemoi.inference.decorators import main_argument
18+
1719
from ..processor import Processor
20+
from . import pre_processor_registry
1821

1922
LOG = logging.getLogger(__name__)
2023

2124

25+
@pre_processor_registry.register("forward_transform_filter")
26+
@main_argument("filter")
2227
class ForwardTransformFilter(Processor):
2328
"""A processor that applies a forward transform filter to the given fields.
2429

src/anemoi/inference/testing/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ def files_for_tests(name: str) -> str:
100100
bits.append("tests")
101101
bits.append(name)
102102
return os.path.sep.join(bits)
103+
104+
105+
class TestingContext:
106+
"""A context for testing plugins."""
107+
108+
pass

tests/configs/mwd.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ lead_time: 48
66
report_error: true
77

88
pre_processors:
9-
- cos_sin_mean_wave_direction
9+
- forward_transform_filter: cos_sin_mean_wave_direction
1010
- no_missing_values
1111

1212
post_processors:
13-
- cos_sin_mean_wave_direction
13+
- backward_transform_filter: cos_sin_mean_wave_direction
14+
1415

1516
use_grib_paramid: true

tests/test_inference.py

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def test_inference_mwd() -> None:
4747

4848
if __name__ == "__main__":
4949
logging.basicConfig(level=logging.INFO)
50+
test_inference_mwd()
51+
exit(0)
5052
for name, obj in list(globals().items()):
5153
if name.startswith("test_") and callable(obj):
5254
print(f"Running {name}...")

0 commit comments

Comments
 (0)