minto.v1.datastore#

Attributes#

T

Classes#

DataStore

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

InstanceStorage

Abstract base class defining the interface for storage strategies.

JSONStorage

Abstract base class defining the interface for storage strategies.

ProblemStorage

SampleSetStorage

Abstract base class defining the interface for storage strategies.

SolutionStorage

Abstract base class defining the interface for storage strategies.

StorageStrategy

Abstract base class defining the interface for storage strategies.

Module Contents#

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
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")
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

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

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:
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:
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

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

Storage for problem instances

meta_data: dict[str, Any]#

Storage for metadata

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

Namespace for MINTO-specific annotations for ommx-artifact.

objects: dict[str, dict]#

Storage for generic JSON-serializable objects

parameters: dict[str, float | int]#

Storage for parameters

problems: dict[str, jijmodeling.Problem]#

Storage for optimization problems

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

Storage for samplesets

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

Storage for problem solutions

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

add_to_artifact_builder(data: ommx.v1.Instance, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
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

load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) ommx.v1.Instance#
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

property extension#
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

add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
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

load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
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

property extension#
class ProblemStorage#

Bases: StorageStrategy[jijmodeling.Problem]

add_to_artifact_builder(data: jijmodeling.Problem, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
load(path: pathlib.Path) jijmodeling.Problem#
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
save(data: jijmodeling.Problem, path: pathlib.Path)#
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

add_to_artifact_builder(data: ommx.v1.SampleSet, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
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

load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
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

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

add_to_artifact_builder(data: ommx.v1.Solution, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str])#
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

load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)#
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

property extension#
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 add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict[str, str]) None#
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 load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) T#
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

property extension: str#
Abstractmethod:

T#