qdk_chemistry.remote.job module

Persistent job handle for QDK/Chemistry.

A Job records algorithm metadata, content hashes, and status for cached computations. Instances serialise to JSON so that results can be recovered across sessions.

class qdk_chemistry.remote.job.Job(*, job_id, backend, backend_config, backend_state, algorithm_info=None, status='submitted', submitted_at=None, file_path=None, run_hash=None, input_hashes=None, output_hashes=None)[source]

Bases: object

Persistent handle for a cached computation.

Instances serialise to a JSON file on disk, making them the canonical record of a cached algorithm run.

Parameters:
job_id

Short unique identifier for this job.

backend

Registered backend name (e.g. "local").

backend_config

Dict of configuration that was passed to the backend constructor (pool, gpus, host, …). Stored so the backend can be re-created from scratch.

backend_state

Opaque dict written by the backend during submit. Contains whatever the backend needs to poll / cancel / fetch (operation IDs, remote paths, PIDs, …).

algorithm_info

Dict with type, name, settings of the algorithm that was submitted.

status

Last-known status string.

submitted_at

ISO-8601 timestamp of submission.

file_path

Path to the job file on disk (None if not persisted yet).

run_hash

Deterministic hash of the algorithm, settings, and inputs. Used for cache lookups. None if not computed.

input_hashes

Per-item content hashes of the submitted inputs, keyed by argument name (e.g. "arg_0", "charge"). None if not recorded.

output_hashes

Per-item result descriptors. Each entry is a dict with "hash" and "type" keys. Primitives also carry a "value" key so they can be reconstructed without a cache backend. Populated when results are fetched. None until results are retrieved.

__init__(*, job_id, backend, backend_config, backend_state, algorithm_info=None, status='submitted', submitted_at=None, file_path=None, run_hash=None, input_hashes=None, output_hashes=None)[source]

Initialise a Job from its constituent parts.

Parameters:
to_dict()[source]

Return a JSON-safe dictionary representing this job.

Return type:

dict[str, Any]

save(path=None)[source]

Write the job file to disk.

Return type:

Path

Parameters:

path (str | Path | None) – Explicit file path. If None, uses file_path (which must have been set earlier, e.g. via job_dir at submit time).

Returns:

The path the file was written to.

Raises:

ValueError – If no path is available.

classmethod load(path)[source]

Reconstruct a Job from a previously saved file.

Return type:

Job

Parameters:

path (str | Path) – Path to a *.job.json file.

Returns:

A fully re-hydrated Job.

classmethod discover(directory)[source]

Find all job files in a directory.

Return type:

list[Job]

Parameters:

directory (str | Path) – Folder to scan (non-recursively) for *.job.json files.

Returns:

List of Job instances, sorted by submitted_at (oldest first).

property is_terminal: bool[source]

Whether the job has reached a final state.