def test_copy(self): """Test copy methods return equivalent layouts.""" layout = Layout() layout.add((self.qr, 0)) layout.add((self.qr, 1)) layout_dict_copy = layout.copy() self.assertTrue(isinstance(layout_dict_copy, Layout)) self.assertDictEqual(layout.get_physical_bits(), layout_dict_copy.get_physical_bits()) self.assertDictEqual(layout.get_virtual_bits(), layout_dict_copy.get_virtual_bits()) layout_copy_copy = copy.copy(layout) self.assertTrue(isinstance(layout_copy_copy, Layout)) self.assertDictEqual(layout.get_physical_bits(), layout_dict_copy.get_physical_bits()) self.assertDictEqual(layout.get_virtual_bits(), layout_dict_copy.get_virtual_bits()) layout_copy_deepcopy = copy.deepcopy(layout) self.assertTrue(isinstance(layout_copy_deepcopy, Layout)) self.assertDictEqual(layout.get_physical_bits(), layout_dict_copy.get_physical_bits()) self.assertDictEqual(layout.get_virtual_bits(), layout_dict_copy.get_virtual_bits())
def test_layout_swap_error(self): """swap() method error""" layout = Layout() layout.add((self.qr, 0)) layout.add((self.qr, 1)) with self.assertRaises(LayoutError): layout.swap(0, (self.qr, 0))
def test_layout_idle_physical_bits(self): """Get physical_bits that are not mapped""" layout = Layout() layout.add((self.qr, 1), 2) layout.add(None, 4) layout.add(None, 6) self.assertEqual(layout.idle_physical_bits(), [4, 6])
def test_layout_len_with_idle(self): """Length of the layout is the amount of physical bits""" layout = Layout() self.assertEqual(len(layout), 0) layout.add((self.qr, 2)) self.assertEqual(len(layout), 1) layout.add((self.qr, 1), 3) self.assertEqual(len(layout), 2)
def test_layout_add(self): """add() method""" layout = Layout() layout[(self.qr, 0)] = 0 layout.add((self.qr, 1)) self.assertEqual(layout[(self.qr, 1)], 1) self.assertEqual(layout[1], (self.qr, 1))
def test_set_virtual_without_physical(self): """When adding a virtual without care in which physical is going""" layout = Layout() layout.add((self.qr, 1), 2) layout.add((self.qr, 0)) self.assertDictEqual(layout.get_virtual_bits(), { (self.qr, 0): 1, (self.qr, 1): 2 })
def test_layout_swap(self): """swap() method""" layout = Layout() layout.add((self.qr, 0)) layout.add((self.qr, 1)) layout.swap(0, 1) self.assertDictEqual(layout.get_virtual_bits(), { (self.qr, 0): 1, (self.qr, 1): 0 })
def test_layout_combine(self): """combine_into_edge_map() method""" layout = Layout() layout.add((self.qr, 0)) layout.add((self.qr, 1)) another_layout = Layout() another_layout.add((self.qr, 1)) another_layout.add((self.qr, 0)) edge_map = layout.combine_into_edge_map(another_layout) self.assertDictEqual(edge_map, { (self.qr, 0): (self.qr, 1), (self.qr, 1): (self.qr, 0) })
def test_layout_combine_smaller(self): """combine_into_edge_map() method with another_layout is smaller and raises an Error""" layout = Layout() layout.add((self.qr, 0)) layout.add((self.qr, 1)) layout.add((self.qr, 2)) another_layout = Layout() another_layout.add((self.qr, 1)) another_layout.add((self.qr, 0)) with self.assertRaises(LayoutError): _ = layout.combine_into_edge_map(another_layout)