def test_initial_layout_3(self): """Test that a user-given initial layout is respected, even if cnots are not in the coupling map. See: https://github.com/Qiskit/qiskit-terra/issues/2503 """ # build a circuit which works as-is on the coupling map, using the initial layout qr = QuantumRegister(3) cr = ClassicalRegister(2) qc = QuantumCircuit(qr, cr) qc.u3(0.1, 0.2, 0.3, qr[0]) qc.u2(0.4, 0.5, qr[2]) qc.barrier() qc.cx(qr[0], qr[2]) initial_layout = [6, 7, 12] backend = FakePoughkeepsie() for optimization_level in range(4): qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=optimization_level) gate_0, qubits_0, _ = qc_b[0] gate_1, qubits_1, _ = qc_b[1] self.assertIsInstance(gate_0, U3Gate) self.assertEqual(qubits_0[0].index, 6) self.assertIsInstance(gate_1, U2Gate) self.assertEqual(qubits_1[0].index, 12)
def test_layout_2503(self, level): """Test that a user-given initial layout is respected, even if cnots are not in the coupling map. See: https://github.com/Qiskit/qiskit-terra/issues/2503 """ # build a circuit which works as-is on the coupling map, using the initial layout qr = QuantumRegister(3, "q") cr = ClassicalRegister(2) ancilla = QuantumRegister(17, "ancilla") qc = QuantumCircuit(qr, cr) qc.append(U3Gate(0.1, 0.2, 0.3), [qr[0]]) qc.append(U2Gate(0.4, 0.5), [qr[2]]) qc.barrier() qc.cx(qr[0], qr[2]) initial_layout = [6, 7, 12] final_layout = { 0: ancilla[0], 1: ancilla[1], 2: ancilla[2], 3: ancilla[3], 4: ancilla[4], 5: ancilla[5], 6: qr[0], 7: qr[1], 8: ancilla[6], 9: ancilla[7], 10: ancilla[8], 11: ancilla[9], 12: qr[2], 13: ancilla[10], 14: ancilla[11], 15: ancilla[12], 16: ancilla[13], 17: ancilla[14], 18: ancilla[15], 19: ancilla[16], } backend = FakePoughkeepsie() qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=level) self.assertEqual(qc_b._layout._p2v, final_layout) gate_0, qubits_0, _ = qc_b[0] gate_1, qubits_1, _ = qc_b[1] output_qr = qc_b.qregs[0] self.assertIsInstance(gate_0, U3Gate) self.assertEqual(qubits_0[0], output_qr[6]) self.assertIsInstance(gate_1, U2Gate) self.assertEqual(qubits_1[0], output_qr[12])
def test_optimization_level(self): """Test several backends with all optimization levels""" for backend in [FakeTenerife(), FakeMelbourne(), FakeRueschlikon(), FakeTokyo(), FakePoughkeepsie()]: 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)
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 same.
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
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. Build circuits with up to QISKIT_RANDOM_QUBITS qubits, apply a random selection of gates from qiskit.circuit.library with randomly selected