Skip to content

Commit

Permalink
test: assert_qua_programs function to reduce code repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Sep 17, 2024
1 parent fad27be commit 69457a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
14 changes: 9 additions & 5 deletions tests/instruments/test_qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ def assert_ast_nodes(node1, node2):
assert n1 == n2


def assert_qua_programs(experiment, target_experiment):
"""Compare QUA program generated by the driver with the target program."""
build = experiment.build(QuaDummyBuilder())
target_build = target_experiment.build(QuaDummyBuilder())
assert_ast_nodes(build.script, target_build.script)
assert_ast_nodes(build.result_analysis, target_build.result_analysis)


def test_program():
qd = Pulse(duration=40, amplitude=0.05, envelope=Gaussian(rel_sigma=0.2))
ro = Readout(
Expand Down Expand Up @@ -113,8 +121,4 @@ def test_program():
r1.buffer(options.nshots).save(f"{op}_readout_I")
r2.buffer(options.nshots).save(f"{op}_readout_Q")

# compare experiment generated by the driver with the target
build = experiment.build(QuaDummyBuilder())
target_build = target_experiment.build(QuaDummyBuilder())
assert_ast_nodes(build.script, target_build.script)
assert_ast_nodes(build.result_analysis, target_build.result_analysis)
assert_qua_programs(experiment, target_experiment)
15 changes: 4 additions & 11 deletions tests/integration/test_qm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from qibolab.pulses import Delay
from qibolab.sweeper import Parameter, Sweeper

from ..instruments.test_qm import QuaDummyBuilder, assert_ast_nodes
from ..instruments.test_qm import assert_qua_programs


def test_qubit_flux(dummy_qrc):
Expand Down Expand Up @@ -165,11 +165,7 @@ def test_qubit_flux(dummy_qrc):
r3.buffer(8).buffer(4).average().save(f"{ro1}_1/acquisition_I")
r4.buffer(8).buffer(4).average().save(f"{ro1}_1/acquisition_Q")

# compare experiment generated by the driver with the target
build = experiment.build(QuaDummyBuilder())
target_build = target_experiment.build(QuaDummyBuilder())
assert_ast_nodes(build.script, target_build.script)
assert_ast_nodes(build.result_analysis, target_build.result_analysis)
assert_qua_programs(experiment, target_experiment)


def test_rabi_sweeps(dummy_qrc):
Expand Down Expand Up @@ -309,8 +305,5 @@ def test_rabi_sweeps(dummy_qrc):
with stream_processing():
r1.buffer(5).buffer(5).average().save(f"{ro1}_2/acquisition_shots")
r2.buffer(5).buffer(5).average().save(f"{ro2}_3/acquisition_shots")
# compare experiment generated by the driver with the target
build = experiment.build(QuaDummyBuilder())
target_build = target_experiment.build(QuaDummyBuilder())
assert_ast_nodes(build.script, target_build.script)
assert_ast_nodes(build.result_analysis, target_build.result_analysis)

assert_qua_programs(experiment, target_experiment)

0 comments on commit 69457a2

Please sign in to comment.