def test_best_mapping_ghz_state_full_device_multiple_qregs(self):
     """Test best mappings with multiple registers"""
     backend = FakeLima()
     qr_a = QuantumRegister(2)
     qr_b = QuantumRegister(3)
     qc = QuantumCircuit(qr_a, qr_b)
     qc.h(qr_a[0])
     qc.cx(qr_a[0], qr_a[1])
     qc.cx(qr_a[0], qr_b[0])
     qc.cx(qr_a[0], qr_b[1])
     qc.cx(qr_a[0], qr_b[2])
     qc.measure_all()
     tqc = transpile(qc,
                     backend,
                     seed_transpiler=self.seed,
                     layout_method="trivial")
     initial_layout = tqc._layout
     dag = circuit_to_dag(tqc)
     cmap = CouplingMap(backend.configuration().coupling_map)
     props = backend.properties()
     pass_ = VF2PostLayout(coupling_map=cmap,
                           properties=props,
                           seed=self.seed,
                           strict_direction=False)
     pass_.run(dag)
     self.assertLayout(dag, cmap, pass_.property_set)
     self.assertNotEqual(pass_.property_set["post_layout"], initial_layout)
 def test_transpile_level_3(self):
     """Make sure that transpile with optimization_level=2 transpiles
     the Clifford."""
     cliff1 = self.create_cliff1()
     qc = QuantumCircuit(3)
     qc.append(cliff1, [0, 1, 2])
     self.assertIn("clifford", qc.count_ops())
     qc2 = transpile(qc, optimization_level=3)
     self.assertNotIn("clifford", qc2.count_ops())
    def test_2q_circuit_5q_backend_v2(self):
        """A simple example, without considering the direction
          0 - 1
        qr1 - qr0
        """
        backend = FakeYorktownV2()

        qr = QuantumRegister(2, "qr")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[1], qr[0])  # qr1 -> qr0
        tqc = transpile(circuit, backend, layout_method="dense")
        initial_layout = tqc._layout
        dag = circuit_to_dag(tqc)
        pass_ = VF2PostLayout(target=backend.target, seed=self.seed)
        pass_.run(dag)
        self.assertLayoutV2(dag, backend.target, pass_.property_set)
        self.assertNotEqual(pass_.property_set["post_layout"], initial_layout)
    def test_2q_circuit_5q_backend(self):
        """A simple example, without considering the direction
          0 - 1
        qr1 - qr0
        """
        backend = FakeYorktown()

        qr = QuantumRegister(2, "qr")
        circuit = QuantumCircuit(qr)
        circuit.cx(qr[1], qr[0])  # qr1 -> qr0
        tqc = transpile(circuit, backend, layout_method="dense")
        initial_layout = tqc._layout
        dag = circuit_to_dag(tqc)
        cmap = CouplingMap(backend.configuration().coupling_map)
        props = backend.properties()
        pass_ = VF2PostLayout(coupling_map=cmap,
                              properties=props,
                              seed=self.seed)
        pass_.run(dag)
        self.assertLayout(dag, cmap, pass_.property_set)
        self.assertNotEqual(pass_.property_set["post_layout"], initial_layout)
 def test_best_mapping_ghz_state_full_device_multiple_qregs_v2(self):
     """Test best mappings with multiple registers"""
     backend = FakeLimaV2()
     qr_a = QuantumRegister(2)
     qr_b = QuantumRegister(3)
     qc = QuantumCircuit(qr_a, qr_b)
     qc.h(qr_a[0])
     qc.cx(qr_a[0], qr_a[1])
     qc.cx(qr_a[0], qr_b[0])
     qc.cx(qr_a[0], qr_b[1])
     qc.cx(qr_a[0], qr_b[2])
     qc.measure_all()
     tqc = transpile(qc,
                     backend,
                     seed_transpiler=self.seed,
                     layout_method="trivial")
     initial_layout = tqc._layout
     dag = circuit_to_dag(tqc)
     pass_ = VF2PostLayout(target=backend.target, seed=self.seed)
     pass_.run(dag)
     self.assertLayoutV2(dag, backend.target, pass_.property_set)
     self.assertNotEqual(pass_.property_set["post_layout"], initial_layout)
Beispiel #6
0
def compile(circuits,
            backend,
            config=None,
            basis_gates=None,
            coupling_map=None,
            initial_layout=None,
            shots=1024,
            max_credits=10,
            seed=None,
            qobj_id=None,
            seed_mapper=None,
            pass_manager=None,
            memory=False):
    """Compile a list of circuits into a qobj.

    Args:
        circuits (QuantumCircuit or list[QuantumCircuit]): circuits to compile
        backend (BaseBackend): a backend to compile for
        config (dict): dictionary of parameters (e.g. noise) used by runner
        basis_gates (list[str]): list of basis gates names supported by the
            target. Default: ['u1','u2','u3','cx','id']
        coupling_map (list): coupling map (perhaps custom) to target in mapping
        initial_layout (list): initial layout of qubits in mapping
        shots (int): number of repetitions of each circuit, for sampling
        max_credits (int): maximum credits to use
        seed (int): random seed for simulators
        seed_mapper (int): random seed for swapper mapper
        qobj_id (int): identifier for the generated qobj
        pass_manager (PassManager): a pass manger for the transpiler pipeline
        memory (bool): if True, per-shot measurement bitstrings are returned as well

    Returns:
        Qobj: the qobj to be run on the backends

    Raises:
        QiskitError: if the desired options are not supported by backend
    """
    warnings.warn(
        'qiskit.compile() is deprecated and will be removed in Qiskit Terra 0.9. '
        'Please use qiskit.compiler.transpile() to transform circuits '
        'and qiskit.compiler.assemble() to produce a runnable qobj.',
        DeprecationWarning)

    new_circuits = transpile(circuits,
                             basis_gates=basis_gates,
                             coupling_map=coupling_map,
                             initial_layout=initial_layout,
                             seed_transpiler=seed_mapper,
                             backend=backend,
                             pass_manager=pass_manager)

    qobj = assemble(new_circuits,
                    qobj_header=None,
                    shots=shots,
                    max_credits=max_credits,
                    seed_simulator=seed,
                    memory=memory,
                    qobj_id=qobj_id,
                    config=config)  # deprecated

    return qobj