From 03deed3ab5a0eb60ea6566172af71903591c0e26 Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Tue, 29 Aug 2023 09:37:03 +0200 Subject: [PATCH 1/3] Skip seqc marker data test if prerequisites not installed --- tests/_program/seqc_tests.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/_program/seqc_tests.py b/tests/_program/seqc_tests.py index 75644fdf..16c5b8be 100644 --- a/tests/_program/seqc_tests.py +++ b/tests/_program/seqc_tests.py @@ -27,6 +27,10 @@ except ImportError: zhinst = None +try: + import numba +except ImportError: + numba = None def take(n, iterable): "Return first n items of the iterable as a list" @@ -63,6 +67,7 @@ def test_dynamic_rate_reduction(self): self.assertEqual(min(max_rate, n), dyn_n) + @unittest.skipIf(zhinst is None and numba is None, "BinaryWaveform.from_sampled backend missing") def test_marker_data(self): channel_1_data = np.linspace(-0.3, 0.4, num=192) channel_2_data = np.linspace(-0.1, 0.1, num=192) From d65a99ce21287262ced2cd8ead0f29ae57c9510b Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Tue, 29 Aug 2023 09:44:30 +0200 Subject: [PATCH 2/3] Make test skip dependent on exception instead of hard coding dependencies --- tests/_program/seqc_tests.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/_program/seqc_tests.py b/tests/_program/seqc_tests.py index 16c5b8be..8761d496 100644 --- a/tests/_program/seqc_tests.py +++ b/tests/_program/seqc_tests.py @@ -14,6 +14,7 @@ from qupulse.parameter_scope import DictScope from qupulse.program.loop import Loop +from qupulse.hardware.util import zhinst_voltage_to_uint16 from qupulse._program.waveforms import ConstantWaveform from qupulse._program.seqc import BinaryWaveform, loop_to_seqc, WaveformPlayback, Repeat, SteppingRepeat, Scope,\ to_node_clusters, find_sharable_waveforms, mark_sharable_waveforms, UserRegisterManager, HDAWGProgramManager,\ @@ -27,10 +28,15 @@ except ImportError: zhinst = None +# This block checks if zhinst_voltage_to_uint16 works. A failing implementation (due to missing dependencies) +# skips tests further down try: - import numba -except ImportError: - numba = None + zhinst_voltage_to_uint16(np.zeros(16), np.zeros(16), + (np.zeros(16), np.zeros(16), np.zeros(16), np.zeros(16))) +except AttributeError: + # prerequisites not installed + zhinst_voltage_to_uint16 = None + def take(n, iterable): "Return first n items of the iterable as a list" @@ -67,7 +73,7 @@ def test_dynamic_rate_reduction(self): self.assertEqual(min(max_rate, n), dyn_n) - @unittest.skipIf(zhinst is None and numba is None, "BinaryWaveform.from_sampled backend missing") + @unittest.skipIf(zhinst_voltage_to_uint16 is None, "BinaryWaveform.from_sampled backend missing") def test_marker_data(self): channel_1_data = np.linspace(-0.3, 0.4, num=192) channel_2_data = np.linspace(-0.1, 0.1, num=192) From 56ed176c70b4b31a29c8e9e079c1cc4bb5fbcc74 Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Tue, 29 Aug 2023 09:45:52 +0200 Subject: [PATCH 3/3] Optimize imports --- tests/_program/seqc_tests.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/_program/seqc_tests.py b/tests/_program/seqc_tests.py index 8761d496..12522ac5 100644 --- a/tests/_program/seqc_tests.py +++ b/tests/_program/seqc_tests.py @@ -1,26 +1,23 @@ -import unittest -from unittest import TestCase, mock -import time -from itertools import zip_longest, islice +import hashlib +import pathlib import sys import tempfile -import pathlib -import hashlib -import random +import time +import unittest +from itertools import zip_longest, islice +from unittest import TestCase, mock import numpy as np +from qupulse._program.seqc import BinaryWaveform, loop_to_seqc, WaveformPlayback, Repeat, SteppingRepeat, Scope, \ + to_node_clusters, find_sharable_waveforms, mark_sharable_waveforms, UserRegisterManager, HDAWGProgramManager, \ + UserRegister, WaveformFileSystem from qupulse.expressions import ExpressionScalar +from qupulse.hardware.util import zhinst_voltage_to_uint16 from qupulse.parameter_scope import DictScope - from qupulse.program.loop import Loop -from qupulse.hardware.util import zhinst_voltage_to_uint16 -from qupulse._program.waveforms import ConstantWaveform -from qupulse._program.seqc import BinaryWaveform, loop_to_seqc, WaveformPlayback, Repeat, SteppingRepeat, Scope,\ - to_node_clusters, find_sharable_waveforms, mark_sharable_waveforms, UserRegisterManager, HDAWGProgramManager,\ - UserRegister, WaveformFileSystem -from qupulse._program.volatile import VolatileRepetitionCount - +from qupulse.program.volatile import VolatileRepetitionCount +from qupulse.program.waveforms import ConstantWaveform from tests.pulses.sequencing_dummies import DummyWaveform try: