From e9412b1f4a83f89baa43442baa19fb633040cdaf Mon Sep 17 00:00:00 2001 From: Serwan Asaad Date: Mon, 28 Oct 2024 12:49:33 +0100 Subject: [PATCH] Fix length issue for python < 3.10 --- quam/components/pulses.py | 3 +++ tests/components/pulses/test_waveform_pulse.py | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/quam/components/pulses.py b/quam/components/pulses.py index d6f9609..e3b2a00 100644 --- a/quam/components/pulses.py +++ b/quam/components/pulses.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from collections.abc import Iterable import numbers import warnings from typing import Any, ClassVar, Dict, List, Optional, Union, Tuple @@ -421,6 +422,8 @@ class WaveformPulse(Pulse): @property def length(self): # noqa: 811 + if not isinstance(self.waveform_I, Iterable): + return None return len(self.waveform_I) @length.setter diff --git a/tests/components/pulses/test_waveform_pulse.py b/tests/components/pulses/test_waveform_pulse.py index 4642aff..a60d552 100644 --- a/tests/components/pulses/test_waveform_pulse.py +++ b/tests/components/pulses/test_waveform_pulse.py @@ -1,3 +1,4 @@ +from collections.abc import Iterable import numpy as np import pytest from quam.components.pulses import WaveformPulse @@ -20,6 +21,7 @@ def test_waveform_pulse_IQ(): assert np.all( pulse.waveform_function() == np.array([1, 2, 3]) + 1.0j * np.array([4, 5, 6]) ) + assert pulse.length def test_waveform_pulse_IQ_mismatch(): @@ -34,3 +36,12 @@ def test_waveform_pulse_to_dict(): "waveform_I": [1, 2, 3], "waveform_Q": [4, 5, 6], } + + +def test_waveform_pulse_length_error(): + with pytest.raises(AttributeError): + pulse = WaveformPulse(waveform_I=[1, 2, 3], length=11) + + pulse = WaveformPulse(waveform_I=[1, 2, 3]) + with pytest.raises(AttributeError): + pulse.length = 11