@@ -63,6 +63,141 @@ def test_output(self):
6363 assert_vm_output_almost_equal (self , self .output , vm .history )
6464
6565
66+ class SequencedRepetitionTest (TestCase ):
67+ def setUp (self ):
68+
69+ base_time = 1e2
70+ rep_factor = 2
71+
72+ wait = AtomicMultiChannelPT (
73+ ConstantPT (f'{ base_time } ' , {'a' : '-1. + idx_a * 0.01' , }),
74+ ConstantPT (f'{ base_time } ' , {'b' : '-0.5 + idx_b * 0.05' })
75+ )
76+
77+ dependent_constant = AtomicMultiChannelPT (
78+ ConstantPT (base_time , {'a' : '-1.0 ' }),
79+ ConstantPT (base_time , {'b' : '-0.5 + idx_b*0.05' ,}),
80+ )
81+
82+ dependent_constant2 = AtomicMultiChannelPT (
83+ ConstantPT (base_time , {'a' : '-0.5 ' }),
84+ ConstantPT (base_time , {'b' : '-0.3 + idx_b*0.05' ,}),
85+ )
86+
87+ #not working
88+ self .pulse_template = (
89+ dependent_constant @
90+ dependent_constant2 .with_repetition (rep_factor ) @
91+ wait .with_iteration ('idx_a' , rep_factor )
92+ ).with_iteration ('idx_b' , rep_factor )
93+
94+ wait_hold = LinSpaceHold (
95+ bases = (- 1.0 , - 0.5 ),
96+ factors = ((0.0 , 0.01 ), (0.05 , 0.0 ),),
97+ duration_base = TimeType .from_float (base_time ),
98+ duration_factors = None
99+ )
100+ dependent_hold_1 = LinSpaceHold (
101+ bases = (- 1.0 , - 0.5 ),
102+ factors = (None , (0.05 ,),),
103+ duration_base = TimeType .from_float (base_time ),
104+ duration_factors = None
105+ )
106+ dependent_hold_2 = LinSpaceHold (
107+ bases = (- 0.5 , - 0.3 ),
108+ factors = (None , (0.05 ,),),
109+ duration_base = TimeType .from_float (base_time ),
110+ duration_factors = None
111+ )
112+
113+ self .program = LinSpaceIter (
114+ length = rep_factor ,
115+ body = (
116+ dependent_hold_1 ,
117+ LinSpaceRepeat (body = (dependent_hold_2 ,), count = rep_factor ),
118+ LinSpaceIter (body = (wait_hold ,), length = rep_factor ),
119+ )
120+ )
121+
122+ self .commands = [
123+ Set (channel = 0 , value = - 1.0 , key = DepKey (factors = ())),
124+ Set (channel = 1 , value = - 0.5 , key = DepKey (factors = (50000000 ,))),
125+ Wait (duration = TimeType (100 , 1 )),
126+
127+ Set (channel = 0 , value = - 0.5 , key = DepKey (factors = ())),
128+ Increment (channel = 1 , value = 0.2 , dependency_key = DepKey (factors = (50000000 ,))),
129+ Wait (duration = TimeType (100 , 1 )),
130+
131+ # This is the repetition
132+ LoopLabel (idx = 0 , count = 1 ),
133+ Wait (duration = TimeType (100 , 1 )),
134+ LoopJmp (idx = 0 ),
135+
136+ Set (channel = 0 , value = - 1.0 , key = DepKey (factors = (0 , 10000000 ))),
137+ Increment (channel = 1 , value = - 0.2 , dependency_key = DepKey (factors = (50000000 ,))),
138+ Wait (duration = TimeType (100 , 1 )),
139+
140+ LoopLabel (idx = 1 , count = 1 ),
141+ Increment (channel = 0 , value = 0.01 , dependency_key = DepKey (factors = (0 , 10000000 ))),
142+ Wait (duration = TimeType (100 , 1 )),
143+ LoopJmp (idx = 1 ),
144+
145+ LoopLabel (idx = 2 , count = 1 ),
146+ Set (channel = 0 , value = - 1.0 , key = DepKey (factors = ())),
147+ Increment (channel = 1 , value = 0.05 , dependency_key = DepKey (factors = (50000000 ,))),
148+ Wait (duration = TimeType (100 , 1 )),
149+ Set (channel = 0 , value = - 0.5 , key = DepKey (factors = ())),
150+ Increment (channel = 1 , value = 0.2 , dependency_key = DepKey (factors = (50000000 ,))),
151+ Wait (duration = TimeType (100 , 1 )),
152+
153+ # next repetition
154+ LoopLabel (idx = 3 , count = 1 ),
155+ Wait (duration = TimeType (100 , 1 )),
156+ LoopJmp (idx = 3 ),
157+
158+ Increment (channel = 0 ,
159+ value = - 0.01 ,
160+ dependency_key = DepKey (factors = (0 , 10000000 ))),
161+ Increment (channel = 1 , value = - 0.2 , dependency_key = DepKey (factors = (50000000 ,))),
162+ Wait (duration = TimeType (100 , 1 )),
163+
164+ LoopLabel (idx = 4 , count = 1 ),
165+ Increment (channel = 0 , value = 0.01 , dependency_key = DepKey (factors = (0 , 10000000 ))),
166+ Wait (duration = TimeType (100 , 1 )),
167+ LoopJmp (idx = 4 ),
168+ LoopJmp (idx = 2 )]
169+
170+ time = TimeType (0 )
171+ self .output = []
172+ for idx_b in range (rep_factor ):
173+ # does not account yet for floating poit errors. We would need to sum here
174+ self .output .append ((time , (- 1.0 , - 0.5 + idx_b * 0.05 )))
175+ time += TimeType .from_float (base_time )
176+
177+ for _ in range (rep_factor ):
178+ self .output .append ((time , (- 0.5 , - 0.3 + idx_b * 0.05 )))
179+ time += TimeType .from_float (base_time )
180+
181+ for idx_a in range (rep_factor ):
182+ self .output .append ((time , (- 1.0 + 0.01 * idx_a , - 0.5 + idx_b * 0.05 )))
183+ time += TimeType .from_float (base_time )
184+
185+ def test_program_1 (self ):
186+ program_builder = LinSpaceBuilder (('a' ,'b' ))
187+ program_1 = self .pulse_template .create_program (program_builder = program_builder )
188+ self .assertEqual ([self .program ], program_1 )
189+
190+ def test_commands_1 (self ):
191+ commands = to_increment_commands ([self .program ])
192+ self .assertEqual (self .commands , commands )
193+
194+ def test_output_1 (self ):
195+ vm = LinSpaceVM (2 )
196+ vm .set_commands (commands = self .commands )
197+ vm .run ()
198+ assert_vm_output_almost_equal (self , self .output , vm .history )
199+
200+
66201class PlainCSDTest (TestCase ):
67202 def setUp (self ):
68203 hold = ConstantPT (10 ** 6 , {'a' : '-1. + idx_a * 0.01' , 'b' : '-.5 + idx_b * 0.02' })
0 commit comments