def test_layout_from_intlist_short(self): """If the intlist is longer that your quantum register, map them to None. virtual physical q1_0 -> 4 q2_0 -> 5 q2_1 -> 6 None -> 8 None -> 9 None -> 10 """ qr1 = QuantumRegister(1, 'qr1') qr2 = QuantumRegister(2, 'qr2') intlist_layout = [4, 5, 6, 8, 9, 10] layout = Layout.from_intlist(intlist_layout, qr1, qr2) expected = Layout({ 4: qr1[0], 5: qr2[0], 6: qr2[1], 8: None, 9: None, 10: None }) self.assertDictEqual(layout._p2v, expected._p2v) self.assertDictEqual(layout._v2p, expected._v2p)
def test_layout_from_intlist(self): """Create a layout from a list of integers. virtual physical q1_0 -> 4 q2_0 -> 5 q2_1 -> 6 q3_0 -> 8 q3_1 -> 9 q3_2 -> 10 """ qr1 = QuantumRegister(1, 'qr1') qr2 = QuantumRegister(2, 'qr2') qr3 = QuantumRegister(3, 'qr3') intlist_layout = [4, 5, 6, 8, 9, 10] layout = Layout.from_intlist(intlist_layout, qr1, qr2, qr3) expected = Layout({ 4: qr1[0], 5: qr2[0], 6: qr2[1], 8: qr3[0], 9: qr3[1], 10: qr3[2] }) self.assertDictEqual(layout._p2v, expected._p2v) self.assertDictEqual(layout._v2p, expected._v2p)
def test_layout_from_intlist_duplicated(self): """If the intlist contains duplicated ints, fail. virtual physical q1_0 -> 4 q2_0 -> 6 -- This is q2_1 -> 6 -- not allowed """ qr1 = QuantumRegister(1, 'qr1') qr2 = QuantumRegister(2, 'qr2') intlist_layout = [4, 6, 6] with self.assertRaises(LayoutError): _ = Layout.from_intlist(intlist_layout, qr1, qr2)
def test_layout_from_intlist_long(self): """If the intlist is shorter that your quantum register, fail. virtual physical q1_0 -> 4 q2_0 -> 5 q2_1 -> 6 q3_0 -> 8 q3_1 -> ? q3_2 -> ? """ qr1 = QuantumRegister(1, 'qr1') qr2 = QuantumRegister(2, 'qr2') qr3 = QuantumRegister(3, 'qr3') intlist_layout = [4, 5, 6, 8] with self.assertRaises(LayoutError): _ = Layout.from_intlist(intlist_layout, qr1, qr2, qr3)