cosmiq.formats#

Versioned JSON formats: cosmiq.schedule/1 and cosmiq.device/1, and the remote jobs’ cosmiq.job/1 and cosmiq.result/1 (see the Remote jobs guide).

cosmiq.schedule/1 is a skeleton (register, device, channels with kinds and breakpoint times, fixed values, a slot table with stable ids such as “amplitude.v[1]”) plus rows [B, n_slots] float64, an optional jacobian (\(\partial\,\mathrm{slots}/\partial\,\mathrm{parameters}\), sparse per row, or one shared J with affine: true when the writer asks for it), and a sha256 digest of the canonical skeleton. Slots are the free values, in CHANNEL_ORDER then index order.

cosmiq.job/1 and cosmiq.result/1 are plain JSON objects (dicts): dumps checks one against its model and writes it canonically, and loads returns it checked. A job forbids unknown fields, a result ignores them (a newer box’s result still reads), and each has its size cap: 1 MiB for a job, 8 MiB for a result.

digest

The sha256 of the canonical skeleton, as "sha256:<hex>" (row values don't change it).

dumps

Canonical JSON.

loads

Parse any cosmiq format (by its "format" field).

schema

The JSON Schema, as committed under schemas/.

Functions

cosmiq.formats.digest(obj: Schedule | ScheduleData) → str#

The sha256 of the canonical skeleton, as “sha256:<hex>” (row values don’t change it).

cosmiq.formats.dumps(obj: Schedule | ScheduleData | DeviceSpec | Mapping[str, Any], *, jacobian_wrt: Mapping[str, Tensor] | None = None, assume_affine: bool = False, indent: int | None = None) → str#

Canonical JSON. With jacobian_wrt (a Schedule only, e.g. dict(program.named_parameters())), adds the Jacobian of the slots with respect to those tensors, computed with autograd: one matrix per batch row (affine: false), exact at these parameter values.

assume_affine=True is your promise that drive() has no value-dependent control flow (no min(w, cap), no if on a value), so that \(\mathrm{slots} = s_0 + J\theta\) for every \(\theta\). Autograd sees one evaluation and can’t verify that. cosmiq checks what it can see (the graph is affine, \(J\) and \(s_0\) are the same in every row, rounding moved no free slot), and writes one shared J with affine: true only when all of that holds; otherwise affine: false.

A mapping is a cosmiq.job/1 or cosmiq.result/1 document (by its “format”): checked against its model and its size cap (1 MiB, 8 MiB) and written as given, canonically. Raises FormatError.

cosmiq.formats.loads(text: str) → ScheduleData | DeviceSpec | dict[str, Any]#

Parse any cosmiq format (by its “format” field). Raises FormatError: unknown fields in physics content, NaN or inf, size limits, a digest mismatch, a bundled device named without its capabilities version.

A cosmiq.job/1 or cosmiq.result/1 document comes back as the parsed dict, checked against its model (a job’s unknown field, or a newer version of either, is refused with what to upgrade). Its size cap (1 MiB, 8 MiB of UTF-8) is checked before the JSON is parsed, from its top-level “format” (_jobs.sniff), and again after.

A schedule keeps the device’s capabilities_version it was written with (ScheduleData.capabilities_version), so the digest always survives a round trip, and dumps(loads(text)) == text for a document written without a Jacobian (which loads doesn’t return) and without indentation. When it names a bundled device whose version here differs, loads still returns it (a re-check against the limits in force is the point of loading it) and warns with a UserWarning: check it again before running it (N-8).

cosmiq.device/1 documents carry their format as “spec_format” (the DeviceSpec field).

cosmiq.formats.schema(kind: Literal['schedule', 'device', 'job', 'result']) → dict[str, Any]#

The JSON Schema, as committed under schemas/.