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:
| Name | Type | Description |
|---|---|---|
data | minto.v1.datastore.T | The data to save |
path | pathlib.Path | The path where the data should be saved |
load¶
load(path: pathlib.Path) -> minto.v1.datastore.TLoad data from the specified path.
Parameters:
| Name | Type | Description |
|---|---|---|
path | pathlib.Path | The path from which to load the data |
Returns:
| Type | Description |
|---|---|
minto.v1.datastore.T | The loaded data |
add_to_artifact_builder¶
add_to_artifact_builder(data, builder: ommx.artifact.ArtifactBuilder, annotations: dict) -> Noneload_from_layer¶
load_from_layer(artifact: ommx.artifact.Artifact, layer: ommx.artifact.Descriptor) -> minto.v1.datastore.TJSONStorage¶
JSONStorage()Methods¶
save¶
save(data, path: pathlib.Path)load¶
load(path: pathlib.Path) -> typing.Anyadd_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.Problemadd_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.Instanceadd_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.InstanceSolutionStorage¶
SolutionStorage()Methods¶
save¶
save(data: ommx.v1.Solution, path: pathlib.Path)load¶
load(path: pathlib.Path) -> ommx.v1.Solutionadd_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.SampleSetadd_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:
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:
.. 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 fileMethods¶
add¶
add(name: str, obj, storage_name: str, with_save = False, save_dir: str | pathlib.Path = '.')Add an object to the specified storage.
Parameters:
| Name | Type | Description |
|---|---|---|
name | str | Identifier for the object |
obj | Any | Object to store |
storage_name | str | Type of storage (‘problems’, ‘instances’, etc.) |
with_save | bool | Whether to save to disk. Defaults to False. |
save_dir | str | Directory 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:
| Name | Type | Description |
|---|---|---|
path | pathlib.Path | Directory 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:
| Name | Type | Description |
|---|---|---|
path | pathlib.Path | Directory containing the stored files |
Returns:
| Type | Description |
|---|---|
| `` | New DataStore instance containing the loaded data |
Raises:
| Exception | Description |
|---|---|
minto.v1.exceptions.FileNotFoundError | If the directory does not exist |
minto.v1.exceptions.FileCorruptionError | If a file is corrupted or has invalid format |
minto.v1.exceptions.MissingMetadataError | If 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:
| Name | Type | Description |
|---|---|---|
builder | ommx.artifact.ArtifactBuilder | The artifact builder |
annotations | dict | Base 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:
| Name | Type | Description |
|---|---|---|
artifact | ommx.artifact.Artifact | The OMMX artifact containing the data |
layers | Iterable | Layer descriptors to process |
Returns:
| Type | Description |
|---|---|
| `` | New DataStore instance containing the data from the layers |
Raises:
| Exception | Description |
|---|---|
minto.v1.exceptions.MissingMetadataError | If required metadata is missing |
minto.v1.exceptions.InvalidMetadataError | If metadata has invalid format or values |
minto.v1.exceptions.FileCorruptionError | If a layer is corrupted or has invalid format |
get_solution¶
get_solution() -> ommx.v1.SolutionGet 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:
| Type | Description |
|---|---|
ommx.v1.Solution | ommx.v1.Solution: The first solution sorted by key |