Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

datastore

minto.v1.datastore

Classes

StorageStrategy

StorageStrategy()

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.

Methods

save
save(data: minto.v1.datastore.T, path: pathlib.Path)

Save data to the specified path.

Parameters:

NameTypeDescription
dataminto.v1.datastore.TThe data to save
pathpathlib.PathThe path where the data should be saved
load
load(path: pathlib.Path) -> minto.v1.datastore.T

Load data from the specified path.

Parameters:

NameTypeDescription
pathpathlib.PathThe path from which to load the data

Returns:

TypeDescription
minto.v1.datastore.TThe loaded data
add_to_artifact_builder
add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict) -> None
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) -> minto.v1.datastore.T

JSONStorage

JSONStorage()

Methods

save
save(data, path: pathlib.Path)
load
load(path: pathlib.Path) -> typing.Any
add_to_artifact_builder
add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict)
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)

ProblemStorage

ProblemStorage()

Methods

save
save(data: jijmodeling.Problem, path: pathlib.Path)
load
load(path: pathlib.Path) -> jijmodeling.Problem
add_to_artifact_builder
add_to_artifact_builder(data: jijmodeling.Problem, builder: ommx.artifact.ArtifactBuilder, annotations: dict)
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)

InstanceStorage

InstanceStorage()

Methods

save
save(data: ommx.v1.Instance, path: pathlib.Path)
load
load(path: pathlib.Path) -> ommx.v1.Instance
add_to_artifact_builder
add_to_artifact_builder(data: ommx.v1.Instance, builder: ommx.artifact.ArtifactBuilder, annotations: dict)
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) -> ommx.v1.Instance

SolutionStorage

SolutionStorage()

Methods

save
save(data: ommx.v1.Solution, path: pathlib.Path)
load
load(path: pathlib.Path) -> ommx.v1.Solution
add_to_artifact_builder
add_to_artifact_builder(data: ommx.v1.Solution, builder: ommx.artifact.ArtifactBuilder, annotations: dict)
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)

SampleSetStorage

SampleSetStorage()

Methods

save
save(data: ommx.v1.SampleSet, path: pathlib.Path)
load
load(path: pathlib.Path) -> ommx.v1.SampleSet
add_to_artifact_builder
add_to_artifact_builder(data: ommx.v1.SampleSet, builder: ommx.artifact.ArtifactBuilder, annotations: dict)
load_from_layer
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor)

DataStore

DataStore(problems: dict = dict(), instances: dict = dict(), solutions: dict = dict(), objects: dict = dict(), parameters: dict = dict(), samplesets: dict = dict(), meta_data: dict = dict())

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:

Directory structure:

.. code-block:: text

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

Methods

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

Add an object to the specified storage.

Parameters:

NameTypeDescription
namestrIdentifier for the object
objAnyObject to store
storage_namestrType of storage (‘problems’, ‘instances’, etc.)
with_saveboolWhether to save to disk. Defaults to False.
save_dirstrDirectory for saving files. Defaults to “.”.
save_all
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:

NameTypeDescription
pathpathlib.PathDirectory where files should be saved
load

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:

NameTypeDescription
pathpathlib.PathDirectory containing the stored files

Returns:

TypeDescription
``New DataStore instance containing the loaded data

Raises:

ExceptionDescription
minto.v1.exceptions.FileNotFoundErrorIf the directory does not exist
minto.v1.exceptions.FileCorruptionErrorIf a file is corrupted or has invalid format
minto.v1.exceptions.MissingMetadataErrorIf required metadata is missing
add_to_artifact_builder
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:

NameTypeDescription
builderommx.artifact.ArtifactBuilderThe artifact builder
annotationsdictBase annotations for all layers
load_from_layers

classmethod

load_from_layers(artifact: ommx.artifact.Artifact, layers: typing.Iterable)

Create a DataStore from OMMX artifact layers.

Parameters:

NameTypeDescription
artifactommx.artifact.ArtifactThe OMMX artifact containing the data
layersIterableLayer descriptors to process

Returns:

TypeDescription
``New DataStore instance containing the data from the layers

Raises:

ExceptionDescription
minto.v1.exceptions.MissingMetadataErrorIf required metadata is missing
minto.v1.exceptions.InvalidMetadataErrorIf metadata has invalid format or values
minto.v1.exceptions.FileCorruptionErrorIf a layer is corrupted or has invalid format
get_solution
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:

TypeDescription
ommx.v1.Solutionommx.v1.Solution: The first solution sorted by key