minto.v1.datastore#

Attributes#

T

Classes#

StorageStrategy

Abstract base class defining the interface for storage strategies.

JSONStorage

Abstract base class defining the interface for storage strategies.

ProblemStorage

InstanceStorage

Abstract base class defining the interface for storage strategies.

SolutionStorage

Abstract base class defining the interface for storage strategies.

SampleSetStorage

Abstract base class defining the interface for storage strategies.

DataStore

A data store for managing optimization-related data with multiple storage types.

Module Contents#

T#
class StorageStrategy#

Bases: abc.ABC, Generic[T]

Abstract base class defining the interface for storage strategies.

This class provides a generic interface for storing and loading different types of data, supporting both file system storage and OMMX artifact storage.

Type Parameters:

T: The type of data this strategy handles

abstract save(data: T, path: pathlib.Path)#

Save data to the specified path.

Parameters:
  • data (T) – The data to save

  • path (pathlib.Path) – The path where the data should be saved

abstract load(path: pathlib.Path) T#

Load data from the specified path.

Parameters:

path (pathlib.Path) – The path from which to load the data

Returns:

The loaded data

Return type:

T

abstract add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str]) None#
abstract load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) T#
property extension: str#
Abstractmethod:

class JSONStorage#

Bases: StorageStrategy[dict]

Abstract base class defining the interface for storage strategies.

This class provides a generic interface for storing and loading different types of data, supporting both file system storage and OMMX artifact storage.

Type Parameters:

T: The type of data this strategy handles

save(data, path: pathlib.Path)#

Save data to the specified path.

Parameters:
  • data (T) – The data to save

  • path (pathlib.Path) – The path where the data should be saved

load(path: pathlib.Path) Any#

Load data from the specified path.

Parameters:

path (pathlib.Path) – The path from which to load the data

Returns:

The loaded data

Return type:

T

add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
property extension#
class ProblemStorage#

Bases: StorageStrategy[jijmodeling.Problem]

save(data: jijmodeling.Problem, path: pathlib.Path)#
load(path: pathlib.Path) jijmodeling.Problem#
add_to_artifact_builder(data: jijmodeling.Problem, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
property extension#
class InstanceStorage#

Bases: StorageStrategy[ommx.v1.Instance]

Abstract base class defining the interface for storage strategies.

This class provides a generic interface for storing and loading different types of data, supporting both file system storage and OMMX artifact storage.

Type Parameters:

T: The type of data this strategy handles

save(data: ommx.v1.Instance, path: pathlib.Path)#

Save data to the specified path.

Parameters:
  • data (T) – The data to save

  • path (pathlib.Path) – The path where the data should be saved

load(path: pathlib.Path) ommx.v1.Instance#

Load data from the specified path.

Parameters:

path (pathlib.Path) – The path from which to load the data

Returns:

The loaded data

Return type:

T

add_to_artifact_builder(data: ommx.v1.Instance, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) ommx.v1.Instance#
property extension#
class SolutionStorage#

Bases: StorageStrategy[ommx.v1.Solution]

Abstract base class defining the interface for storage strategies.

This class provides a generic interface for storing and loading different types of data, supporting both file system storage and OMMX artifact storage.

Type Parameters:

T: The type of data this strategy handles

save(data: ommx.v1.Solution, path: pathlib.Path)#

Save data to the specified path.

Parameters:
  • data (T) – The data to save

  • path (pathlib.Path) – The path where the data should be saved

load(path: pathlib.Path) ommx.v1.Solution#

Load data from the specified path.

Parameters:

path (pathlib.Path) – The path from which to load the data

Returns:

The loaded data

Return type:

T

add_to_artifact_builder(data: ommx.v1.Solution, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
property extension#
class SampleSetStorage#

Bases: StorageStrategy[ommx.v1.SampleSet]

Abstract base class defining the interface for storage strategies.

This class provides a generic interface for storing and loading different types of data, supporting both file system storage and OMMX artifact storage.

Type Parameters:

T: The type of data this strategy handles

save(data: ommx.v1.SampleSet, path: pathlib.Path)#

Save data to the specified path.

Parameters:
  • data (T) – The data to save

  • path (pathlib.Path) – The path where the data should be saved

load(path: pathlib.Path) ommx.v1.SampleSet#

Load data from the specified path.

Parameters:

path (pathlib.Path) – The path from which to load the data

Returns:

The loaded data

Return type:

T

add_to_artifact_builder(data: ommx.v1.SampleSet, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
property extension#
class DataStore#

A data store for managing optimization-related data with multiple storage types.

This class provides a unified interface for storing and managing different types of optimization-related data, including problems, instances, solutions, and various metadata. It supports both file system storage and OMMX artifact storage.

The data store maintains separate storage for:

  • Problems: JijModeling Problem instances

  • Instances: OMMX Instance objects

  • Solutions: OMMX Solution objects

  • Objects: Generic JSON-serializable objects

  • Parameters: Configuration parameters

  • Samplesets: OMMX SampleSet objects

  • Meta-data: Additional metadata

Directory structure:

dir
 ├── problem_*.problem     # Individual problem files
 ├── instance_*.instance   # Individual instance files
 ├── solution_*.solution   # Individual solution files
 ├── objects_*.json       # Individual object files
 ├── parameters_.json     # Single parameters file
 ├── samplesets_*.sampleset   # Individual sampleset files
 └── meta_data_.json      # Single metadata file
problems: dict[str, jijmodeling.Problem]#

Storage for optimization problems

instances: dict[str, ommx.v1.Instance]#

Storage for problem instances

solutions: dict[str, ommx.v1.Solution]#

Storage for problem solutions

objects: dict[str, dict]#

Storage for generic JSON-serializable objects

parameters: dict[str, float | int]#

Storage for parameters

samplesets: dict[str, ommx.v1.SampleSet]#

Storage for samplesets

meta_data: dict[str, Any]#

Storage for metadata

minto_namespace: ClassVar[str] = 'org.minto'#

Namespace for MINTO-specific annotations for ommx-artifact.

add(name: str, obj, storage_name: str, with_save=False, save_dir: str | pathlib.Path = '.')#

Add an object to the specified storage.

Parameters:
  • name (str) – Identifier for the object

  • obj (Any) – Object to store

  • storage_name (str) – Type of storage (‘problems’, ‘instances’, etc.)

  • with_save (bool, optional) – Whether to save to disk. Defaults to False.

  • save_dir (str, optional) – Directory for saving files. Defaults to “.”.

Examples

>>> ds = DataStore()
>>> ds.add("problem1", problem, "problems", with_save=True)
>>> ds.add("param1", {"value": 42}, "parameters")
save_all(path: pathlib.Path)#

Save all stored data to the specified directory.

Saves all objects in all storage types to their respective files in the specified directory, maintaining the standard directory structure.

Parameters:

path (pathlib.Path) – Directory where files should be saved

classmethod load(path: pathlib.Path)#

Load a DataStore from a directory.

Creates a new DataStore instance and populates it with data from files in the specified directory.

Parameters:

path (pathlib.Path) – Directory containing the stored files

Returns:

New DataStore instance containing the loaded data

Return type:

DataStore

Raises:
add_to_artifact_builder(builder: ommx.artifact.ArtifactBuilder, annotations: dict)#

Add all stored data to an OMMX artifact builder.

Adds all objects from all storage types to the artifact builder, including appropriate annotations for each layer.

Parameters:
  • builder (ox_art.ArtifactBuilder) – The artifact builder

  • annotations (dict[str, str]) – Base annotations for all layers

classmethod load_from_layers(artifact: ommx.artifact.Artifact, layers: Iterable[ommx.artifact.Descriptor])#

Create a DataStore from OMMX artifact layers.

Parameters:
  • artifact (ox_art.Artifact) – The OMMX artifact containing the data

  • layers (Iterable[ox_art.Descriptor]) – Layer descriptors to process

Returns:

New DataStore instance containing the data from the layers

Return type:

DataStore

Raises:
get_solution() ommx.v1.Solution#

Get a solution from runs.

If there are multiple solutions, return the first solution sorted by key. This is a syntax sugar for the common use case where there is only one solution. If you have multiple solutions in one experiment or one run, refer to the .solutions property instead.

Returns:

The first solution sorted by key

Return type:

ommx.v1.Solution