def test_3q_circuit_Tenerife_sd(self): """3 qubits in Tenerife, considering the direction 1 1 ↙ ↑ ↙ ↑ 0 ← 2 ← 3 0 ← qr2 ← qr1 ↑ ↙ ↑ ↙ 4 qr0 """ cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_ = VF2Layout(cmap5, strict_direction=True, seed=self.seed, max_trials=1) pass_.run(dag) self.assertLayout(dag, cmap5, pass_.property_set, strict_direction=True)
def test_seed(self): """Different seeds yield different results""" seed_1 = 42 seed_2 = 45 cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_1 = VF2Layout(CouplingMap(cmap5), seed=seed_1, max_trials=1) pass_1.run(dag) layout_1 = pass_1.property_set["layout"] self.assertEqual(pass_1.property_set["VF2Layout_stop_reason"], VF2LayoutStopReason.SOLUTION_FOUND) pass_2 = VF2Layout(CouplingMap(cmap5), seed=seed_2, max_trials=1) pass_2.run(dag) layout_2 = pass_2.property_set["layout"] self.assertEqual(pass_2.property_set["VF2Layout_stop_reason"], VF2LayoutStopReason.SOLUTION_FOUND) self.assertNotEqual(layout_1, layout_2)
def test_3q_circuit_5q_coupling_sd(self): """3 qubits in Tenerife, considering the direction qr0 ↙ ↑ qr2 ← qr1 ← 3 ↑ ↙ 4 """ cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_ = CSPLayout(CouplingMap(cmap5), strict_direction=True, seed=self.seed) pass_.run(dag) layout = pass_.property_set["layout"] self.assertEqual(layout[qr[0]], 1) self.assertEqual(layout[qr[1]], 2) self.assertEqual(layout[qr[2]], 0) self.assertEqual(pass_.property_set["CSPLayout_stop_reason"], "solution found")
def test_3q_circuit_5q_coupling(self): """ 3 qubits in Tenerife, without considering the direction qr1 / | qr0 - qr2 - 3 | / 4 """ cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, 'qr') circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_ = CSPLayout(CouplingMap(cmap5), strict_direction=False, seed=self.seed) pass_.run(dag) layout = pass_.property_set['layout'] self.assertEqual(layout[qr[0]], 0) self.assertEqual(layout[qr[1]], 1) self.assertEqual(layout[qr[2]], 2) self.assertEqual(pass_.property_set['CSPLayout_stop_reason'], 'solution found')
def test_partial_layout(self): """Tests partial_layout See: https://github.com/Qiskit/qiskit-terra/issues/4757""" circuit = QuantumCircuit(3) circuit.h(1) transpiled = transpile(circuit, backend=FakeTenerife(), optimization_level=0, initial_layout=[1, 2, 0], seed_transpiler=0) self.circuit_drawer(transpiled, filename='partial_layout.png')
def test_optimization_level(self): """Test several backends with all optimization levels""" for backend in [FakeTenerife(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo()]: for optimization_level in range(4): result = transpile( [self._circuit], backend=backend, optimization_level=optimization_level ) self.assertIsInstance(result, QuantumCircuit)
class TestTranspileLevels(QiskitTestCase): """Test transpiler on fake backend""" @combine(circuit=[emptycircuit, circuit_2532], level=[0, 1, 2, 3], backend=[FakeTenerife(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo(), FakePoughkeepsie(), None], dsc='Transpiler {circuit.__name__} on {backend} backend at level {level}', name='{circuit.__name__}_{backend}_level{level}') def test(self, circuit, level, backend): """All the levels with all the backends""" result = transpile(circuit(), backend=backend, optimization_level=level, seed_transpiler=42) self.assertIsInstance(result, QuantumCircuit)
def test_partial_layout(self): """Tests partial_layout See: https://github.com/Qiskit/qiskit-terra/issues/4757""" filename = self._get_resource_path('test_latex_partial_layout.tex') circuit = QuantumCircuit(3) circuit.h(1) transpiled = transpile(circuit, backend=FakeTenerife(), optimization_level=0, initial_layout=[1, 2, 0], seed_transpiler=0) circuit_drawer(transpiled, filename=filename, output='latex_source') self.assertEqualToReference(filename)
def test_3_q_gate(self): """The pass does not handle gates with more than 2 qubits""" seed_1 = 42 cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.ccx(qr[1], qr[0], qr[2]) dag = circuit_to_dag(circuit) pass_1 = VF2Layout(CouplingMap(cmap5), seed=seed_1) with self.assertRaises(TranspilerError): pass_1.run(dag)
def test_3_q_gate(self): """The pass does not handle gates with more than 2 qubits""" seed_1 = 42 cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.ccx(qr[1], qr[0], qr[2]) dag = circuit_to_dag(circuit) pass_1 = VF2Layout(CouplingMap(cmap5), seed=seed_1, max_trials=1) pass_1.run(dag) self.assertEqual(pass_1.property_set["VF2Layout_stop_reason"], VF2LayoutStopReason.MORE_THAN_2Q)
def test_4q_circuit_Tenerife_loose_nodes(self): """4 qubits in Tenerife, with loose nodes 1 ↙ ↑ 0 ← 2 ← 3 ↑ ↙ 4 """ cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) qr = QuantumRegister(4, "q") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 dag = circuit_to_dag(circuit) pass_ = VF2Layout(cmap5, seed=self.seed, max_trials=1) pass_.run(dag) self.assertLayout(dag, cmap5, pass_.property_set)
def test_yzy_zyz_cases(self): """yzy_to_zyz works in previously failed cases. See: https://github.com/Qiskit/qiskit-terra/issues/607 """ backend = FakeTenerife() qr = QuantumRegister(2) circ1 = QuantumCircuit(qr) circ1.cx(qr[0], qr[1]) circ1.rz(0.7, qr[1]) circ1.rx(1.570796, qr[1]) qobj1 = compile(circ1, backend) self.assertIsInstance(qobj1, QasmQobj) circ2 = QuantumCircuit(qr) circ2.y(qr[0]) circ2.h(qr[0]) circ2.s(qr[0]) circ2.h(qr[0]) qobj2 = compile(circ2, backend) self.assertIsInstance(qobj2, QasmQobj)
def test_3q_circuit_Tenerife(self): """3 qubits in Tenerife, without considering the direction 1 1 ↙ ↑ / | 0 ← 2 ← 3 0 - qr1 - qr2 ↑ ↙ | / 4 qr0 """ cmap5 = CouplingMap(FakeTenerife().configuration().coupling_map) qr = QuantumRegister(3, "q") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_ = VF2Layout(cmap5, strict_direction=False, seed=self.seed) pass_.run(dag) self.assertLayout(dag, cmap5, pass_.property_set)
def test_seed(self): """Different seeds yield different results""" seed_1 = 42 seed_2 = 43 cmap5 = FakeTenerife().configuration().coupling_map qr = QuantumRegister(3, "qr") circuit = QuantumCircuit(qr) circuit.cx(qr[1], qr[0]) # qr1 -> qr0 circuit.cx(qr[0], qr[2]) # qr0 -> qr2 circuit.cx(qr[1], qr[2]) # qr1 -> qr2 dag = circuit_to_dag(circuit) pass_1 = CSPLayout(CouplingMap(cmap5), seed=seed_1) pass_1.run(dag) layout_1 = pass_1.property_set["layout"] pass_2 = CSPLayout(CouplingMap(cmap5), seed=seed_2) pass_2.run(dag) layout_2 = pass_2.property_set["layout"] self.assertNotEqual(layout_1, layout_2)
oneQ_gates = [HGate, IdGate, SGate, SdgGate, TGate, TdgGate, XGate, YGate, ZGate, Reset] twoQ_gates = [CnotGate, CyGate, CzGate, SwapGate, CHGate] threeQ_gates = [ToffoliGate, FredkinGate] oneQ_oneP_gates = [U0Gate, U1Gate, RXGate, RYGate, RZGate] oneQ_twoP_gates = [U2Gate] oneQ_threeP_gates = [U3Gate] twoQ_oneP_gates = [CrzGate, RZZGate, Cu1Gate] twoQ_threeP_gates = [Cu3Gate] oneQ_oneC_gates = [Measure] variadic_gates = [Barrier] mock_backends = [FakeTenerife(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo(), FakePoughkeepsie()] @settings(report_multiple_bugs=False, max_examples=50, deadline=None) class QCircuitMachine(RuleBasedStateMachine): """Build a Hypothesis rule based state machine for constructing, transpiling and simulating a series of random QuantumCircuits. Build circuits with up to QISKIT_RANDOM_QUBITS qubits, apply a random selection of gates from qiskit.extensions.standard with randomly selected qargs, cargs, and parameters. At random intervals, transpile the circuit for a random backend with a random optimization level and simulate both the initial and the transpiled circuits to verify that their counts are the
def setUp(self): self.cmap5 = FakeTenerife().configuration().coupling_map self.cmap16 = FakeRueschlikon().configuration().coupling_map
twoQ_gates = [CXGate, CYGate, CZGate, SwapGate, CHGate] threeQ_gates = [CCXGate, CSwapGate] oneQ_oneP_gates = [U1Gate, RXGate, RYGate, RZGate] oneQ_twoP_gates = [U2Gate] oneQ_threeP_gates = [U3Gate] twoQ_oneP_gates = [CRZGate, RZZGate, CU1Gate] twoQ_threeP_gates = [CU3Gate] oneQ_oneC_gates = [Measure] variadic_gates = [Barrier] mock_backends = [ FakeYorktown(), FakeTenerife(), FakeOurense(), FakeVigo(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo(), FakePoughkeepsie(), FakeAlmaden(), FakeSingapore(), FakeJohannesburg(), FakeBoeblingen() ] # FakeRochester disabled until https://github.com/Qiskit/qiskit-aer/pull/693 is released.
oneQ_gates = [HGate, IGate, SGate, SdgGate, TGate, TdgGate, XGate, YGate, ZGate, Reset] twoQ_gates = [CXGate, CYGate, CZGate, SwapGate, CHGate] threeQ_gates = [CCXGate, CSwapGate] oneQ_oneP_gates = [U1Gate, RXGate, RYGate, RZGate] oneQ_twoP_gates = [U2Gate] oneQ_threeP_gates = [U3Gate] twoQ_oneP_gates = [CRZGate, RZZGate, CU1Gate] twoQ_threeP_gates = [CU3Gate] oneQ_oneC_gates = [Measure] variadic_gates = [Barrier] mock_backends = [FakeYorktown(), FakeTenerife(), FakeOurense(), FakeVigo(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo(), FakePoughkeepsie(), FakeAlmaden(), FakeSingapore(), FakeJohannesburg(), FakeBoeblingen()] # FakeRochester disabled until https://github.com/Qiskit/qiskit-aer/pull/693 is released. @settings(report_multiple_bugs=False, max_examples=25, deadline=None, suppress_health_check=[HealthCheck.filter_too_much]) class QCircuitMachine(RuleBasedStateMachine): """Build a Hypothesis rule based state machine for constructing, transpiling and simulating a series of random QuantumCircuits.