Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): Add accumulate_from_start_of_forecast post-processor #133

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/anemoi/inference/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
from typing import Any
from typing import Dict
from typing import List
from typing import Literal
from typing import Optional
from typing import Union
Expand Down Expand Up @@ -59,6 +60,9 @@ class Config:
input: Union[str, Dict, None] = "test"
output: Union[str, Dict, None] = "printer"

pre_processors: List[Union[str, Dict]] = []
post_processors: Optional[List[Union[str, Dict]]] = None # TODO: change default to [] when we have a factory

forcings: Union[Dict[str, Dict], None] = None
"""Where to find the forcings."""

Expand Down
2 changes: 1 addition & 1 deletion src/anemoi/inference/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __init__(
self,
checkpoint,
*,
accumulations=True,
accumulations=False,
device: str = "cuda",
precision: str = None,
report_error=False,
Expand Down
33 changes: 33 additions & 0 deletions src/anemoi/inference/runners/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


import logging
import warnings

from anemoi.utils.config import DotDict
from pydantic import BaseModel
Expand Down Expand Up @@ -40,6 +41,37 @@ def __init__(self, config):

self.config = config

# TODO #131: Remove this when we have a processor factory
# For now, implement a three-way switch.
# post_processors: None -> accumulate_from_start_of_forecast = True
# post_processors: [] -> accumulate_from_start_of_forecast = False
# post_processors: ["accumulate_from_start_of_forecast"] -> accumulate_from_start_of_forecast = True
post_processors = config.get("post_processors")

if isinstance(post_processors, list):
accumulate_from_start_of_forecast = "accumulate_from_start_of_forecast" in post_processors

if not accumulate_from_start_of_forecast:
warnings.warn(
"""
post_processors are defined but `accumulate_from_start_of_forecast` is not set."
🚧 Accumulations will NOT be accumulated from the beginning of the forecast. 🚧
"""
)
else:
warnings.warn(
"""
No post_processors defined. Accumulations will be accumulated from the beginning of the forecast.

🚧🚧🚧 In a future release, the default will be to NOT accumulate from the beginning of the forecast. 🚧🚧🚧
Update your config if you wish to keep accumulating from the beginning.
https://github.com/ecmwf/anemoi-inference/issues/131
""",
)
accumulate_from_start_of_forecast = True

LOG.info("accumulate_from_start_of_forecast: %s", accumulate_from_start_of_forecast)

super().__init__(
config.checkpoint,
device=config.device,
Expand All @@ -52,6 +84,7 @@ def __init__(self, config):
development_hacks=config.development_hacks,
output_frequency=config.output_frequency,
write_initial_state=config.write_initial_state,
accumulations=accumulate_from_start_of_forecast,
)

def create_input(self):
Expand Down
Loading