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(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_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_get_bits(self): """Get the map from the (qu)bits view""" layout_dict = {(self.qr, 0): 0, (self.qr, 1): 1, (self.qr, 2): 2} layout = Layout(layout_dict) self.assertDictEqual(layout_dict, layout.get_virtual_bits())