Global medium-range weather forecasting is critical for socioeconomic decision-making. Traditional numerical weather prediction (NWP) models rely on increasing computational power to enhance accuracy and cannot easily leverage historical data to refine their core physics. In contrast, machine learning (ML)-based models learn directly from historical data, optimizing accuracy and computational efficiency. This data-driven approach captures complex quantitative relationships that are difficult to express with explicit equations.
GraphCast is a state-of-the-art ML-based weather forecasting model trained on reanalysis data. It can predict hundreds of global weather variables over a 10-day horizon at 0.25° resolution in under one minute. Research demonstrates that GraphCast outperforms the most accurate operational deterministic systems on 90% of 1,380 verification targets. It also excels at predicting severe weather events, such as tropical cyclones, atmospheric rivers, and extreme temperatures.
The core architecture of GraphCast adopts an "Encode-Process-Decode" structure based on Graph Neural Networks (GNN). GNN-based learning simulators are very effective in learning complex physical dynamics of fluids and other materials because their representation and computational structure are similar to learned finite element solvers.
Structure diagram of GraphCast
To address the uneven density of latitude-longitude grids, GraphCast uses a "multi-mesh" representation instead of a standard grid. This multi-mesh is constructed by refining an icosahedron 6 times iteratively; each step divides a triangular face into 4 smaller ones.
The model operates on a graph \(\mathcal{G(V^\mathrm{G}, V^\mathrm{M}, E^\mathrm{M}, E^\mathrm{G2M}, E^\mathrm{M2G})}\), defined as follows:
\(\mathcal{V^\mathrm{G}}\): Set of grid nodes representing vertical atmospheric slices at specific latitude/longitude points. Node features are denoted by \(\mathbf{v}_i^\mathrm{G,features}\).
\(V^\mathrm{M}\): Set of mesh nodes generated by the icosahedral refinement. Node features are denoted by \(\mathbf{v}_i^\mathrm{M,features}\).
\(\mathcal{E^\mathrm{M}}\): Set of undirected edges connecting mesh nodes (\(e^\mathrm{M}_{v^\mathrm{M}_s \rightarrow v^\mathrm{M}_r}\)), with features \(\mathbf{e}^\mathrm{M,features}_{v^\mathrm{M}_s \rightarrow v^\mathrm{M}_r}\).
\(\mathcal{E^\mathrm{G2M}}\): Set of edges connecting sending grid nodes to receiving mesh nodes (\(e^\mathrm{G2M}_{v^\mathrm{G}_s \rightarrow v^M_r}\)), with features \(\mathbf{e}^\mathrm{G2M,features}_{v^\mathrm{G}_s \rightarrow v^\mathrm{M}_r}\).
\(\mathcal{E^\mathrm{M2G}}\): Set of edges connecting sending mesh nodes to receiving grid nodes (\(e^\mathrm{M2G}_{v^M_s \rightarrow v^G_r}\)), with features \(\mathbf{e}^\mathrm{M2G,features}_{v^\mathrm{M}_s \rightarrow v^\mathrm{G}_r}\).
The encoder maps input data into GraphCast's latent representation. First, five Multi-Layer Perceptrons (MLPs) embed the features of the graph components into a latent space:
Next, information propagates from grid nodes to mesh nodes via a Grid2Mesh GNN layer. Edges in \(\mathcal{E^\mathrm{G2M}}\) are updated based on associated nodes:
We use a subset of the 2020 ERA5 reanalysis archive from ECMWF. The dataset spans 1979-2018 with a 6-hour interval (00z, 06z, 12z, 18z), a horizontal resolution of 0.25°, and 37 vertical pressure levels.
The model predicts 227 target variables: 5 surface variables and 6 atmospheric variables across 13 selected pressure levels.
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.# Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at# http://www.apache.org/licenses/LICENSE-2.0# Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.fromtypingimportDictimporthydraimportnumpyasnpimportpaddleimportplotfromomegaconfimportDictConfigimportppscifromppsci.data.datasetimportatmospheric_datasetdefeval(cfg:DictConfig):model=ppsci.arch.GraphCastNet(**cfg.MODEL)# set dataloader configeval_dataloader_cfg={"dataset":{"name":"GridMeshAtmosphericDataset","input_keys":("input",),"label_keys":("label",),**cfg.DATA,},"batch_size":cfg.EVAL.batch_size,}# set validatorerror_validator=ppsci.validate.SupervisedValidator(eval_dataloader_cfg,loss=None,output_expr={"pred":lambdaout:out["pred"]},metric=None,name="error_validator",)defloss(output_dict:Dict[str,paddle.Tensor],label_dict:Dict[str,paddle.Tensor],*args,)->Dict[str,paddle.Tensor]:graph=output_dict["pred"]pred=dataset.denormalize(graph.grid_node_feat.numpy())pred=graph.grid_node_outputs_to_prediction(pred,dataset.targets_template)target=graph.grid_node_outputs_to_prediction(label_dict["label"][0].numpy(),dataset.targets_template)pred=atmospheric_dataset.dataset_to_stacked(pred)target=atmospheric_dataset.dataset_to_stacked(target)loss=np.average(np.square(pred.data-target.data))loss=paddle.full([],loss)return{"loss":loss}defmetric(output_dict:Dict[str,paddle.Tensor],label_dict:Dict[str,paddle.Tensor],*args,)->Dict[str,paddle.Tensor]:graph=output_dict["pred"][0]pred=dataset.denormalize(graph.grid_node_feat.numpy())pred=graph.grid_node_outputs_to_prediction(pred,dataset.targets_template)target=graph.grid_node_outputs_to_prediction(label_dict["label"][0].numpy(),dataset.targets_template)metric_dic={var_name:np.average(target[var_name].data-pred[var_name].data)forvar_nameinlist(target)}returnmetric_dicdataset=error_validator.data_loader.dataseterror_validator.loss=ppsci.loss.FunctionalLoss(loss)error_validator.metric={"error":ppsci.metric.FunctionalMetric(metric)}validator={error_validator.name:error_validator}# initialize solversolver=ppsci.solver.Solver(model,validator=validator,cfg=cfg,pretrained_model_path=cfg.EVAL.pretrained_model_path,eval_with_no_grad=cfg.EVAL.eval_with_no_grad,)# evaluate modelsolver.eval()# visualize predictionwithsolver.no_grad_context_manager(True):forindex,(input_,label_,_)inenumerate(error_validator.data_loader):output_=model(input_)graph=output_["pred"]pred=dataset.denormalize(graph.grid_node_feat.numpy())pred=graph.grid_node_outputs_to_prediction(pred,dataset.targets_template)target=graph.grid_node_outputs_to_prediction(label_["label"][0].numpy(),dataset.targets_template)plot.log_images(target,pred,"2m_temperature",level=50,file="result.png")@hydra.main(version_base=None,config_path="./conf",config_name="graphcast_small.yaml")defmain(cfg:DictConfig):ifcfg.mode=="eval":eval(cfg)else:raiseValueError(f"cfg.mode should in ['eval'], but got '{cfg.mode}'")if__name__=="__main__":main()