Skip to content

Commit 47905c0

Browse files
committed
Cleanup test. Originial commands and program work in simulator
1 parent 670e3bc commit 47905c0

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

tests/program/linspace_tests.py

+30-16
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,15 @@ def setUp(self):
6868
hold = ConstantPT(10 ** 6, {'a': '-1. + idx * 0.01'})
6969
hold_random = ConstantPT(10 ** 5, {'a': -.4})
7070
# self.pulse_template = (hold_random@(hold_random@hold).with_repetition(10)@hold_random@hold)\
71-
self.pulse_template = (hold_random@(hold).with_repetition(10))\
72-
.with_iteration('idx', 200)
71+
self.pulse_template = (hold_random @ hold.with_repetition(10)).with_iteration('idx', 200)
7372

7473
self.program = LinSpaceIter(
7574
length=200,
7675
body=(
77-
LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None),
78-
LinSpaceRepeat(
76+
LinSpaceHold(bases=(-.4,), factors=(None,), duration_base=TimeType(10**5), duration_factors=None),
77+
LinSpaceRepeat(body=(
7978
LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None),
80-
10),
79+
), count=10),
8180
# LinSpaceHold(bases=(-.4),factors=None,duration_base=TimeType(10**6),duration_factors=None),
8281
# LinSpaceHold(bases=(-1.,),factors=((0.01,),),duration_base=TimeType(10**6),duration_factors=None)
8382
),)
@@ -86,20 +85,20 @@ def setUp(self):
8685
key = DepKey.from_voltages((0.01,), DEFAULT_INCREMENT_RESOLUTION)
8786

8887
self.commands = [
89-
[Set(channel=0, value=-0.4, key=DepKey(factors=())),
88+
Set(channel=0, value=-0.4, key=DepKey(factors=())),
9089
Wait(duration=TimeType(100000, 1)),
9190
#here is what currently happens:
92-
# Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))),
93-
# Wait(duration=TimeType(1000000, 1)),
94-
# LoopLabel(idx=0, count=9),
95-
# Wait(duration=TimeType(1000000, 1)),
96-
# LoopJmp(idx=0),
97-
#however, i think this is what should happen (maybe also with an additional "Set" before,
98-
#which might cause complications if omitted in other contexts like AWG amplitude:
99-
LoopLabel(idx=0, count=10),
10091
Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))),
10192
Wait(duration=TimeType(1000000, 1)),
93+
LoopLabel(idx=0, count=9),
94+
Wait(duration=TimeType(1000000, 1)),
10295
LoopJmp(idx=0),
96+
#however, i think this is what should happen (maybe also with an additional "Set" before,
97+
#which might cause complications if omitted in other contexts like AWG amplitude:
98+
#LoopLabel(idx=0, count=10),
99+
#Set(channel=0, value=-1.0, key=DepKey(factors=(10000000,))),
100+
#Wait(duration=TimeType(1000000, 1)),
101+
#LoopJmp(idx=0),
103102

104103
LoopLabel(idx=1, count=199),
105104
Set(channel=0, value=-0.4, key=DepKey(factors=())),
@@ -108,12 +107,21 @@ def setUp(self):
108107
Wait(duration=TimeType(1000000, 1)),
109108
LoopLabel(idx=2, count=9),
110109
#also here, an increment 0 may be helpful (at least to be able to force).
111-
Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))),
110+
#Increment(channel=0, value=0, dependency_key=DepKey(factors=(10000000,))),
112111
Wait(duration=TimeType(1000000, 1)),
113112
LoopJmp(idx=2),
114-
LoopJmp(idx=1)]
113+
LoopJmp(idx=1)
115114
]
116115

116+
self.output = []
117+
time = TimeType(0)
118+
for idx in range(200):
119+
self.output.append((time, [-.4]))
120+
time += TimeType(10**5)
121+
self.output.append((time, [-1. + idx * 0.01]))
122+
time += TimeType(10**7)
123+
124+
117125
def test_program(self):
118126
program_builder = LinSpaceBuilder(('a',))
119127
program = self.pulse_template.create_program(program_builder=program_builder)
@@ -123,6 +131,12 @@ def test_commands(self):
123131
commands = to_increment_commands([self.program])
124132
self.assertEqual(self.commands, commands)
125133

134+
def test_output(self):
135+
vm = LinSpaceVM(1)
136+
vm.set_commands(self.commands)
137+
vm.run()
138+
assert_vm_output_almost_equal(self, self.output, vm.history)
139+
126140

127141
class PlainCSDTest(TestCase):
128142
def setUp(self):

0 commit comments

Comments
 (0)