From 56846812b47c14d37d9e788e8bf39c7fed548245 Mon Sep 17 00:00:00 2001 From: Nomos11 <82180697+Nomos11@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:34:53 +0200 Subject: [PATCH 1/5] first failing test for pre_dep!=post_dep --- tests/program/linspace_tests.py | 75 ++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/tests/program/linspace_tests.py b/tests/program/linspace_tests.py index 461b583c..f153061e 100644 --- a/tests/program/linspace_tests.py +++ b/tests/program/linspace_tests.py @@ -65,25 +65,25 @@ def test_output(self): class SequencedRepetitionTest(TestCase): def setUp(self): - + base_time = 1e2 rep_factor = 2 - + wait = AtomicMultiChannelPT( ConstantPT(f'{base_time}', {'a': '-1. + idx_a * 0.01', }), ConstantPT(f'{base_time}', {'b': '-0.5 + idx_b * 0.05'}) ) - + dependent_constant = AtomicMultiChannelPT( ConstantPT(base_time, {'a': '-1.0 '}), - ConstantPT(base_time, {'b': '-0.5 + idx_b*0.05',}), + ConstantPT(base_time, {'b': '-0.5 + idx_b*0.05',}), ) - + dependent_constant2 = AtomicMultiChannelPT( ConstantPT(base_time, {'a': '-0.5 '}), - ConstantPT(base_time, {'b': '-0.3 + idx_b*0.05',}), + ConstantPT(base_time, {'b': '-0.3 + idx_b*0.05',}), ) - + #not working self.pulse_template = ( dependent_constant @ @@ -198,6 +198,67 @@ def test_output_1(self): assert_vm_output_almost_equal(self, self.output, vm.history) +class PrePostDepTest(TestCase): + def setUp(self): + hold = ConstantPT(10 ** 6, {'a': '-1. + idx * 0.01'}) + hold_random = ConstantPT(10 ** 5, {'a': -.4}) + # self.pulse_template = (hold_random@(hold_random@hold).with_repetition(10)@hold_random@hold)\ + self.pulse_template = (hold_random@(hold).with_repetition(10))\ + .with_iteration('idx', 200) + + self.program = LinSpaceIter( + length=200, + body=( + LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None), + LinSpaceRepeat( + LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None), + 10), + # LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None), + # LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None) + ),) + + + key = DepKey.from_voltages((0.01,), DEFAULT_INCREMENT_RESOLUTION) + + self.commands = [ + [Set(channel=0, value=-0.4, key=DepKey(factors=())), + Wait(duration=TimeType(100000, 1)), + #here is what currently happens: + # Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), + # Wait(duration=TimeType(1000000, 1)), + # LoopLabel(idx=0, count=9), + # Wait(duration=TimeType(1000000, 1)), + # LoopJmp(idx=0), + #however, i think this is what should happen (maybe also with an additional "Set" before, + #which might cause complications if omitted in other contexts like AWG amplitude: + LoopLabel(idx=0, count=10), + Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), + Wait(duration=TimeType(1000000, 1)), + LoopJmp(idx=0), + + LoopLabel(idx=1, count=199), + Set(channel=0, value=-0.4, key=DepKey(factors=())), + Wait(duration=TimeType(100000, 1)), + Increment(channel=0, value=0.01, dependency_key=DepKey(factors=(10000000,))), + Wait(duration=TimeType(1000000, 1)), + LoopLabel(idx=2, count=9), + #also here, an increment 0 may be helpful (at least to be able to force). + Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))), + Wait(duration=TimeType(1000000, 1)), + LoopJmp(idx=2), + LoopJmp(idx=1)] + ] + + def test_program(self): + program_builder = LinSpaceBuilder(('a',)) + program = self.pulse_template.create_program(program_builder=program_builder) + self.assertEqual([self.program], program) + + def test_commands(self): + commands = to_increment_commands([self.program]) + self.assertEqual(self.commands, commands) + + class PlainCSDTest(TestCase): def setUp(self): hold = ConstantPT(10**6, {'a': '-1. + idx_a * 0.01', 'b': '-.5 + idx_b * 0.02'}) From 28b8228595bcead95ba850dc088efef85c36bebf Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Fri, 21 Jun 2024 13:42:20 +0200 Subject: [PATCH 2/5] Correct type annotation in LinspaceVM --- qupulse/program/linspace.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qupulse/program/linspace.py b/qupulse/program/linspace.py index ad681a96..9ea4e442 100644 --- a/qupulse/program/linspace.py +++ b/qupulse/program/linspace.py @@ -499,7 +499,7 @@ def __init__(self, channels: int, self.time = TimeType(0) self.registers = tuple({} for _ in range(channels)) - self.history: List[Tuple[TimeType, Tuple[float, ...]]] = [] + self.history: List[Tuple[TimeType, List[float]]] = [] self.commands = None self.label_targets = None @@ -523,9 +523,13 @@ def change_state(self, cmd: Union[Set, Increment, Wait, Play]): self.time += dt t += dt elif isinstance(cmd, Wait): - self.history.append( - (self.time, self.current_values.copy()) - ) + if self.history and self.history[-1][1] == self.current_values: + # do not create noop entries + pass + else: + self.history.append( + (self.time, self.current_values.copy()) + ) self.time += cmd.duration elif isinstance(cmd, Set): self.current_values[cmd.channel] = cmd.value From bd98812e80960f1e0b670b6bf5764ae5c25eb419 Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Fri, 21 Jun 2024 13:42:57 +0200 Subject: [PATCH 3/5] Cleanup test. Originial commands and program work in simulator --- tests/program/linspace_tests.py | 47 +++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/tests/program/linspace_tests.py b/tests/program/linspace_tests.py index f153061e..72569c1d 100644 --- a/tests/program/linspace_tests.py +++ b/tests/program/linspace_tests.py @@ -203,16 +203,15 @@ def setUp(self): hold = ConstantPT(10 ** 6, {'a': '-1. + idx * 0.01'}) hold_random = ConstantPT(10 ** 5, {'a': -.4}) # self.pulse_template = (hold_random@(hold_random@hold).with_repetition(10)@hold_random@hold)\ - self.pulse_template = (hold_random@(hold).with_repetition(10))\ - .with_iteration('idx', 200) + self.pulse_template = (hold_random @ hold.with_repetition(10)).with_iteration('idx', 200) self.program = LinSpaceIter( length=200, body=( - LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None), - LinSpaceRepeat( + LinSpaceHold(bases=(-.4,), factors=(None,), duration_base=TimeType(10**5), duration_factors=None), + LinSpaceRepeat(body=( LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None), - 10), + ), count=10), # LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None), # LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None) ),) @@ -221,21 +220,20 @@ def setUp(self): key = DepKey.from_voltages((0.01,), DEFAULT_INCREMENT_RESOLUTION) self.commands = [ - [Set(channel=0, value=-0.4, key=DepKey(factors=())), + Set(channel=0, value=-0.4, key=DepKey(factors=())), Wait(duration=TimeType(100000, 1)), #here is what currently happens: - # Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), - # Wait(duration=TimeType(1000000, 1)), - # LoopLabel(idx=0, count=9), - # Wait(duration=TimeType(1000000, 1)), - # LoopJmp(idx=0), - #however, i think this is what should happen (maybe also with an additional "Set" before, - #which might cause complications if omitted in other contexts like AWG amplitude: - LoopLabel(idx=0, count=10), Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), Wait(duration=TimeType(1000000, 1)), + LoopLabel(idx=0, count=9), + Wait(duration=TimeType(1000000, 1)), LoopJmp(idx=0), - + #however, i think this is what should happen (maybe also with an additional "Set" before, + #which might cause complications if omitted in other contexts like AWG amplitude: + #LoopLabel(idx=0, count=10), + #Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), + #Wait(duration=TimeType(1000000, 1)), + #LoopJmp(idx=0), LoopLabel(idx=1, count=199), Set(channel=0, value=-0.4, key=DepKey(factors=())), Wait(duration=TimeType(100000, 1)), @@ -243,12 +241,21 @@ def setUp(self): Wait(duration=TimeType(1000000, 1)), LoopLabel(idx=2, count=9), #also here, an increment 0 may be helpful (at least to be able to force). - Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))), + #Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))), Wait(duration=TimeType(1000000, 1)), LoopJmp(idx=2), - LoopJmp(idx=1)] + LoopJmp(idx=1) ] + self.output = [] + time = TimeType(0) + for idx in range(200): + self.output.append((time, [-.4])) + time += TimeType(10**5) + self.output.append((time, [-1. + idx * 0.01])) + time += TimeType(10**7) + + def test_program(self): program_builder = LinSpaceBuilder(('a',)) program = self.pulse_template.create_program(program_builder=program_builder) @@ -258,6 +265,12 @@ def test_commands(self): commands = to_increment_commands([self.program]) self.assertEqual(self.commands, commands) + def test_output(self): + vm = LinSpaceVM(1) + vm.set_commands(self.commands) + vm.run() + assert_vm_output_almost_equal(self, self.output, vm.history) + class PlainCSDTest(TestCase): def setUp(self): From 49c099e0918bbc36bec9cb710c8b8b5e6c3b0e3c Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Fri, 3 Jan 2025 16:26:41 +0100 Subject: [PATCH 4/5] Remove dead code and comments --- tests/program/linspace_tests.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/program/linspace_tests.py b/tests/program/linspace_tests.py index 72569c1d..557978fc 100644 --- a/tests/program/linspace_tests.py +++ b/tests/program/linspace_tests.py @@ -216,32 +216,20 @@ def setUp(self): # LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None) ),) - - key = DepKey.from_voltages((0.01,), DEFAULT_INCREMENT_RESOLUTION) - self.commands = [ Set(channel=0, value=-0.4, key=DepKey(factors=())), Wait(duration=TimeType(100000, 1)), - #here is what currently happens: Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), Wait(duration=TimeType(1000000, 1)), LoopLabel(idx=0, count=9), Wait(duration=TimeType(1000000, 1)), LoopJmp(idx=0), - #however, i think this is what should happen (maybe also with an additional "Set" before, - #which might cause complications if omitted in other contexts like AWG amplitude: - #LoopLabel(idx=0, count=10), - #Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))), - #Wait(duration=TimeType(1000000, 1)), - #LoopJmp(idx=0), LoopLabel(idx=1, count=199), Set(channel=0, value=-0.4, key=DepKey(factors=())), Wait(duration=TimeType(100000, 1)), Increment(channel=0, value=0.01, dependency_key=DepKey(factors=(10000000,))), Wait(duration=TimeType(1000000, 1)), LoopLabel(idx=2, count=9), - #also here, an increment 0 may be helpful (at least to be able to force). - #Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))), Wait(duration=TimeType(1000000, 1)), LoopJmp(idx=2), LoopJmp(idx=1) From 110ca5faa546d23f4d0ecdd40d7aac0fb7fc63ad Mon Sep 17 00:00:00 2001 From: Simon Humpohl Date: Thu, 23 Jan 2025 15:27:07 +0100 Subject: [PATCH 5/5] Remove noop's from expected VM output --- tests/program/linspace_tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/program/linspace_tests.py b/tests/program/linspace_tests.py index 557978fc..da0b15ef 100644 --- a/tests/program/linspace_tests.py +++ b/tests/program/linspace_tests.py @@ -174,8 +174,9 @@ def setUp(self): self.output.append((time, (-1.0, -0.5 + idx_b * 0.05))) time += TimeType.from_float(base_time) + # The VM does not create noop entries + self.output.append((time, (-0.5, -0.3 + idx_b * 0.05))) for _ in range(rep_factor): - self.output.append((time, (-0.5, -0.3 + idx_b * 0.05))) time += TimeType.from_float(base_time) for idx_a in range(rep_factor):