Problem¶
In this package, we assume the following initial optimization problem definition,
This optimization problem is defined by :
an objective function \(f\) shared across a problem class;
a context \(x\) specific to each problem instance.
Moreover, it is assumed that the gradient \(\nabla_y f\) is defined.
Every class of problem differs from one another. This package provides an interface that should be respected for compatibility with our neural network library.
Problem¶
- class Problem[source]¶
Bases:
ABCBase abstract class for graph-based optimization or learning problems.
Subclasses must implement methods to retrieve the problem context graph, an initial zero decision graph, compute gradients, evaluate score, and provide problem metadata.
- Notes:
All returned Graph objects must adhere to the energnn.graph.Graph API.
Methods returning tuples will return additional information in the dict when get_info=True for tracking purpose.
Initialize the problem instance. |
|
Retrieve the context graph math:x of the problem instance. |
|
Compute the gradient graph \(\nabla_y f\) for a given decision \(y\). |
|
Should return a scalar score that evaluates the decision graph \(y\). |
|
Should define the structure of all decision graphs. |
|
Should define the structure of all context graphs. |
Batch¶
- class ProblemBatch[source]¶
Bases:
ABCAbstract base class for handling batches of problem instances.
Subclasses should implement methods to retrieve batch of context, compute gradients and scores for batches of decision graphs, and provide an initial zero decision batch.
Initialize the batch handler. |
|
Retrieve the batch of context graphs \(x\). |
|
Compute gradients \(\nabla_y f\) for a batched of decision graphs \(y\). |
|
Evaluate a scalar score for each decision graph in the batch. |
|
Should define the structure of all decision graphs. |
|
Should define the structure of all context graphs. |
Dataset¶
- class ProblemDataset(name, split, version, instances, size, context_max_shape, decision_max_shape, generation_date, selection_criteria, tags=None)[source]¶
Bases:
dictDictionary-like container for datasets of problem instances.
Stores dataset-level metadata and a list of ProblemMetadata instances.
- Parameters:
name (str) – Identifier for the dataset.
split (str) – Dataset split name (e.g., “train”, “val”, “test”).
version (int) – Version number of the dataset.
instances (list[ProblemMetadata]) – List of ProblemMetadata objects describing each instance.
size (int) – Total number of instances in the dataset.
context_max_shape (dict) – Maximum dimensions of context graphs across instances.
decision_max_shape (dict) – Maximum dimensions of decision graphs across instances.
generation_date (datetime) – Timestamp when the dataset was generated.
selection_criteria (dict) – A dictionary that contains some criteria
tags – Key-value tags associated with the dataset for grouping or filtering.
Retrieve the dataset's information to send to the feature store. |
|
Identify instances whose files are missing in a local directory. |
|
List the storage paths for all instances in the dataset. |
|
Serialize the dataset to a JSON file for human-readable archives. |
|
Serialize the dataset to a pickle file for efficient reload. |
|
Load a dataset from a pickle file produced by to_pickle. |
Metadata¶
- class ProblemMetadata(name, config_id, code_version, context_shape, decision_shape, storage_path='', filter_tags=None)[source]¶
Bases:
dictMetadata of a Problem instance.
- Parameters:
name (str) – Name of the instance.
config_id (str) – Identifier of the configuration file used to generate the instance.
code_version (int) – Version of the code used to generate the instance.
context_shape (dict) – Shape of the context of the instance, formatted as a dict containing only int values (no jax.Array).
decision_shape (dict) – Shape of the decision of the instance, formatted as a dict containing only int values (no jax.Array).
filter_tags (dict | None) – Dictionary of the criteria used to select the instance to form datasets.
Loader¶
- class ProblemLoader(batch_size, shuffle=False)[source]¶
Bases:
ABC,Sized,Iterator[ProblemBatch]Abstract base class for problem loaders that yield batches of problem instances.
Iterates over problem instances in batches, optionally shuffling the dataset.
- Parameters:
batch_size (int) – Number of instances per batch returned by the iterator.
shuffle (bool) – If true, randomly shuffle the dataset.
Initialize the problem loader. |
|
Return the loader iterator. |
|
Retrieve the next batch of problems. |
|
Number of batches per epoch. |
|
Should define the structure of all context graphs. |
|
Should define the structure of all decision graphs. |