Skip to content

Commit

Permalink
Fix and test MultichannelProgram init
Browse files Browse the repository at this point in the history
  • Loading branch information
terrorfisch committed Aug 17, 2018
1 parent faaf2c0 commit f9e3b63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion qctoolkit/_program/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def __init__(self, instruction_block: Union[AbstractInstructionBlock, Loop], cha
self._init_from_instruction_block(instruction_block, channels)
elif isinstance(instruction_block, Loop):
assert channels is None
self._init_from_loop(loop=instruction_block)
else:
raise TypeError('Invalid program type', type(instruction_block), instruction_block)

Expand All @@ -308,7 +309,7 @@ def _init_from_loop(self, loop: Loop):

assert first_waveform is not None

self._programs[first_waveform.defined_channels] = loop
self._programs[frozenset(first_waveform.defined_channels)] = loop

def _init_from_instruction_block(self, instruction_block, channels):
if channels is None:
Expand Down
9 changes: 9 additions & 0 deletions tests/_program/loop_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,15 @@ def test_via_repr(self):
self.assertEqual(root_loopA.__repr__(), reprA)
self.assertEqual(root_loopB.__repr__(), reprB)

def test_init_from_loop(self):
program = Loop(waveform=DummyWaveform(defined_channels={'A', 'B'}))

mcp = MultiChannelProgram(program)
self.assertEqual(mcp.programs, {frozenset('AB'): program})

with self.assertRaises(TypeError):
MultiChannelProgram(mcp)


class ProgramWaveformCompatibilityTest(unittest.TestCase):
def test_is_compatible_incompatible(self):
Expand Down

0 comments on commit f9e3b63

Please sign in to comment.