Datastore
DataStore
dataclass
¶
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
Attributes:
Name | Type | Description |
---|---|---|
problems | dict[str, Problem] | Storage for optimization problems |
instances | dict[str, Instance] | Storage for problem instances |
solutions | dict[str, Solution] | Storage for problem solutions |
objects | dict[str, dict] | Storage for generic JSON-serializable objects |
parameters | dict[str, dict[str, Any]] | Storage for parameters |
meta_data | dict[str, Any] | Storage for metadata |
Source code in minto/v1/datastore.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
add(name, obj, storage_name, with_save=False, save_dir='.')
¶
Add an object to the specified storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | Identifier for the object | required |
obj | Any | Object to store | required |
storage_name | str | Type of storage ('problems', 'instances', etc.) | required |
with_save | bool | Whether to save to disk. Defaults to False. | False |
save_dir | str | Directory for saving files. Defaults to ".". | '.' |
Examples:
>>> ds = DataStore()
>>> ds.add("problem1", problem, "problems", with_save=True)
>>> ds.add("param1", {"value": 42}, "parameters")
Source code in minto/v1/datastore.py
add_to_artifact_builder(builder, annotations)
¶
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 | Default |
---|---|---|---|
builder | ArtifactBuilder | The artifact builder | required |
annotations | dict[str, str] | Base annotations for all layers | required |
Source code in minto/v1/datastore.py
load(path)
classmethod
¶
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 | Default |
---|---|---|---|
path | Path | Directory containing the stored files | required |
Returns:
Name | Type | Description |
---|---|---|
DataStore | New DataStore instance containing the loaded data |
Source code in minto/v1/datastore.py
load_from_layers(artifact, layers)
classmethod
¶
Create a DataStore from OMMX artifact layers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
artifact | Artifact | The OMMX artifact containing the data | required |
layers | Iterable[Descriptor] | Layer descriptors to process | required |
Returns:
Name | Type | Description |
---|---|---|
DataStore | New DataStore instance containing the data from the layers |
Source code in minto/v1/datastore.py
save_all(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 | Default |
---|---|---|---|
path | Path | Directory where files should be saved | required |
Source code in minto/v1/datastore.py
StorageStrategy
¶
Bases: 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
Source code in minto/v1/datastore.py
load(path)
abstractmethod
¶
Load data from the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | The path from which to load the data | required |
Returns:
Name | Type | Description |
---|---|---|
T | T | The loaded data |
save(data, path)
abstractmethod
¶
Save data to the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data | T | The data to save | required |
path | Path | The path where the data should be saved | required |