-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rydberg-h-factory
- Loading branch information
Showing
2 changed files
with
121 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,121 +1,60 @@ | ||
from bloqade.ir import Sequence, rydberg, detuning, Uniform, Linear, ScaledLocations | ||
from bloqade.ir.location import Square | ||
from bloqade.atom_arrangement import Chain | ||
from unittest.mock import patch | ||
import bloqade.ir.routine.quera | ||
from bloqade.task.batch import RemoteBatch | ||
import glob | ||
import os | ||
|
||
# import bloqade.lattice as lattice | ||
import pytest | ||
|
||
n_atoms = 11 | ||
lattice_const = 5.9 | ||
|
||
rabi_amplitude_values = [0.0, 15.8, 15.8, 0.0] | ||
rabi_detuning_values = [-16.33, -16.33, "delta_end", "delta_end"] | ||
durations = [0.8, "sweep_time", 0.8] | ||
@patch("bloqade.ir.routine.quera.MockBackend") | ||
def test_batch_error(*args): | ||
backend = bloqade.ir.routine.quera.MockBackend() | ||
|
||
ordered_state_2D_prog = ( | ||
Square(n_atoms, lattice_const) | ||
.rydberg.rabi.amplitude.uniform.piecewise_linear(durations, rabi_amplitude_values) | ||
.detuning.uniform.piecewise_linear(durations, rabi_detuning_values) | ||
) | ||
backend.submit_task.side_effect = ValueError("some random error") | ||
backend.dict.return_value = {"state_file": ".mock_state.txt"} | ||
|
||
ordered_state_2D_job = ordered_state_2D_prog.assign(delta_end=42.66, sweep_time=2.4) | ||
with pytest.raises(RemoteBatch.SubmissionException): | ||
( | ||
Chain(5, 6.1) | ||
.rydberg.detuning.uniform.linear(-10, 10, 3.0) | ||
.quera.mock() | ||
.run_async(100) | ||
) | ||
|
||
pbin = ordered_state_2D_job.quera.aquila() | ||
error_files = glob.glob("partial-batch-errors-*") | ||
batch_files = glob.glob("partial-batch-future-*") | ||
|
||
pbin = pbin.parse_circuit() | ||
for error_file, batch_file in zip(error_files, batch_files): | ||
os.remove(error_file) | ||
os.remove(batch_file) | ||
|
||
# pbin.circuit.sequence | ||
assert len(error_files) == 1 | ||
assert len(batch_files) == 1 | ||
|
||
|
||
# dict interface | ||
seq = Sequence( | ||
{ | ||
rydberg: { | ||
detuning: { | ||
Uniform: Linear(start=1.0, stop="x", duration=3.0), | ||
ScaledLocations({1: 1.0, 2: 2.0}): Linear( | ||
start=1.0, stop="x", duration=3.0 | ||
), | ||
}, | ||
} | ||
} | ||
) | ||
@patch("bloqade.ir.routine.quera.MockBackend") | ||
def test_batch_warn(*args): | ||
backend = bloqade.ir.routine.quera.MockBackend() | ||
|
||
backend.submit_task.side_effect = ValueError("some random error") | ||
backend.dict.return_value = {"state_file": ".mock_state.txt"} | ||
|
||
# job = HardwareBatchResult.load_json("example-3-2d-ordered-state-job.json") | ||
with pytest.warns(): | ||
( | ||
Chain(5, 6.1) | ||
.rydberg.detuning.uniform.linear(-10, 10, 3.0) | ||
.quera.mock() | ||
.run_async(100, ignore_submission_error=True) | ||
) | ||
|
||
# res = job.report() | ||
error_files = glob.glob("partial-batch-errors-*") | ||
batch_files = glob.glob("partial-batch-future-*") | ||
|
||
for error_file, batch_file in zip(error_files, batch_files): | ||
os.remove(error_file) | ||
os.remove(batch_file) | ||
|
||
# print(lattice.Square(3).apply(seq).__lattice__) | ||
# print(lattice.Square(3).apply(seq).braket(nshots=1000).run_async().report().dataframe) | ||
# print("bitstring") | ||
# print(lattice.Square(3).apply(seq).braket(nshots=1000).run_async().report().bitstring) | ||
|
||
# # pipe interface | ||
# report = ( | ||
# lattice.Square(3) | ||
# .rydberg.detuning.uniform.apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .location(2) | ||
# .scale(3.0) | ||
# .apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .rydberg.rabi.amplitude.uniform | ||
# .apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .assign(x=10) | ||
# .braket(nshots=1000) | ||
# .run_async() | ||
# .report() | ||
# ) | ||
|
||
# print(report) | ||
# print(report.bitstring) | ||
# print(report.dataframe) | ||
|
||
# lattice.Square(3).rydberg.detuning.location(2).location(3).apply( | ||
# Linear(start=1.0, stop="x", duration=3.0) | ||
# ).location(3).location(4).apply(Linear(start=1.0, stop="x", duration=3.0)).braket( | ||
# nshots=1000 | ||
# ).run_async() | ||
|
||
# # start.rydberg.detuning.location(2).location(3) | ||
|
||
|
||
# prog = ( | ||
# lattice.Square(3) | ||
# .rydberg.detuning.uniform.apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .location(2) | ||
# .scale(3.0) | ||
# .apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .hyperfine.rabi.amplitude.location(2) | ||
# .apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .assign(x=1.0) | ||
# .multiplex(10.0).braket(nshots=1000) | ||
# .run_async() | ||
# .report() | ||
# .dataframe.groupby(by=["x"]) | ||
# .count() | ||
# ) | ||
|
||
# ( | ||
# lattice.Square(3) | ||
# .rydberg.detuning.uniform.apply(Linear(start=1.0, stop="x", duration=3.0)) | ||
# .multiplex.quera | ||
# ) | ||
|
||
|
||
# wf = ( | ||
# Linear(start=1.0, stop=2.0, duration=2.0) | ||
# .scale(2.0) | ||
# .append(Linear(start=1.0, stop=2.0, duration=2.0)) | ||
# ) | ||
|
||
|
||
# prog = ( | ||
# lattice.Square(3) | ||
# .hyperfine.detuning.location(1) | ||
# .scale(2.0) | ||
# .piecewise_linear(coeffs=[1.0, 2.0, 3.0]) | ||
# .location(2) | ||
# .constant(value=2.0, duration="x") | ||
# ) | ||
|
||
# prog.seq | ||
# prog.lattice | ||
assert len(error_files) == 1 | ||
assert len(batch_files) == 1 |