Skip to content

Commit

Permalink
Temporary state file for tests (#476)
Browse files Browse the repository at this point in the history
* replace submit with compile

* add temporary file for integration test using state_file.
  • Loading branch information
weinbe58 authored Aug 30, 2023
1 parent 8629403 commit 6fcaf8e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
95 changes: 66 additions & 29 deletions tests/test_hardware_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_integration_scale():
location.Square(1)
.rydberg.detuning.uniform.apply(seq)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

panel = json.loads(job.json())
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_integration_neg():
location.Square(1)
.rydberg.detuning.uniform.apply(seq)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

panel = json.loads(job.json())
Expand Down Expand Up @@ -129,7 +129,9 @@ def test_integration_poly_order_err():
def test_integration_poly_const():
## constant
seq = Poly(coeffs=[1], duration=0.5).append(Constant(1, duration=0.5))
job = location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(12)
job = (
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(12)
)

panel = json.loads(job.json())
print(panel)
Expand All @@ -151,7 +153,9 @@ def test_integration_poly_const():
def test_integration_poly_linear():
## linear
seq = Poly(coeffs=[1, 2], duration=0.5).append(Constant(2, duration=0.5))
job = location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
job = (
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)
)

panel = json.loads(job.json())
print(panel)
Expand Down Expand Up @@ -182,7 +186,7 @@ def my_cos(time):
wf = Sample(wv, Interpolation.Constant, dt)
## phase can only have piecewise constant.
with pytest.raises(ValueError):
location.Square(1).rydberg.detuning.uniform.apply(wf).quera.mock().submit(10)
location.Square(1).rydberg.detuning.uniform.apply(wf).quera.mock().compile(10)


def test_integration_slice_linear_const():
Expand All @@ -193,7 +197,7 @@ def test_integration_slice_linear_const():
location.Square(1)
.rydberg.detuning.uniform.apply(seq)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

panel = json.loads(job.json())
Expand All @@ -216,7 +220,9 @@ def test_integration_slice_linear_const():

def test_integration_slice_linear_no_stop():
seq = Linear(start=0.0, stop=1.0, duration=1.0)[0:]
job = location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
job = (
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)
)

panel = json.loads(job.json())

Expand All @@ -238,7 +244,9 @@ def test_integration_slice_linear_no_stop():

def test_integration_slice_linear_no_start():
seq = Linear(start=0.0, stop=1.0, duration=1.0)[:1.0]
job = location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
job = (
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)
)

panel = json.loads(job.json())

Expand All @@ -260,25 +268,25 @@ def test_integration_slice_linear_no_start():
def test_integration_slice_linear_error_neg_start():
with pytest.raises(ValueError):
seq = Linear(start=0.0, stop=1.0, duration=1.0)[-0.1:1.0]
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)


def test_integration_slice_linear_error_exceed_stop():
with pytest.raises(ValueError):
seq = Linear(start=0.0, stop=1.0, duration=1.0)[:4.0]
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)


def test_integration_slice_linear_error_revese():
with pytest.raises(ValueError):
seq = Linear(start=0.0, stop=1.0, duration=1.0)[0.5:0.0]
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)


def test_integration_slice_linear_error_same_vals_nofield():
with pytest.raises(ValueError):
seq = Linear(start=0.0, stop=1.0, duration=1.0)[0.0:0.0]
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.detuning.uniform.apply(seq).quera.mock().compile(10)


def test_integration_phase():
Expand All @@ -289,7 +297,7 @@ def test_integration_phase():
)
.record("a")
.quera.mock()
.submit(10)
.compile(10)
)

panel = json.loads(batch.json())
Expand Down Expand Up @@ -323,15 +331,17 @@ def test_intergration_phase_nonconst_err():

seq = Poly(coeffs=[1, 2], duration=0.5)
with pytest.raises(ValueError):
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().compile(
10
)


def test_integration_phase_linear():
job = (
location.Square(1)
.rydberg.rabi.phase.uniform.linear(start=1, stop=1, duration=1)
.quera.mock()
.submit(10)
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -355,7 +365,10 @@ def test_integration_phase_linear():
def test_integration_phase_polyconst():
seq = Poly(coeffs=[1], duration=0.5)
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -380,7 +393,10 @@ def test_integration_phase_slice():
##[Further investigate!]
seq = Poly(coeffs=[1], duration=1.0)[0:0.5]
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -404,7 +420,10 @@ def test_integration_phase_slice():
def test_integration_phase_scale():
seq = 3.0 * Constant(value=1.0, duration=1.0)
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -428,7 +447,10 @@ def test_integration_phase_scale():
def test_integration_phase_neg():
seq = -Constant(value=1.0, duration=1.0)
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -452,7 +474,10 @@ def test_integration_phase_neg():
def test_integration_phase_slice_no_start():
seq = Poly(coeffs=[1], duration=1.0)[:0.5]
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -477,7 +502,10 @@ def test_integration_phase_slice_no_stop():
##[Further investigate!]
seq = Poly(coeffs=[1], duration=0.5)[0:]
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -502,7 +530,10 @@ def test_integration_phase_slice_same_start_stop():
##[Further investigate!]
seq = Poly(coeffs=[1], duration=0.5)[0:0.5]
job = (
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1)
.rydberg.rabi.phase.uniform.apply(seq)
.quera.mock()
.compile(10)
)

panel = json.loads(job.json())
Expand All @@ -526,19 +557,25 @@ def test_integration_phase_slice_same_start_stop():
def test_integration_phase_slice_error_neg_start():
with pytest.raises(ValueError):
seq = Poly(coeffs=[1], duration=1.0)[-0.1:0.5]
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().compile(
10
)


def test_integration_phase_slice_error_exceed_stop():
with pytest.raises(ValueError):
seq = Poly(coeffs=[1], duration=1.0)[0:2.0]
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().compile(
10
)


def test_integration_phase_slice_error_reverse():
with pytest.raises(ValueError):
seq = Poly(coeffs=[1], duration=1.0)[2.0:0.0]
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().submit(10)
location.Square(1).rydberg.rabi.phase.uniform.apply(seq).quera.mock().compile(
10
)


def test_integration_phase_sampl_linear_err():
Expand Down Expand Up @@ -574,7 +611,7 @@ def test_integration_batchassign_assign():
.rydberg.detuning.uniform.apply(Constant("initial_detuning", "time"))
.batch_assign(initial_detuning=[1, 2, 3, 4], time=[2, 4, 5, 0.6])
.quera.mock()
.submit(10)
.compile(10)
)

assert len(batch.tasks) == 4
Expand All @@ -589,7 +626,7 @@ def test_integration_record():
.record("a")
.piecewise_constant(durations=[0.3], values=["a"])
.quera.mock()
.submit(10)
.compile(10)
)

panel = json.loads(job.json())
Expand Down Expand Up @@ -624,7 +661,7 @@ def my_cos(time):
.rydberg.rabi.phase.uniform.fn(my_cos, duration=1.0)
.sample(dt=0.5)
.quera.mock()
.submit(10)
.compile(10)
)

panel = json.loads(job.json())
Expand Down Expand Up @@ -661,7 +698,7 @@ def my_cos(time):
.rydberg.detuning.uniform.fn(my_cos, duration=1.0)
.sample(dt=0.5)
.quera.mock()
.submit(10)
.compile(10)
)

panel = json.loads(job.json())
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mock_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
rabi_amplitude_max=15,
)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

# print(len(quantum_task.task_result.shot_outputs))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parallelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_parallel_task():
)
.parallelize(10.0)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

assert quantum_batch.tasks[0].parallel_decoder
Expand All @@ -46,4 +46,4 @@ def test_error_parallel_noatom():
"final_detuning",
"final_detuning",
],
).parallelize(10.0).quera.mock().submit(shots=1)
).parallelize(10.0).quera.mock().compile(shots=1)
7 changes: 5 additions & 2 deletions tests/test_report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bloqade.ir.location import ListOfLocations
import tempfile

prog = (
ListOfLocations()
Expand Down Expand Up @@ -26,8 +27,10 @@
rabi_amplitude_max=15,
)
)
future = prog.quera.mock().submit(shots=100)
future.fetch()

with tempfile.NamedTemporaryFile() as f:
future = prog.quera.mock(state_file=f.name).submit(shots=100)
future.pull()

print(future.report().bitstrings)
print(future.report().counts)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_schema_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_local_no_global():
.scale(0.5)
.apply(seq)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

panel = json.loads(batch.json())
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_local_global():
.scale(0.5)
.apply(seq)
.quera.mock()
.submit(shots=10)
.compile(shots=10)
)

panel = json.loads(job.json())
Expand Down

0 comments on commit 6fcaf8e

Please sign in to comment.