Artifact

Artifact#

class Artifact#

Reader for OMMX Artifacts.

An artifact is an OCI container image that stores OMMX data (instances, solutions, sample sets, etc.) as layers.

>>> artifact = Artifact.load("ghcr.io/jij-inc/ommx/random_lp_instance:4303c7f")
>>> print(artifact.image_name)
ghcr.io/jij-inc/ommx/random_lp_instance:4303c7f

get_blob(digest_or_descriptor: Any) bytes#

Get raw bytes of a blob by digest string or Descriptor.

get_dataframe(descriptor: Descriptor) Any#

Get a pandas DataFrame from an artifact layer stored by add_dataframe().

get_instance(descriptor: Optional[Descriptor] = None) Instance#

Get an instance from the artifact.

  • If descriptor is None, returns the first instance layer.

  • If descriptor is given, returns the instance for that specific layer.

Raises ValueError if no instance layer is found.

get_json(descriptor: Descriptor) Any#

Get a JSON object from an artifact layer stored by add_json().

get_layer(descriptor: Descriptor) Any#

Get the layer object corresponding to the descriptor.

Dynamically dispatched based on media_type:

  • application/org.ommx.v1.instance returns Instance

  • application/org.ommx.v1.solution returns Solution

  • application/vnd.numpy returns a numpy array

get_layer_descriptor(digest: str) Descriptor#

Look up a layer descriptor by digest.

get_ndarray(descriptor: Descriptor) Any#

Get a numpy array from an artifact layer stored by add_ndarray().

get_parametric_instance(descriptor: Optional[Descriptor] = None) ParametricInstance#

Get a parametric instance from the artifact.

  • If descriptor is None, returns the first parametric instance layer.

  • If descriptor is given, returns the parametric instance for that specific layer.

Raises ValueError if no parametric instance layer is found.

get_sample_set(descriptor: Optional[Descriptor] = None) SampleSet#

Get a sample set from the artifact.

  • If descriptor is None, returns the first sample set layer.

  • If descriptor is given, returns the sample set for that specific layer.

Raises ValueError if no sample set layer is found.

get_solution(descriptor: Optional[Descriptor] = None) Solution#

Get a solution from the artifact.

  • If descriptor is None, returns the first solution layer.

  • If descriptor is given, returns the solution for that specific layer.

Raises ValueError if no solution layer is found.

load(image_name: str) Artifact#

Load an artifact stored as a container image in local or remote registry.

If the image is not found in local registry, it will try to pull from remote registry.

>>> artifact = Artifact.load("ghcr.io/jij-inc/ommx/random_lp_instance:4303c7f")
>>> print(artifact.image_name)
ghcr.io/jij-inc/ommx/random_lp_instance:4303c7f

load_archive(path: str | PathLike | Path) Artifact#

Load an artifact stored as a single file or directory.

>>> artifact = Artifact.load_archive("data/random_lp_instance.ommx")
>>> print(artifact.image_name)
ghcr.io/jij-inc/ommx/random_lp_instance:...

push() None#

Push the artifact to remote registry.

property annotations: dict[str, str]#

Read-only property.

Annotations in the artifact manifest.

property image_name: Optional[str]#

Read-only property.

property instance: Instance#

Read-only property.

The first instance layer in the artifact.

Raises ValueError if no instance layer is found. For multiple instance layers, use get_instance() with a descriptor.

property layers: list[Descriptor]#

Read-only property.

property parametric_instance: ParametricInstance#

Read-only property.

The first parametric instance layer in the artifact.

Raises ValueError if no parametric instance layer is found. For multiple parametric instance layers, use get_parametric_instance() with a descriptor.

property sample_set: SampleSet#

Read-only property.

The first sample set layer in the artifact.

Raises ValueError if no sample set layer is found. For multiple sample set layers, use get_sample_set() with a descriptor.

property solution: Solution#

Read-only property.

The first solution layer in the artifact.

Raises ValueError if no solution layer is found. For multiple solution layers, use get_solution() with a descriptor.