Skip to content

Commit 2d8a119

Browse files
anaprietonemmc4117pre-commit-ci[bot]
authored andcommitted
feat: activate minmium plotting for integration tests (#669)
## Description Testing plots it's not part our current testing suite. Since most of them are implemented via callbacks a simple way would be to activate a minimal plotting set up for the integration test to ensure we don't break them in the future. This PR proposes those changes: - Spectrum plot it's quite slow so for now it's deactivated for the SG model - Since the test dataset for LAM and SG is a small one we just test plotting tp - The plots for the interpolator are deactivated - while the callbacks run the output produced is not scientifically correct. More work will be done in the future to address this (@mc4117 - notified about this in slack channel) - In the hierarchical model - current plotting of edge features is not support - this plot is for now deactivated. (Discussed with @icedoom888 ) cc: @VeraChristina - having those tests would also be useful in the context of multiple datasets to ensure there is no feature regression for plotting. ## What problem does this change solve? <!-- Describe if it's a bugfix, new feature, doc update, or breaking change --> ## What issue or task does this change relate to? <!-- link to Issue Number --> ## Additional notes ## <!-- Include any additional information, caveats, or considerations that the reviewer should be aware of. --> ***As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/*** By opening this pull request, I affirm that all authors agree to the [Contributor License Agreement.](https://github.com/ecmwf/codex/blob/main/Legal/contributor_license_agreement.md) --------- Co-authored-by: Mariana Clare <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 415b184 commit 2d8a119

File tree

10 files changed

+216
-44
lines changed

10 files changed

+216
-44
lines changed

.github/workflows/integration-tests-hpc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
#SBATCH --qos=ng
5353
#SBATCH --gpus=1
5454
#SBATCH --gres=gpu:1
55-
#SBATCH --mem=30G
55+
#SBATCH --mem=64G
5656
troika_user: ${{ secrets.HPC_CI_INTEGRATION_USER }}
5757
benchmark-tests:
5858
runs-on: hpc

training/src/anemoi/training/diagnostics/callbacks/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ def get_callbacks(config: DictConfig) -> list[Callback]:
182182
trainer_callbacks.extend(instantiate(callback, config) for callback in config.diagnostics.callbacks)
183183

184184
# Plotting callbacks
185-
trainer_callbacks.extend(instantiate(callback, config) for callback in config.diagnostics.plot.callbacks)
185+
if config["training"]["model_task"] != "anemoi.training.train.tasks.GraphInterpolator":
186+
trainer_callbacks.extend(instantiate(callback, config) for callback in config.diagnostics.plot.callbacks)
187+
else:
188+
LOGGER.info("Plotting callbacks have been temporarily deactivated for the TimeInterpolator")
186189

187190
# Extend with config enabled callbacks
188191
trainer_callbacks.extend(_get_config_enabled_callbacks(config))

training/src/anemoi/training/diagnostics/callbacks/plot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,13 @@ def _plot(
710710
else:
711711
LOGGER.warning("There are no trainable node attributes to plot.")
712712

713-
if len(edge_trainable_modules := self.get_edge_trainable_modules(model)):
713+
from anemoi.models.models import AnemoiModelEncProcDecHierarchical
714+
715+
if isinstance(model, AnemoiModelEncProcDecHierarchical):
716+
LOGGER.warning(
717+
"Edge trainable features are not supported for Hierarchical models, skipping plot generation.",
718+
)
719+
elif len(edge_trainable_modules := self.get_edge_trainable_modules(model)):
714720
fig = plot_graph_edge_features(model, edge_trainable_modules, q_extreme_limit=self.q_extreme_limit)
715721

716722
self._output_figure(

training/src/anemoi/training/diagnostics/callbacks/plot_ens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def on_validation_batch_end(
286286
trainer,
287287
pl_module,
288288
outputs,
289-
batch[0][:, :, 0, :, :],
289+
batch[:, :, 0, :, :],
290290
batch_idx,
291291
)
292292

training/tests/integration/config/test_ensemble_crps.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,45 @@ dataloader:
1414
end: 2017-01-08 12:00:00
1515
validation:
1616
start: 2017-01-08 18:00:00
17+
18+
diagnostics:
19+
plot:
20+
callbacks:
21+
# Add plot callbacks here.
22+
- _target_: anemoi.training.diagnostics.callbacks.plot_ens.PlotEnsSample
23+
sample_idx: ${diagnostics.plot.sample_idx}
24+
per_sample : 2
25+
parameters: ${diagnostics.plot.parameters}
26+
every_n_batches: ${diagnostics.plot.frequency.batch}
27+
#Defining the accumulation levels for precipitation related fields and the colormap
28+
accumulation_levels_plot: [0, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 7, 100] # in mm
29+
members: null # None for all members, list for specific members
30+
31+
# Deterministic callbacks are also overloaded.
32+
- _target_: anemoi.training.diagnostics.callbacks.plot_ens.PlotLoss
33+
# group parameters by categories when visualizing contributions to the loss
34+
# one-parameter groups are possible to highlight individual parameters
35+
parameter_groups:
36+
moisture: [tp, cp, tcw]
37+
sfc_wind: [10u, 10v]
38+
every_n_batches: ${diagnostics.plot.frequency.batch}
39+
- _target_: anemoi.training.diagnostics.callbacks.plot_ens.PlotSpectrum
40+
sample_idx: ${diagnostics.plot.sample_idx}
41+
parameters: ${diagnostics.plot.parameters}
42+
every_n_batches: ${diagnostics.plot.frequency.batch}
43+
- _target_: anemoi.training.diagnostics.callbacks.plot_ens.PlotHistogram
44+
sample_idx: ${diagnostics.plot.sample_idx}
45+
parameters: ${diagnostics.plot.parameters}
46+
every_n_batches: ${diagnostics.plot.frequency.batch}
47+
precip_and_related_fields: ["tp", "cp"] # Optional: specify precip fields for special histogram treatment
48+
- _target_: anemoi.training.diagnostics.callbacks.plot_ens.GraphTrainableFeaturesPlot
49+
every_n_epochs: ${diagnostics.plot.frequency.epoch}
50+
51+
# Overloaded PlotSample will return the plots for the first ensemble member
52+
# - _target_: anemoi.training.diagnostics.callbacks.plot_ens.PlotSample
53+
# sample_idx: ${diagnostics.plot.sample_idx}
54+
# per_sample: 6
55+
# parameters: ${diagnostics.plot.parameters}
56+
# every_n_batches: ${diagnostics.plot.frequency.batch}
57+
# accumulation_levels_plot: [0, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 7, 100] # in mm
58+
# precip_and_related_fields: ["tp", "cp"] # Optional: specify precip fields

training/tests/integration/config/test_lam.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,41 @@ data:
5050
- "cos_local_time"
5151
- "sin_julian_day"
5252
- "sin_local_time"
53+
54+
diagnostics:
55+
plot:
56+
# Parameters to plot
57+
parameters:
58+
- tp
59+
callbacks:
60+
# Add plot callbacks here
61+
- _target_: anemoi.training.diagnostics.callbacks.plot.GraphTrainableFeaturesPlot
62+
every_n_epochs: 5
63+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotLoss
64+
# group parameters by categories when visualizing contributions to the loss
65+
# one-parameter groups are possible to highlight individual parameters
66+
parameter_groups:
67+
moisture: [tp]
68+
every_n_batches: ${diagnostics.plot.frequency.batch}
69+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotSample
70+
sample_idx: ${diagnostics.plot.sample_idx}
71+
per_sample : 6
72+
parameters: ${diagnostics.plot.parameters}
73+
every_n_batches: ${diagnostics.plot.frequency.batch}
74+
#Defining the accumulation levels for precipitation related fields and the colormap
75+
accumulation_levels_plot: [0, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 7, 100] # in mm
76+
precip_and_related_fields: ${diagnostics.plot.precip_and_related_fields}
77+
colormaps: ${diagnostics.plot.colormaps}
78+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotSpectrum
79+
# every_n_batches: 100 # Override for batch frequency
80+
# min_delta: 0.01 # Minimum distance between two consecutive points
81+
sample_idx: ${diagnostics.plot.sample_idx}
82+
every_n_batches: ${diagnostics.plot.frequency.batch}
83+
parameters:
84+
- tp
85+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotHistogram
86+
sample_idx: ${diagnostics.plot.sample_idx}
87+
every_n_batches: ${diagnostics.plot.frequency.batch}
88+
precip_and_related_fields: ${diagnostics.plot.precip_and_related_fields}
89+
parameters:
90+
- tp

training/tests/integration/config/test_stretched.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ training:
6060
scalers:
6161
node_weights:
6262
weight_frac_of_total: 0.25
63+
64+
65+
diagnostics:
66+
plot:
67+
# Parameters to plot
68+
parameters:
69+
- tp
70+
callbacks:
71+
# Add plot callbacks here
72+
- _target_: anemoi.training.diagnostics.callbacks.plot.GraphTrainableFeaturesPlot
73+
every_n_epochs: 5
74+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotLoss
75+
# group parameters by categories when visualizing contributions to the loss
76+
# one-parameter groups are possible to highlight individual parameters
77+
parameter_groups:
78+
moisture: [tp]
79+
every_n_batches: ${diagnostics.plot.frequency.batch}
80+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotSample
81+
sample_idx: ${diagnostics.plot.sample_idx}
82+
per_sample : 6
83+
parameters: ${diagnostics.plot.parameters}
84+
every_n_batches: ${diagnostics.plot.frequency.batch}
85+
#Defining the accumulation levels for precipitation related fields and the colormap
86+
accumulation_levels_plot: [0, 0.05, 0.1, 0.25, 0.5, 1, 1.5, 2, 3, 4, 5, 6, 7, 100] # in mm
87+
precip_and_related_fields: ${diagnostics.plot.precip_and_related_fields}
88+
colormaps: ${diagnostics.plot.colormaps}
89+
# - _target_: anemoi.training.diagnostics.callbacks.plot.PlotSpectrum
90+
# # every_n_batches: 100 # Override for batch frequency
91+
# # min_delta: 0.01 # Minimum distance between two consecutive points
92+
# sample_idx: ${diagnostics.plot.sample_idx}
93+
# every_n_batches: ${diagnostics.plot.frequency.batch}
94+
# parameters:
95+
# - tp
96+
- _target_: anemoi.training.diagnostics.callbacks.plot.PlotHistogram
97+
sample_idx: ${diagnostics.plot.sample_idx}
98+
every_n_batches: ${diagnostics.plot.frequency.batch}
99+
precip_and_related_fields: ${diagnostics.plot.precip_and_related_fields}
100+
parameters:
101+
- tp

training/tests/integration/config/testing_modifications.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dataloader:
1313
diagnostics:
1414
plot:
1515
callbacks: []
16+
asynchronous: False # Whether to plot asynchronously
1617
log:
1718
wandb:
1819
enabled: False

0 commit comments

Comments
 (0)