Skip to content

Commit

Permalink
Cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Oct 19, 2023
1 parent f9d3810 commit ce42fc0
Showing 1 changed file with 44 additions and 58 deletions.
102 changes: 44 additions & 58 deletions tests/program/linspace_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
from qupulse.program.linspace import *


class IdxProgramBuilderTests(TestCase):
def test_single_channel_ramp(self):
hold = ConstantPT(10**6, {'a': '-1. + idx * 0.01'})
ramp = hold.with_iteration('idx', 200)

program_builder = LinSpaceBuilder.from_channel_dict({'a': 0})
program = ramp.create_program(program_builder=program_builder)
class SingleRampTest(TestCase):
def setUp(self):
hold = ConstantPT(10 ** 6, {'a': '-1. + idx * 0.01'})
self.pulse_template = hold.with_iteration('idx', 200)

expected = LinSpaceIter(
self.program = LinSpaceIter(
length=200,
body=(LinSpaceHold(
bases=(-1.,),
Expand All @@ -22,90 +19,79 @@ def test_single_channel_ramp(self):
),)
)

self.assertEqual([expected], program)

def test_single_ramp_increment_commands(self):
program = LinSpaceIter(
length=200,
body=(LinSpaceHold(
bases=(-1.,),
factors=((0.01,),),
duration_base=TimeType(10 ** 6),
duration_factors=None
),)
)

commands = to_increment_commands([program])
key = DepKey.from_voltages((0.01,), DEFAULT_INCREMENT_RESOLUTION)

expected = [
Set(0, -1.0),
self.commands = [
Set(0, -1.0, key),
Wait(TimeType(10 ** 6)),
LoopLabel(0, 199),
Increment(0, 0.01, DepKey.from_voltages((0.01,), DEFAULT_RESOLUTION)),
Increment(0, 0.01, key),
Wait(TimeType(10 ** 6)),
LoopJmp(0)
]
self.assertEqual(expected, commands)

def test_csd_program(self):
hold = ConstantPT(10**6, {'a': '-1. + idx_a * 0.01', 'b': '-.5 + idx_b * 0.02'})
scan_a = hold.with_iteration('idx_a', 200)
csd = scan_a.with_iteration('idx_b', 100)
def test_program(self):
program_builder = LinSpaceBuilder(('a',))
program = self.pulse_template.create_program(program_builder=program_builder)
self.assertEqual([self.program], program)

program_builder = LinSpaceBuilder.from_channel_dict({'a': 0, 'b': 1})
program = csd.create_program(program_builder=program_builder)
def test_commands(self):
commands = to_increment_commands([self.program])
self.assertEqual(self.commands, commands)

expected = LinSpaceIter(length=100, body=(LinSpaceIter(
length=200,
body=(LinSpaceHold(
bases=(-1., -0.5),
factors=((0.0, 0.01),
(0.02, 0.0)),
duration_base=TimeType(10**6),
duration_factors=None
),)
),))

self.assertEqual([expected], program)
class PlainCSDTest(TestCase):
def setUp(self):
hold = ConstantPT(10**6, {'a': '-1. + idx_a * 0.01', 'b': '-.5 + idx_b * 0.02'})
scan_a = hold.with_iteration('idx_a', 200)
self.pulse_template = scan_a.with_iteration('idx_b', 100)

def test_csd_increment_commands(self):
program = LinSpaceIter(length=100, body=(LinSpaceIter(
self.program = LinSpaceIter(length=100, body=(LinSpaceIter(
length=200,
body=(LinSpaceHold(
bases=(-1., -0.5),
factors=((0.0, 0.01),
(0.02, 0.0)),
duration_base=TimeType(10 ** 6),
duration_base=TimeType(10**6),
duration_factors=None
),)
),))

commands = to_increment_commands([program])
key_0 = DepKey.from_voltages((0, 0.01,), DEFAULT_INCREMENT_RESOLUTION)
key_1 = DepKey.from_voltages((0.02,), DEFAULT_INCREMENT_RESOLUTION)

expected = [
Set(0, -1.0, DepKey.from_voltages((0, 0.01,), DEFAULT_RESOLUTION)),
Set(1, -0.5, DepKey.from_voltages((0.02,), DEFAULT_RESOLUTION)),
self.commands = [
Set(0, -1.0, key_0),
Set(1, -0.5, key_1),
Wait(TimeType(10 ** 6)),

LoopLabel(0, 199),
Increment(0, 0.01, DepKey.from_voltages((0, 0.01,), DEFAULT_RESOLUTION)),
Increment(0, 0.01, key_0),
Wait(TimeType(10 ** 6)),
LoopJmp(0),

LoopLabel(1, 99),

Increment(0, -2.0, DepKey.from_voltages((0, 0.01,), DEFAULT_RESOLUTION)),
Increment(1, 0.02, DepKey.from_voltages((0.02,), DEFAULT_RESOLUTION)),
Increment(0, -2.0, key_0),
Increment(1, 0.02, key_1),
Wait(TimeType(10 ** 6)),

LoopLabel(2, 199),
Increment(0, 0.01, DepKey.from_voltages((0, 0.01,), DEFAULT_RESOLUTION)),
Increment(0, 0.01, key_0),
Wait(TimeType(10 ** 6)),
LoopJmp(2),

LoopJmp(1),
]
self.assertEqual(expected, commands)

def test_program(self):
program_builder = LinSpaceBuilder(('a', 'b'))
program = self.pulse_template.create_program(program_builder=program_builder)
self.assertEqual([self.program], program)

def test_increment_commands(self):
commands = to_increment_commands([self.program])
self.assertEqual(self.commands, commands)


class SingletLoadProcessing(TestCase):
Expand All @@ -132,8 +118,8 @@ def setUp(self):
)
),))

key_0 = DepKey.from_voltages((0, 0.01,), DEFAULT_RESOLUTION)
key_1 = DepKey.from_voltages((0.02,), DEFAULT_RESOLUTION)
key_0 = DepKey.from_voltages((0, 0.01,), DEFAULT_INCREMENT_RESOLUTION)
key_1 = DepKey.from_voltages((0.02,), DEFAULT_INCREMENT_RESOLUTION)

self.commands = [
Set(0, -0.4),
Expand Down Expand Up @@ -188,7 +174,7 @@ def setUp(self):
]

def test_singlet_scan_program(self):
program_builder = LinSpaceBuilder.from_channel_dict({'a': 0, 'b': 1})
program_builder = LinSpaceBuilder(('a', 'b'))
program = self.pulse_template.create_program(program_builder=program_builder)
self.assertEqual([self.program], program)

Expand Down

0 comments on commit ce42fc0

Please sign in to comment.