Qiskit on cosmiq (cosmiq.qiskit)#
Write circuits in Qiskit, compile them for a cosmiq device, and run them with Qiskit’s
SamplerV2 and EstimatorV2 interfaces on the digital path. Install the extra
with pip install "cosmiq[qiskit]"; it isn’t available on Intel Macs (see
Installation).
from qiskit import QuantumCircuit, transpile
import cosmiq as cq
from cosmiq.qiskit import EstimatorV2, SamplerV2, target
reg = cq.Register.chain(4, 5.0) # qubit q is atom q
tgt = target("cosmiq-ref-1", reg) # cz in range, r and rz everywhere, measure
qc = QuantumCircuit(4)
qc.h(0)
for q in range(3):
qc.cx(q, q + 1)
qc.measure_all()
qc_t = transpile(qc, target=tgt, optimization_level=2)
sampler = SamplerV2(device="cosmiq-ref-1", register=reg, noise=True, seed=7)
counts = sampler.run([qc_t], shots=2000).result()[0].data.meas.get_counts()
An expectation value of the same circuit, with the estimator:
from qiskit.quantum_info import SparsePauliOp
qc_e = transpile(qc.remove_final_measurements(inplace=False), target=tgt)
zz = SparsePauliOp("ZZII").apply_layout(qc_e.layout) # Z on qubits 2 and 3, through the layout
evs = EstimatorV2(device="cosmiq-ref-1", register=reg).run([(qc_e, zz)]).result()[0].data.evs
target(device, register)#
A Qiskit Target for the device and register: cz on every pair of atoms within the
profile’s cz_range_um, r(θ, φ) and rz(λ) on every atom, and measure. Atoms with no
partner in range get no cz. The atoms don’t move, so the register fixes which pairs can
interact. A device with no digital profile is refused (DIGITAL_DEVICE), and so are 17 or more
atoms (DIGITAL_SIZE).
SamplerV2#
SamplerV2(
device="cosmiq-ref-1",
register=reg,
noise=True,
seed=7,
trajectories=None,
default_shots=1024,
max_memory=2 * 1024**3,
)
Results have the shapes of Qiskit’s
StatevectorSampler: per classical register, aBitArrayof the pub’s shape times the shots, in Qiskit’s bit order.noise=True: each shot gets its own draw of the device’s noise, readout errors included.trajectories=caps how many noise draws each parameter point uses, shared out among its shots;Nonegives every shot its own.noise=False: the noise-free circuit.seed: the same seed gives the same counts.Nonedraws a fresh one per pub and records it in the pub’s metadata ("seed").max_memory: the memory the simulator plans its batches for (see the digital path).The metadata also records the device, the profile’s version,
noise, the trajectories and how many batches ran.
EstimatorV2#
EstimatorV2(
device="cosmiq-ref-1",
register=reg,
noise=False,
seed=7,
trajectories=4096,
default_precision=0.0,
max_memory=2 * 1024**3,
)
Results have the shapes of Qiskit’s
StatevectorEstimator:evsandstds, in the pub’s broadcast shape.noise=False: exact expectation values, andstdsof 0.noise=True: the average overtrajectoriesnoise draws (at least 2) per parameter point, withstdsits standard error. Readout errors don’t enter.There is no shot noise: a pub’s
precisionis recorded in the metadata ("target_precision"), not applied.Observables are Pauli sums (I, X, Y, Z); a projector term raises
ValueError, as it does inStatevectorEstimator. Map observables through a transpiled circuit’s layout yourself (SparsePauliOp.apply_layout), as with any Qiskit backend.
Circuits the primitives take#
Only the native instructions
cz,r,rz,measureandbarrier: transpile withtarget()first. Anything else is refused (DIGITAL_GATE).Measurement at the end only: a gate on a measured qubit, a second measurement of a qubit, a reset or control flow is refused (
DIGITAL_MIDCIRCUIT). A classical bit written twice keeps its last value, as inStatevectorSampler.Parameters can stay unbound until the run, as long as each angle is a real affine expression \(\sum a_k \theta_k + b\) (Qiskit’s transpiler keeps them so). Anything else is refused (
DIGITAL_PARAM_EXPR).Up to 16 qubits, no wider than the register, and CZs within range (
DIGITAL_RANGE). Every refusal is raised atrun(), before anything is simulated.The circuit’s global phase is dropped: it changes no probability and no expectation value.
Remote#
Remote jobs aren’t open yet; cq.remote.local() runs the same code on your machine, through
the same path a remote job takes. The primitives take a session=:
local = cq.remote.local() # this machine, no account needed
local_sampler = SamplerV2(session=local, device="cosmiq-ref-1", register=reg)
res = local_sampler.run([qc_t], shots=100).result()
with cq.remote.session("vqpu:cosmiq-ref-1") as qpu: # the virtual QPU, once remote jobs open
res = SamplerV2(session=qpu, register=reg).run([qc_t], shots=100).result()
Sessions: a virtual QPU session (
vqpu:*, whose device is the session’s), orcq.remote.local()withdevice=("cosmiq-ref-1"or"cosmiq-ref-1-ideal"). Anemu:*session is refused (DIGITAL_TARGET), and so is a device with no digital profile (DIGITAL_DEVICE).register=is always needed, to check each CZ’s range.Jobs: large parameter sweeps are split into several jobs automatically. Each job carries the circuit with its parameters unbound, and the rows to run.
Noise: remote jobs always run the device’s full noise, readout errors included, one noise draw per shot. So
noise,trajectoriesandmax_memoryaren’t taken, and neither isseedon the virtual QPU, which picks and keeps each job’s seed. Inlocal(),seed=works as locally.Shots: up to 1,000 per parameter row, which is also the default. More is refused with a
FormatErrornaming the limit.Time: a very large job can run past the virtual QPU’s time limit (at most an hour); it is then stopped, and ends failed with the code
timeout.The remote
EstimatorV2measures the observable’s Pauli terms from shots, as hardware would, so readout errors enter. Itsprecision(0.05 by default) sets the shots per row, and a precision that would need more than 1,000 shots is refused.Results have the local primitives’ shapes. The metadata gives the target, the profile’s version, the seed (
Noneon the virtual QPU) and the number of jobs;cq.remote.verifychecks that a job’s receipt signs the profile’s version.Rehearsals (
train.local(cfg, rehearse=...)) don’t take digital jobs yet: they’re refused before booking (REHEARSAL_DIGITAL).Not offered: digital jobs on
emu:*sessions, atom-loss flags in results, error mitigation, and receipts from the primitives themselves (verifytakes a digital job’s view).
Not claimed#
No gradients through the primitives, no error mitigation, no mid-circuit measurement, no atom
moves or zones, and no GPU. Remote digital jobs are tested on this machine through
cq.remote.local(), not on the virtual QPU (see Remote). Tested sizes and the tests
behind this page are on Claims and limits and
the digital path’s evidence.