From 9220a7c4188815cbf9dbd95b3cd3e12ae3804220 Mon Sep 17 00:00:00 2001 From: Tobias Ahrens Date: Wed, 18 Oct 2023 15:56:54 +0200 Subject: [PATCH] Add a comman table property to the sequencer class Often a command table is associated with a specific sequencer code. This commit simplt adds a property as a "storage" in the sequencer class for a command table. There is no logic attached to this other then storing. --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 1 + docs/source/conf.py | 11 +++++++---- src/zhinst/toolkit/sequence.py | 25 +++++++++++++++++++------ tests/test_sequence.py | 15 ++++++++++++++- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 21898e1c..b88d402e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.10.0 hooks: - id: black - repo: https://github.com/PyCQA/isort diff --git a/CHANGELOG.md b/CHANGELOG.md index 03fb54d3..222b81be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * The function `enable_qccs_mode` of the HDAWG driver now accept an optional argument to select the QCCS generation. It's advised to set it to 2 (gen2) when the HDAWG is operated with PQSC together with SHF instruments, and set it to 1 (gen1) when the HDAWG is operated with PQSC together with UHFQA instruments. +* Add command table property to the sequencer class to have a simple way to store them together. ## Version 0.6.1 * Deep gets on nodes with keywords returns an enum like the regular get. diff --git a/docs/source/conf.py b/docs/source/conf.py index ab8f2ad9..e109f48b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -83,7 +83,7 @@ # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] -html_css_files = ['zhinst-sphinx-theme/css/custom.css'] +html_css_files = ["zhinst-sphinx-theme/css/custom.css"] html_theme_options = { "logo": { @@ -111,7 +111,10 @@ # Spelling # sphinxcontrib.spelling configuration file -spelling_word_list_filename='spelling_wordlist.txt' +spelling_word_list_filename = "spelling_wordlist.txt" # Show suggestion in console output -spelling_show_suggestions=False -spelling_exclude_patterns=['examples/*.nblink', 'source/_static/zhinst-sphinx-theme/**/*'] +spelling_show_suggestions = False +spelling_exclude_patterns = [ + "examples/*.nblink", + "source/_static/zhinst-sphinx-theme/**/*", +] diff --git a/src/zhinst/toolkit/sequence.py b/src/zhinst/toolkit/sequence.py index c39e0ce2..e2d48797 100644 --- a/src/zhinst/toolkit/sequence.py +++ b/src/zhinst/toolkit/sequence.py @@ -1,5 +1,6 @@ """Custom sequence code class.""" from zhinst.toolkit.waveform import Waveforms +from zhinst.toolkit.command_table import CommandTable import re import typing as t @@ -57,10 +58,12 @@ def __init__( *, constants: t.Dict[str, float] = None, waveforms: Waveforms = None, + command_table: CommandTable = None, ): self._partial_seq = code if code else "" self._constants = constants if constants else {} self._waveforms = waveforms + self._command_table = command_table def __str__(self) -> str: return self.to_string() @@ -102,31 +105,41 @@ def to_string(self, *, waveform_snippet: bool = True) -> str: return sequence @property - def code(self): + def code(self) -> str: """Code of the Sequence.""" return self._partial_seq @code.setter - def code(self, value): + def code(self, value: str) -> None: """Code of the Sequence.""" self._partial_seq = value @property - def constants(self): + def constants(self) -> t.Dict[str, float]: """Constants of the Sequence.""" return self._constants @constants.setter - def constants(self, value): + def constants(self, value: t.Dict[str, float]) -> None: """Constants of the Sequence.""" self._constants = value @property - def waveforms(self): + def waveforms(self) -> Waveforms: """Waveforms of the Sequence.""" return self._waveforms @waveforms.setter - def waveforms(self, value): + def waveforms(self, value: Waveforms) -> None: """Waveforms of the Sequence.""" self._waveforms = value + + @property + def command_table(self) -> CommandTable: + """Command table of the Sequence.""" + return self._command_table + + @command_table.setter + def command_table(self, value: CommandTable) -> None: + """Command table of the Sequence.""" + self._waveforms = value diff --git a/tests/test_sequence.py b/tests/test_sequence.py index 02a96c8e..9f9ccd8f 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -1,6 +1,6 @@ import numpy as np -from zhinst.toolkit import Sequence, Waveforms +from zhinst.toolkit import Sequence, Waveforms, CommandTable def test_assignment(): @@ -105,3 +105,16 @@ def test_to_string_existing_constant(): } ...""" ) + + +def test_setting_command_table(): + sequencer = Sequence() + ct = CommandTable() + sequencer.command_table = ct + assert sequencer.command_table == ct + + +def test_setting_command_table_constructor(): + ct = CommandTable() + sequencer = Sequence(command_table=ct) + assert sequencer.command_table == ct