From 45c199913756cace6aa5721dd169a2a628ceb416 Mon Sep 17 00:00:00 2001 From: Sebbe Blokhuizen Date: Mon, 3 Aug 2026 14:16:14 +0200 Subject: [PATCH 1/2] parse shorthand notation as a single constant tendency --- docs/source/tendencies.rst | 2 ++ docs/source/yaml_format.rst | 6 ++++-- tests/test_yaml_parser.py | 20 ++++++++++++++------ waveform_editor/yaml/yaml_parser.py | 20 ++++++++++++++++++++ 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/docs/source/tendencies.rst b/docs/source/tendencies.rst index 0dd3bd45..697f6618 100644 --- a/docs/source/tendencies.rst +++ b/docs/source/tendencies.rst @@ -20,6 +20,8 @@ Most tendencies accept the following parameters to define their time interval. Y .. note:: The :ref:`Piecewise Linear Tendency ` is an exception and derives its time interval solely from its ``time`` parameter list. It does *not* accept ``start``, ``duration``, or ``end``. +.. _constant-tendency: + Constant Tendency ================= diff --git a/docs/source/yaml_format.rst b/docs/source/yaml_format.rst index 72fd8d7c..7928d0f4 100644 --- a/docs/source/yaml_format.rst +++ b/docs/source/yaml_format.rst @@ -108,11 +108,13 @@ a list of waveforms, or a single number (float or integer). Refer to the :ref:`Available Tendencies ` documentation for details on the different tendency types and their parameters. - 2. **Constant Value:** A simple number (integer or float) defines a constant waveform over time. + 2. **Constant Value:** A bare number (integer or float) or string defines a constant waveform over time, equivalent to a single :ref:`constant tendency `. .. code-block:: yaml - ec_launchers/beam(1)/phase/angle: -1.65898 # Constant value + ec_launchers/beam(1)/phase/angle: -1.65898 # Constant float value + pulse_schedule/ec/mode: 3 # Constant int value + core_sources/source(1)/identifier/name: ec # Constant string value 3. **Empty Waveform:** An empty list ``[{}]`` defines a waveform that is constantly zero. diff --git a/tests/test_yaml_parser.py b/tests/test_yaml_parser.py index 45d0da9a..03b55e67 100644 --- a/tests/test_yaml_parser.py +++ b/tests/test_yaml_parser.py @@ -132,18 +132,26 @@ def test_scientific_notation(yaml_parser): def test_constant_shorthand_notation(yaml_parser): - """Test if shorthand notation is parsed correctly.""" + """Test if shorthand notation is parsed as a constant tendency.""" - waveforms = {"waveform: 5": 5, "waveform: 1.23": 1.23} + waveforms = { + "waveform: 5": (5, int), + "waveform: 1.23": (1.23, float), + "waveform: test": ("test", str), + } - for waveform, expected_value in waveforms.items(): + for waveform, (expected_value, expected_type) in waveforms.items(): waveform = yaml_parser.parse_waveform(waveform) - assert isinstance(waveform, DerivedWaveform) - assert waveform.yaml == expected_value + assert isinstance(waveform, Waveform) + assert len(waveform.tendencies) == 1 + assert isinstance(waveform.tendencies[0], ConstantTendency) + assert waveform.value_type is expected_type assert not waveform.annotations - assert waveform.dependencies == set() assert not yaml_parser.parse_errors + _, values = waveform.get_value() + assert all(v == expected_value for v in values) + def test_load_yaml(config): """Test if yaml is loaded correctly.""" diff --git a/waveform_editor/yaml/yaml_parser.py b/waveform_editor/yaml/yaml_parser.py index 60ad2f94..0d69da5a 100644 --- a/waveform_editor/yaml/yaml_parser.py +++ b/waveform_editor/yaml/yaml_parser.py @@ -165,6 +165,26 @@ def parse_waveform(self, yaml_str): name=name, dd_version=dd_version, ) + # Shorthand notation for waveforms containing a constant tendency, e.g. + # ec_launchers/beam(1)/phase/angle: -1.65898 # float + # pulse_schedule/ec/mode: 3 # int + # core_sources/source(1)/identifier/name: ec # string + elif isinstance(waveform, (int, float)) or ( + "'" not in waveform and '"' not in waveform + ): + waveform = Waveform( + waveform=[ + { + "user_type": "constant", + "user_value": waveform, + "line_number": line_number, + } + ], + yaml_str=yaml_str, + line_number=line_number, + name=name, + dd_version=dd_version, + ) else: waveform = DerivedWaveform( yaml_str, name, self.config, dd_version=dd_version From 99f978a0263cc3db19365d45b53820f68327a5c2 Mon Sep 17 00:00:00 2001 From: Sebbe Blokhuizen Date: Mon, 3 Aug 2026 14:21:47 +0200 Subject: [PATCH 2/2] ruff --- tests/test_yaml_parser.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_yaml_parser.py b/tests/test_yaml_parser.py index 03b55e67..51068f9f 100644 --- a/tests/test_yaml_parser.py +++ b/tests/test_yaml_parser.py @@ -2,7 +2,6 @@ from pytest import approx from waveform_editor.configuration import WaveformConfiguration -from waveform_editor.derived_waveform import DerivedWaveform from waveform_editor.tendencies.constant import ConstantTendency from waveform_editor.tendencies.linear import LinearTendency from waveform_editor.tendencies.periodic.sawtooth_wave import SawtoothWaveTendency