GraphNetCore.jl Documentation

GraphNetwork

GraphNetCore.GraphNetworkType
GraphNetwork(model, ps, st, e_norm, n_norm, o_norm)

The central data structure that contains the neural network and the normalisers corresponding to the components of the GNN (edge features, node features and output).

Arguments

  • model: Enocde-Process-Decode model as a Lux.jl Chain.
  • ps: Parameters of the model.
  • st: State of the model.
  • e_norm: Normaliser for the edge features of the GNN.
  • n_norm: Normaliser for the node features of the GNN, whereas each feature has its own normaliser.
  • o_norm: Normaliser for the output of the GNN, whereas each quantity of interest has its own normaliser.
source
GraphNetCore.build_modelFunction
build_model(quantities_size, dims, output_size, mps, layer_size, hidden_layers)

Constructs the Encode-Process-Decode model as a Lux.jl Chain with the given arguments.

Arguments

  • quantities_size: Sum of dimensions of each node feature.
  • dims: Dimension of the mesh.
  • output_size: Sum of dimensions of output quantities.
  • mps: Number of message passing steps.
  • layer_size: Size of hidden layers.
  • hidden_layers: Number of hidden layers.

Returns

  • Encode-Process-Decode model as a Lux.jl Chain.
source
GraphNetCore.step!Function
step!(gn, graph, target_quantities_change, mask, loss_function)

Arguments

  • gn: GraphNetwork that is used.
  • graph: Input data stored in a FeatureGraph.
  • target_quantities_change: Derivatives of quantities of interest (e.g. via finite differences from data).
  • mask: Mask for excluding node types that should not be updated.
  • loss_function: Loss function that is used to calculate the error.

Returns

  • Calculated gradients.
  • Calculated training loss.
source
GraphNetCore.save!Function
save!(gn, opt_state, df_train, df_valid, step, train_loss, path; is_training = true)

Creates a checkpoint of the GraphNetwork at the given training step.

Arguments

  • gn: GraphNetwork that a checkpoint is created of.
  • opt_state: State of the optimiser.
  • df_train: DataFrames.jl DataFrame that stores the train losses at the checkpoints.
  • df_valid: DataFrames.jl DataFrame that stores the validation losses at the checkpoints (only improvements are saved).
  • step: Current training step where the checkpoint is created.
  • train_loss: Current training loss.
  • path: Path to the folder where checkpoints are saved.

Keyword Arguments

  • is_training = true: True if used in training, false otherwise (in validation).
source
FileIO.loadFunction
load(quantities, dims, norms, output, message_steps, ls, hl, opt, device, path)

Loads the GraphNetwork from the latest checkpoint at the given path.

Arguments

  • quantities: Sum of dimensions of each node feature.
  • dims: Dimension of the mesh.
  • e_norms: Normalisers for edge features.
  • n_norms: Normalisers for node features.
  • o_norms: Normalisers for output features.
  • output: Sum of dimensions of output quantities.
  • message_steps: Number of message passing steps.
  • ls: Size of hidden layers.
  • hl: Number of hidden layers.
  • opt: Optimiser that is used for training. Set this to nothing if you want to use the optimiser from the checkpoint.
  • device: Device where the model should be loaded (see Lux GPU Management).
  • path: Path to the folder where the checkpoint is.

Returns

  • GraphNetwork that is loaded from the checkpoint.
  • Loaded Optimiser state. Is nothing if no checkpoint was found or an optimiser was passed as an argument.
  • DataFrames.jl DataFrame containing the train losses at the checkpoints.
  • DataFrames.jl DataFrame containing the validation losses at the checkpoints (only improvements are saved).
source

FeatureGraph

GraphNetCore.FeatureGraphType
FeatureGraph(nf, ef, senders, receivers)

Data structure that is used as an input for the GraphNetwork.

Arguments

  • nf: Node features of the graph.
  • ef: edge features of the graph.
  • senders: List of nodes in the mesh where graph edges start.
  • receivers: List of nodes in the mesh where graph edges end.
source

Normaliser

GraphNetCore.NormaliserOfflineMinMaxType
NormaliserOfflineMinMax(data_min, data_max, target_min = 0.0f0, target_max = 0.0f0)

Offline normalization if the minimum and maximum of the quantity is known (e.g. from the training data). It is recommended to use offline normalization since the minimum and maximum do not need to be inferred from data.

Arguments

  • data_min: Minimum of the quantity in the dataset.
  • data_max: Maximum of the quantity in the dataset.
  • target_min: Minimum of the target of normalization.
  • target_max: Maximum of the target of normalization.
source
GraphNetCore.NormaliserOfflineMeanStdType
NormaliserOfflineMeanStd(data_mean, data_std)

Offline normalization if the mean and standard deviation of the quantity is known (e.g. from the training data). It is recommended to use offline normalization since the minimum and maximum do not need to be inferred from data.

Arguments

  • data_mean: Mean of the quantity in the dataset.
  • data_std: Standard deviation of the quantity in the dataset.
source
GraphNetCore.NormaliserOnlineType
NormaliserOnline(max_accumulations, std_epsilon, acc_count, num_accumulations, acc_sum, acc_sum_squared)

Online normalization if the minimum and maximum of the quantity is not known. It is recommended to use offline normalization since the minimum and maximum do not need to be inferred from data.

Arguments

  • max_accumulations: Maximum number of accumulation steps.
  • std_epsilon: Epsilon for caluclating the standard deviation.
  • acc_count: Sum of dimensions of quantities in each accumulation step.
  • num_accumulations: Current number of accumulation steps.
  • acc_sum: Sum of quantities in each step.
  • acc_sum_squared: Sum of quantities squared in each step.
source

Utilities

GraphNetCore.triangles_to_edgesFunction
triangles_to_edges(faces)

Converts the given faces of a mesh to edges.

Arguments

  • faces: Two-dimensional array with the node indices in the first dimension.

Returns

source
GraphNetCore.parse_edgesFunction
parse_edges(edges)

Converts the given edges to unique pairs of senders and receivers (in both directions).

Arguments

  • edges: Two-dimensional Array containing the edges. The first dimension represents a sender-receiver pair.

Returns

  • Tuple containing the bi-directional sender-receiver pairs. The first index is one direction, the second index the other one.
source
GraphNetCore.one_hotFunction
one_hot(indices, depth, offset = 0)

Constructs a onehot matrix of Bool with the given indices.

Arguments

  • indices: Indices for the onehot matrix.
  • depth: Depth of the matrix. The second dimension will be clipped or padded with zeros to the depth.
  • offset = 0: Offset of the matrix in the second dimension.

Returns

  • Onehot matrix from the given arguments.
source
GraphNetCore.minmaxnormFunction
minmaxnorm(input, input_min, input_max, new_min = 0.0f0, new_max = 1.0f0)

Normalizes the given input to the new given range.

Arguments

  • input: Data that should be normalized.
  • input_min: Minimum of the given data.
  • input_max: Maximum of the given data.
  • new_min = 0.0f0: New minimum of the normalized data.
  • new_max = 1.0f0: New maximum of the normalized data.

Returns

  • Normalized data.
source
GraphNetCore.mse_reduceFunction
mse_reduce(target, output)

Calculates the mean squared error of the given arguments with Tullio for GPU compatibility.

Arguments

  • target: Ground truth from the data.
  • output: Output of the network.

Returns

  • Calculated mean squared error.
source