Exporting to Braket and Pulser#
A cosmiq program can be exported to the formats of two other neutral-atom toolkits: Amazon Braket’s analog Hamiltonian simulation (AHS) programs, and Pulser’s sequences. You can then run it with their simulators, or send it on with their tools. Neither Braket nor Pulser needs to be installed to export: the exports are plain JSON.
import json
import cosmiq as cq
spec = cq.devices.get("cosmiq-ref-1")
schedule = program() # a program targeted at cosmiq-ref-1, as in the quickstart
ahs = cq.export.to_braket_ahs(schedule, spec=spec) # a dict: Braket's AHS program, in SI units
sequence = cq.export.to_pulser(schedule, spec=spec) # a str: Pulser's sequence, as JSON
to_braket_ahs(schedule, *, local_detuning="rewrite", spec=None)returns a dict that Braket reads as an AHS program. Times, positions and rates are converted to seconds, metres and rad/s.to_pulser(schedule, *, spec=None)returns Pulser’s JSON for the sequence, on a Pulser device built from cosmiq’s device.specis the device the schedule was checked for. It can be left out for a bundled device such as cosmiq-ref-1; for a device of your own, pass its spec.batch_indexpicks one row of a batched schedule: Braket and Pulser take one program at a time.
local_detuning. A local detuning shifts some atoms more than others. cosmiq and Braket
write that shift with opposite signs. "rewrite", the default, rewrites the program into
Braket’s convention, as QuEra’s hardware takes it, and checks the result against the device’s
limits again. "direct" passes cosmiq’s shift through unchanged, for simulators that take
either sign.
Running the exports#
On Braket’s local simulator (install it with pip install amazon-braket-sdk):
from braket.devices import LocalSimulator
from braket.ir.ahs import Program
task = LocalSimulator("braket_ahs").run(Program.parse_obj(ahs), shots=1000)
result = task.result()
On Pulser’s emulator (the pulser package):
from pulser import Sequence
from pulser_simulation import QutipEmulator
seq = Sequence.from_abstract_repr(sequence)
result = QutipEmulator.from_sequence(seq).run()
cq.export.shots_to_braket_bits(shots) turns cosmiq’s shots into Braket’s bit layout, for
comparing results side by side.
How the exports are checked#
Both exports are run on Braket’s and Pulser’s own simulators and checked against cosmiq’s emulator: they give the same results, within tested tolerances (the evidence). No claim is made about any real QPU.
Limits#
The check covers small programs only, without noise. Braket’s own conversion of times can make
a sudden change in a program take effect one simulator step late. Pulser takes only its own
interaction strength, so to_pulser refuses a device with another one, and it needs times in
whole nanoseconds. Braket’s results can’t show an atom lost during the sequence.