From 7c4d0abefbb5f5a5ccd5fce258767072921ebd44 Mon Sep 17 00:00:00 2001 From: Yuan Ren Date: Fri, 1 Mar 2024 16:36:41 -0800 Subject: [PATCH 1/3] Add seq duration --- src/broadbean/sequence.py | 11 +++++++++++ tests/test_sequence.py | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/src/broadbean/sequence.py b/src/broadbean/sequence.py index a2b557c1..25d4e848 100644 --- a/src/broadbean/sequence.py +++ b/src/broadbean/sequence.py @@ -634,6 +634,17 @@ def points(self): for elem in self._data.values(): total += elem.points return total + + @property + def duration(self) -> float: + """ + Returns the duration in seconds of the sequence. + """ + duration = 0.0 + for pos, elem in self._data.items(): + nrep = self._sequencing[pos]['nrep'] + duration += nrep * elem.duration + return duration def element(self, pos): """ diff --git a/tests/test_sequence.py b/tests/test_sequence.py index f06d6887..49edd8d5 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -329,6 +329,14 @@ def test_add_subsequence_raises(protosequence1, squarepulse_baseelem): doublemainseq.addSubSequence(1, mainseq) +################################################## +# Sequence properties + +def test_duration(protosequence1, protosequence2): + assert np.round(protosequence1.duration, 12) == 50e-6 + assert np.round(protosequence2.duration, 12) == 75e-6 + + ################################################## # AWG settings From 6323b907ac128bb8b6de87125f61ca570fa6f291 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:45:46 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/broadbean/sequence.py | 2 +- tests/test_sequence.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/broadbean/sequence.py b/src/broadbean/sequence.py index 25d4e848..026ed1db 100644 --- a/src/broadbean/sequence.py +++ b/src/broadbean/sequence.py @@ -634,7 +634,7 @@ def points(self): for elem in self._data.values(): total += elem.points return total - + @property def duration(self) -> float: """ diff --git a/tests/test_sequence.py b/tests/test_sequence.py index 49edd8d5..6250fbbc 100644 --- a/tests/test_sequence.py +++ b/tests/test_sequence.py @@ -331,7 +331,7 @@ def test_add_subsequence_raises(protosequence1, squarepulse_baseelem): ################################################## # Sequence properties - + def test_duration(protosequence1, protosequence2): assert np.round(protosequence1.duration, 12) == 50e-6 assert np.round(protosequence2.duration, 12) == 75e-6 From 10a37d52d3f4847d3227a52e2a478e9ae1f38a8f Mon Sep 17 00:00:00 2001 From: Yuan Ren Date: Fri, 1 Mar 2024 22:06:30 -0800 Subject: [PATCH 3/3] Fix darker error --- src/broadbean/sequence.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/broadbean/sequence.py b/src/broadbean/sequence.py index 25d4e848..091fc72e 100644 --- a/src/broadbean/sequence.py +++ b/src/broadbean/sequence.py @@ -642,7 +642,7 @@ def duration(self) -> float: """ duration = 0.0 for pos, elem in self._data.items(): - nrep = self._sequencing[pos]['nrep'] + nrep = self._sequencing[pos]["nrep"] duration += nrep * elem.duration return duration