Skip to content

Refactor mappers to allow dynamic behaviour #552

@JPXKQX

Description

@JPXKQX

Is your feature request related to a problem? Please describe.

Currently, mappers in anemoi-models are static: they receive the subgraph (edge indices & edge attributes) at initialisation, storing it as a mapper attribute. This design limits flexibility when applying the model to novel use cases (observations, multi-domain training, ...). Redesigning them to be dynamic, so that the subgraph is passed during forward(), would make mappers more extensible.

Should all mappers be strictly dynamic? Not necessarily. If benchmarks show a significant performance degradation when always passing the subgraph at forward(), we plan to introduce a caching mechanism. This would allow subgraphs to be stored and reused internally through specialised classes.

Current Status

self.encoder = instantiate(  
  model_config.model.encoder, 
  sub_graph=graph[(self._graph_name_data, "to", self._graph_name_hidden)], 
  **encoder_kwargs 
  ...
) 
x_data_latent, x_latent = self.encoder( 
        (x_data_latent, x_hidden_latent), 
        **kwargs 
        ...
) 

Proposed Solution

self.encoder = instantiate(  
     model_config.model.encoder, 
     **encoder_kwargs,
     ...
) 

x_data_latent, x_latent = self.encoder( 
        (x_data_latent, x_hidden_latent), 
        edge_index=graph[(self._graph_name_data, "to", self._graph_name_hidden)].edge_index, 
        **kwargs,
       ...
) 

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Next Up

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions