Module ml4opf.formulations.model

Abstract base class for ML models for OPF.

Each formulation should inherit from OPFModel and implement the following methods:

  • evaluate_model: Evaluate the model on the test data.

User models should inherit from the formulation's OPFModel class (e.g., ACPModel) and implement the methods:

  • save_checkpoint: Save the model's checkpoint to a file.

  • load_from_checkpoint: Load the model's checkpoint from a file.

  • predict: Predict the solution for a given set of inputs.

Classes

class OPFModel

An abstract base class for ACOPF models.

Ancestors

  • abc.ABC

Subclasses

Static methods

def load_from_checkpoint(path_to_folder: str,
problem: OPFProblem)

Load the model's checkpoint from a file.

Args

path : str
Path to load the checkpoint from.

Methods

def evaluate_model(self, reduction: str | None = None, inner_reduction: str | None = None) ‑> dict[str, torch.Tensor]

Evaluate the model on the test data.

Args

reduction : str, optional
Reduction method for the metrics. Defaults to None. Must be one of "mean", "sum", "none". If specified, each value in the returned dictionary will be a scalar. Otherwise, they are arrays of shape (n_test_samples,)

Returns

dict[str, Tensor]
Dictionary containing Tensor metrics of the model's performance.
def predict(self, *inputs: torch.Tensor) ‑> dict[str, torch.Tensor]

Predict the solution for a given set of inputs.

Args

*inputs : Tensor
Input tensors to the model.

Returns

dict[str, Tensor]
Dictionary containing the solution.
def save_checkpoint(self, path_to_folder: str)

Save the model's checkpoint to a file.

Args

path : str
Path to save the checkpoint.