interaction_net

class mfai.pytorch.models.nlam.interaction_net.CheckpointWrapper(module)[source]

Bases: Module

Wrapper for checkpointing a module. Comes from AIFS.

Parameters:

module (Module)

forward(*args, **kwargs)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Sequential

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Sequential

class mfai.pytorch.models.nlam.interaction_net.InteractionNet(edge_index, input_dim, update_edges=True, hidden_layers=1, hidden_dim=None, edge_chunk_sizes=None, aggr_chunk_sizes=None, aggr='sum', checkpoint=False)[source]

Bases: MessagePassing

Implementation of a generic Interaction Network, from Battaglia et al. (2016).

Parameters:
aggregate(messages, index, ptr, dim_size)[source]

Overridden aggregation function to: * return both aggregated and original messages, * only aggregate to number of receiver nodes.

Return type:

tuple[Tensor, Tensor]

Parameters:
forward(send_rep, rec_rep, edge_rep)[source]

Apply interaction network to update the representations of receiver nodes, and optionally the edge representations.

send_rep: (N_send, d_h), vector representations of sender nodes rec_rep: (N_rec, d_h), vector representations of receiver nodes edge_rep: (M, d_h), vector representations of edges used

Returns: rec_rep: (N_rec, d_h), updated vector representations of receiver nodes (optionally) edge_rep: (M, d_h), updated vector representations of edges

Return type:

Tensor | tuple[Tensor, Tensor]

Parameters:
message(x_j, x_i, edge_attr)[source]

Compute messages from node j to node i.

Return type:

Tensor

Parameters:
class mfai.pytorch.models.nlam.interaction_net.SplitMLPs(mlps, chunk_sizes)[source]

Bases: Module

Module that feeds chunks of input through different MLPs. Split up input along dim -2 using given chunk sizes and feeds each chunk through separate MLPs.

Parameters:
forward(x)[source]

Chunk up input and feed through MLPs.

x: (…, N, d), where N = sum(chunk_sizes)

Returns: joined_output: (…, N, d), concatenated results from the different MLPs

Return type:

Tensor

Parameters:

x (Tensor)

mfai.pytorch.models.nlam.interaction_net.make_mlp(blueprint, layer_norm=True, checkpoint=False)[source]

Create MLP from list blueprint, with input dimensionality: blueprint[0] output dimensionality: blueprint[-1] and hidden layers of dimensions: blueprint[1], …, blueprint[-2].

if layer_norm is True, includes a LayerNorm layer at the output (as used in GraphCast)

Return type:

Sequential | CheckpointWrapper

Parameters: