diff --git a/src/qibolab/pulses.py b/src/qibolab/pulses.py index 01f8797e9..a20d7a8b3 100644 --- a/src/qibolab/pulses.py +++ b/src/qibolab/pulses.py @@ -218,7 +218,7 @@ def eval(value: str) -> "PulseShape": shape_name = re.findall(r"(\w+)", value)[0] if shape_name not in globals(): raise ValueError(f"shape {value} not found") - shape_parameters = re.findall(r"[\w+\d\.\d]+", value)[1:] + shape_parameters = re.findall(r"[-\w+\d\.\d]+", value)[1:] # TODO: create multiple tests to prove regex working correctly return globals()[shape_name](*shape_parameters) diff --git a/tests/test_pulses.py b/tests/test_pulses.py index 8135b3c75..9939b8fae 100644 --- a/tests/test_pulses.py +++ b/tests/test_pulses.py @@ -275,12 +275,18 @@ def test_pulses_pulseshape_sampling_rate(shape): def test_pulseshape_eval(): shape = PulseShape.eval("Rectangular()") assert isinstance(shape, Rectangular) - shape = PulseShape.eval("Drag(5, 1)") - assert isinstance(shape, Drag) with pytest.raises(ValueError): shape = PulseShape.eval("Ciao()") +@pytest.mark.parametrize("rel_sigma,beta", [(5, 1), (5, -1), (3, -0.03), (4, 0.02)]) +def test_drag_shape_eval(rel_sigma, beta): + shape = PulseShape.eval(f"Drag({rel_sigma}, {beta})") + assert isinstance(shape, Drag) + assert shape.rel_sigma == rel_sigma + assert shape.beta == beta + + def test_raise_shapeiniterror(): shape = Rectangular() with pytest.raises(ShapeInitError):