cosmiq.emulator#
The emulator: run a cosmiq program and get its final state, probabilities, expectation values and shots, with exact gradients (see the Emulator guide).
unverified_bypass_count() is the number of calls in this process that ran past a refusal
through an Emulator(..., unverified=...); UnverifiedWarning is what each such call warns.
How a run was done. |
|
What |
|
|
A state-vector emulator of the device a schedule targets (see the Emulator guide). |
The noise of a run: calibration values by key, in the units of |
|
A diagonal observable. |
|
|
A call through |
\(\langle n_i n_j \rangle\), [B, N, N], with \(\langle n_i \rangle\) on the diagonal; empty sites left out pair by pair. |
|
\(\langle n_i \rangle\) per atom, [B, N], empty sites left out (\(E[n_i \cdot \mathrm{pre}_i]/E[\mathrm{pre}_i]\)). |
|
\(\sum_b w_b P(b)\), [B]: |
|
The read bitstring distribution, \([B, 2^N]\) float64 in |
|
The probability of reading any of |
|
How many calls in this process bypassed at least one refusal through an |
Classes
- class cosmiq.emulator.EmulationReport(device: str, torch_device: str, dt: float, n_cells: int, batch_size: int, trajectories: int, shots: int | None, shots_per_trajectory: int | None, effective_sample_size: int | None, noise_used: tuple[str, ...], noise_unused: Mapping[str, str], standard_error: Mapping[str, Tensor], calibration_id: str | None, seed: int | None, chunks: int, checkpointed: bool, wall_seconds: float, notes: tuple[str, ...], infos: Sequence[EngineInfo | None] = (), verified: bool = True, bypassed: tuple[str, ...] = (), reason: str | None = None, tensor: TensorReport | None = None)#
Bases:
objectHow a run was done. Compares by identity.
- device: str#
The device ref the physics came from, “cosmiq-ref-1@1.0.0”.
- shots_per_trajectory: int | None#
The most shots any trajectory gave (shots spread evenly when shots > K).
- effective_sample_size: int | None#
Independent noise draws behind the shots: K when the noise is drawn per trajectory (shots of one trajectory share it), else the number of shots.
- noise_unused: Mapping[str, str]#
Calibration keys left out, and why (
coherence.*andramp.*unless the noise is"hardware": “opt-in: noise=’hardware’”).
- standard_error: Mapping[str, Tensor]#
Per observable, the standard error of its average over the K trajectories (empty when K = 1). Detached.
- checkpointed: bool#
True when each chunk was wrapped in torch.utils.checkpoint (a gradient run in more than one chunk).
- infos: Sequence[EngineInfo | None] = ()#
The engine’s account, per chunk (kept live: a backward pass can replace an entry).
- verified: bool = True#
False when this call bypassed a refusal through
Emulator(..., unverified=...): then no accuracy claim of any kind applies to its result. A tested call through an unverified emulator is verified.
- tensor: TensorReport | None = None#
space="tensor"‘s account (bond dimension, discarded weight, cells), None in the other spaces.
- property estimate_seconds: float#
Time spent on the error control: its probe runs other than the kept one (about half a forward pass).
- property certificate: float | None#
\(\lVert \psi_0^\mathrm{rebuilt} - \psi_0 \rVert_2\) of the adjoint, the largest over the chunks, after a backward pass; None before one, or when no chunk ran the adjoint.
- class cosmiq.emulator.EmulationResult(state: Tensor | None, expectations: Mapping[str, Tensor], shots: tuple[Shots, ...] | None, report: EmulationReport, *, probabilities: Tensor | None = None, samples_only: bool = False)#
Bases:
objectWhat
Emulator.runreturns.state: \(\psi(T)\), [B, D] complex, when the run kept it (keep_state=True), else None;probabilities(): \(|\psi|^2\), or the averaged read distribution, [B, D] float64;expectations: each observable’s value by name, float64, differentiable;shots: oneShotsper batch row in shot mode, else None;report: how the run was done (EmulationReport).
- class cosmiq.emulator.Emulator(device: device | str | None = None, precision: Literal['auto', 'single', 'double'] = 'auto', method: Literal['auto', 'split', 'krylov', 'dense', 'density_matrix'] = 'auto', backend: Literal['auto', 'torch-ref', 'torch-kron', 'triton'] = 'auto', gradient: Literal['auto', 'adjoint', 'checkpoint', 'none', 'trajectory'] = 'auto', tol: float | None = None, samples_only: bool = False, observable: Observable | None = None, max_memory: int | None = None, space: Literal['full', 'blockade', 'tensor'] = 'full', blockade: Literal['kings'] | None = None, unverified: str | None = None, bond_dim: int | None = None)
Bases:
ModuleA state-vector emulator of the device a schedule targets (see the Emulator guide).
emu = cq.Emulator() # CPU, complex128 result = emu.run(program(), observables=[density()]) result.expectations["density"] # [B, N], differentiable
device: the torch device, or None for the schedule’s own (“mps” is refused);precision,method,backend,gradient,tol,max_memory: the engine’s options (EngineOptions); “auto” picks, and the report says what;samples_only: shots only, read as the analog hardware would (a lost atom reads 1);observable: whatforwardreturns, sonn.Sequential(program, emulator)works;space: “full” (the \(2^N\) state space) or “blockade”, the blockade fast mode: allowed only on the registers, programs and observables that were tested (see Claims and limits), everything else refused;blockade="kings"blockades the diagonals of a square lattice; or “tensor”, an MPS run by two-site TDVP, allowed only on the chains, programs and sizes that were tested, everything else refused.bond_dim: space=”tensor“‘s bond dimension: None (the cell’s tested \(\chi\)), or that \(\chi\), 32 at \(N \le 12\) and 64 at \(N = 16\) (the tested values).unverified: None, or the reason you run past refusals for lack of evidence (see “Running outside the tested range” in the Emulator guide): an untested or failed cell then warns (cq.UnverifiedWarning) and runs, and its report saysverified=False. Inspace="blockade", the cells outside its table; in the full space, the density matrix above 12 atoms (its gradient above 10), the trajectory gradient above 6 atoms or in complex64, and either off the CPU. Hard refusals stay hard, and remote sessions,cq.remote.local(), PennyLane andcq.gradients.estimaterefuse such an emulator. Read-only; logged at WARNING when built and when unpickled. No accuracy claim of any kind applies to a result that bypassed a refusal.
last_reportis the report of this emulator’s last successful call (run,forwardorvjp), None before one or after a refused call. Shared across threads, the last writer wins.- property last_report: EmulationReport | None
The report of this emulator’s last successful
run,forwardorvjp; None before one, and after a refused or failed call. Shared across threads, the last writer wins.
- forward(schedule: Schedule) Tensor
The value of
observable(set in the constructor), [B, …]: fornn.Sequential(program, emulator).
- run(schedule: Schedule | ScheduleData, *, observables: Sequence[Observable] = (), shots: int | None = None, noise: Literal['device', 'hardware'] | NoiseModel | None = None, trajectories: int | None = None, seed: int | None = None, spec: DeviceSpec | None = None, dt: float | None = None, keep_state: bool = False, initial: Tensor | None = None) EmulationResult
Evolve every batch row of
scheduleand measure it.schedule: a targetedSchedule(a program’s output), any schedule withspec=, or a loadedScheduleData(no gradients: usevjp). The device’s C6, clock and calibration come from its target, or fromspec.dt: the cell length in µs; the device clock by default. Every breakpoint must be on its grid.observables: what to measure, in expectation (exact over K trajectories).shots: sample this many per row (shot mode).noise: None (ideal), “device” (every noise source in the calibration, except the three “hardware” adds), “hardware” (“device” plus T2 by quantum jumps, the ramp filter and loss during the sequence: forward only, onsplit), or aNoiseModel.trajectories: K. Expectation mode: 100 by default. Shot mode: one per shot up to 1,000, then shots spread over them. One whenever the noise draws nothing per trajectory.seed: the root of every draw; None draws one from torch’s generator, and the report records it.keep_state: keep \(\psi(T)\) in the result (noiseless runs only; not undermethod="density_matrix").initial: start from this state instead of \(|g\ldots g\rangle\) (noiseless runs only): complex, \([2^N]\) for every row or \([B, 2^N]\), inCONVENTIONS.state_order, each row of norm 1. Gradients flow back to it, so runs and gates chain into one torch graph.
Through an
Emulator(..., unverified=...), a call that bypasses a refusal warns (cq.UnverifiedWarning) and reportsverified=False.
- vjp(data: ScheduleData, observables: Sequence[Observable], cotangents: Mapping[str, Any], *, noise: Literal['device', 'hardware'] | NoiseModel | None = None, trajectories: int | None = None, seed: int | None = None, spec: DeviceSpec | None = None, dt: float | None = None) Tensor
\(\partial L/\partial\,\mathrm{slots}\), [B, n_slots] float64 on the CPU, for \(L = \sum_\mathrm{name} \sum \mathrm{cotangent} \cdot \mathrm{value}\) over
observables: the server side of a gradient. The client multiplies it by its document’s Jacobian (\(\partial\,\mathrm{slots}/\partial\,\mathrm{parameters}\)) to get its parameters’ gradient.datais a loaded document’s ScheduleData; its slots (thefreevalues, in wire order) become leaf tensors.cotangentshas one [B, …] array per observable, by name, shaped like its value.Through an
Emulator(..., unverified=...), a call that bypasses a refusal warns (cq.UnverifiedWarning) and reportsverified=Falseinlast_report.
- class cosmiq.emulator.NoiseModel(values: Mapping[str, float | Tensor] | None = None, *, calibration_id: str | None = None, unused: Mapping[str, str] | None = None, hardware: bool = False)#
Bases:
objectThe noise of a run: calibration values by key, in the units of
NoiseModel.KEYS.Build it from a device (
from_spec), or by hand:NoiseModel({"laser.amplitude_sigma": 0.02}). Values are checked when it’s built (known key, finite, in range); a value of a key inDIFFERENTIABLEmay be a 0-d tensor that requires grad. Alaser.detuning_offset_sigmaneeds acalibration_id: the offset is drawn once per snapshot, from its id.hardware=True(whatnoise="hardware"builds) also readscoherence.*(T2, by quantum jumps) andramp.*(the ramp filter), and makesloss.sequence_probabilityact during the sequence; such a model takes gradients only undermethod="density_matrix"orgradient="trajectory". Without it, those keys are refused in a model by hand and kept inunused, with the reason, byfrom_spec.- KEYS: ClassVar[Mapping[str, CalibrationKey]] = mappingproxy({'filling.vacancy_probability': CalibrationKey(unit='probability', low=0.0, high=1.0, meaning='an empty trap before the sequence', low_open=False), 'spam.preparation_error': CalibrationKey(unit='probability', low=0.0, high=1.0, meaning='an atom not prepared in the ground state', low_open=False), 'spam.false_positive': CalibrationKey(unit='probability', low=0.0, high=1.0, meaning='a ground atom read as Rydberg', low_open=False), 'spam.false_negative': CalibrationKey(unit='probability', low=0.0, high=1.0, meaning='a Rydberg atom read as ground', low_open=False), 'loss.sequence_probability': CalibrationKey(unit='probability', low=0.0, high=1.0, meaning='an atom lost during the sequence, per shot', low_open=False), 'coherence.t1_rydberg': CalibrationKey(unit='us', low=0.0, high=None, meaning='T1 of the Rydberg state', low_open=True), 'coherence.dephasing_rate': CalibrationKey(unit='1/us', low=0.0, high=None, meaning='the residual dephasing rate, 1/T2', low_open=False), 'thermal.doppler_sigma': CalibrationKey(unit='rad/us', low=0.0, high=None, meaning='the rms Doppler detuning, per atom', low_open=False), 'thermal.position_sigma': CalibrationKey(unit='um', low=0.0, high=None, meaning='the rms error of each position coordinate', low_open=False), 'laser.amplitude_sigma': CalibrationKey(unit='relative', low=0.0, high=None, meaning='the rms error of the Rabi frequency, shot to shot', low_open=False), 'laser.waist': CalibrationKey(unit='um', low=0.0, high=None, meaning="the global beam's waist, for the amplitude profile", low_open=True), 'laser.detuning_sigma': CalibrationKey(unit='rad/us', low=0.0, high=None, meaning='the rms error of the global detuning, shot to shot', low_open=False), 'laser.detuning_offset_sigma': CalibrationKey(unit='rad/us', low=0.0, high=None, meaning='the rms calibration offset of the global detuning', low_open=False), 'local.crosstalk': CalibrationKey(unit='relative', low=0.0, high=1.0, meaning='the fraction of the local detuning that spills onto a neighbour', low_open=False), 'local.weight_sigma': CalibrationKey(unit='relative', low=0.0, high=None, meaning='the rms error of the local weights', low_open=False), 'ramp.rabi_correction_52ns': CalibrationKey(unit='factor', low=0.0, high=1.0, meaning='the Rabi frequency reached in a 52 ns ramp', low_open=True), 'ramp.rabi_correction_100ns': CalibrationKey(unit='factor', low=0.0, high=1.0, meaning='the Rabi frequency reached in a 100 ns ramp', low_open=True), 'ramp.rabi_correction_200ns': CalibrationKey(unit='factor', low=0.0, high=1.0, meaning='the Rabi frequency reached in a 200 ns ramp', low_open=True)})#
Every calibration key, its unit and its range (cosmiq.devices’ vocabulary).
- property calibration_id: str | None#
The snapshot it came from. It seeds the detuning’s calibration offset.
- property hardware: bool#
True for
noise="hardware"‘s model: T2, the ramp filter and loss during the sequence act.
- classmethod from_spec(spec: DeviceSpec, include: Iterable[str] = GROUPS, *, hardware: bool = False) NoiseModel#
Every mechanism the spec’s calibration has values for, in the groups (or keys) of
include.cosmiq-ref-1-idealhas none, so its model is empty and its runs are exactly the noiseless ones.hardware=Truereads the groups “coherence” and “ramp” too (asking for them without it raises FormatError); it refuses ramp corrections that don’t agree on one filter (ramp_fit).
- classmethod none() NoiseModel#
No noise at all: the same as
noise=None.
- without(*names: str) NoiseModel#
The same model without these groups (“spam”) or keys (“spam.false_positive”).
- scaled(factor: float) NoiseModel#
Every noise strength times
factor(0 turns it off, 0.5 halves it): the sigmas and probabilities, the rates 1/T1 and the dephasing rate (so T1 becomes T1/factor), and the ramp filter’s time constant. The beam waist isn’t an error, so it stays; a probability scaled above 1 raises FormatError.scaled(0)never raises: T1 is then infinite (the key moves tounused) and the ramp corrections are all 1.
- active(key: str) bool#
True when
keyis in the model and acts: a non-zero value, or for the ramp corrections a filter with a time constant above 0.
- class cosmiq.emulator.Observable(name: str)#
Bases:
objectA diagonal observable. Build one with
density(),correlation(),probabilities(),projector(...)ordiagonal(...);namekeys the result’sexpectations.
- class cosmiq.emulator.UnverifiedWarning(message: str = '', *, hits: Sequence[Hit] = (), reason: str = '', site: str = '')
Bases:
UserWarningA call through
Emulator(..., unverified="reason")bypassed at least one refusal: no accuracy claim applies to its result.codes,refusals,hits: what it bypassed;reason: the emulator’sunverified;site: “file:line” where the emulator was built.
Functions
- cosmiq.emulator.correlation() Observable#
\(\langle n_i n_j \rangle\), [B, N, N], with \(\langle n_i \rangle\) on the diagonal; empty sites left out pair by pair.
- cosmiq.emulator.density() Observable#
\(\langle n_i \rangle\) per atom, [B, N], empty sites left out (\(E[n_i \cdot \mathrm{pre}_i]/E[\mathrm{pre}_i]\)).
- cosmiq.emulator.diagonal(weights_or_fn: Any, *, name: str = 'diagonal') Observable#
\(\sum_b w_b P(b)\), [B]:
weights_or_fnis a \([2^N]\) weight vector (array or tensor, which may require grad), or a function of the bits,fn(bits) -> [2^N], wherebitsis a \([2^N, N]\) int64 tensor (row \(b\) is basis state \(b\), atom 0 first).
- cosmiq.emulator.probabilities(*, allow_large: bool = False) Observable#
The read bitstring distribution, \([B, 2^N]\) float64 in
CONVENTIONS.state_order(atom 0 the most significant bit). Refused above 2 GiB unlessallow_large=True.