Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linspace bugs / essential features #858

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qupulse/program/linspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def _add_iteration_node(self, node: LinSpaceIter):
self.add_node(node.body)

if node.length > 1:
self.iterations[-1] = node.length
self.iterations[-1] = node.length - 1
label, jmp = self.new_loop(node.length - 1)
self.commands.append(label)
self.add_node(node.body)
Expand Down
69 changes: 65 additions & 4 deletions tests/program/linspace_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,67 @@ def test_commands(self):
self.assertEqual(self.commands, commands)


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'})
Expand Down Expand Up @@ -74,7 +135,7 @@ def setUp(self):

LoopLabel(1, 99),

Increment(0, -2.0, key_0),
Increment(0, -1.99, key_0),
Increment(1, 0.02, key_1),
Wait(TimeType(10 ** 6)),

Expand Down Expand Up @@ -131,8 +192,8 @@ def setUp(self):

LoopLabel(1, 99),

Increment(0, 1e-3 + -200 * 1e-2, key_0),
Increment(1, 0.02 + -200 * -3e-3, key_1),
Increment(0, 1e-3 + -199 * 1e-2, key_0),
Increment(1, 0.02 + -199 * -3e-3, key_1),
Wait(TimeType(10 ** 6)),

LoopLabel(2, 199),
Expand Down Expand Up @@ -223,7 +284,7 @@ def setUp(self):
Set(0, -0.4),
Set(1, -0.3),
Wait(TimeType(10 ** 5)),
Increment(0, -2.0, key_0),
Increment(0, -1.99, key_0),
Increment(1, 0.02, key_1),
Wait(TimeType(10 ** 6)),
Set(0, 0.05),
Expand Down
Loading