Skip to content

Commit

Permalink
Fix length issue for python < 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
nulinspiratie committed Oct 28, 2024
1 parent 7d85052 commit e9412b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions quam/components/pulses.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions tests/components/pulses/test_waveform_pulse.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Iterable
import numpy as np
import pytest
from quam.components.pulses import WaveformPulse
Expand All @@ -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():
Expand All @@ -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

0 comments on commit e9412b1

Please sign in to comment.