Esempio n. 1
0
def _parse_transpile_args(circuits, backend, basis_gates, coupling_map,
                          backend_properties, initial_layout, seed_transpiler,
                          optimization_level, pass_manager, callback,
                          output_name):
    """Resolve the various types of args allowed to the transpile() function through
    duck typing, overriding args, etc. Refer to the transpile() docstring for details on
    what types of inputs are allowed.

    Here the args are resolved by converting them to standard instances, and prioritizing
    them in case a transpile option is passed through multiple args (explicitly setting an
    arg has more priority than the arg set by backend)

    Returns:
        list[TranspileConfig]: a transpile config for each circuit, which is a standardized
            object that configures the transpiler and determines the pass manager to use.
    """
    # Each arg could be single or a list. If list, it must be the same size as
    # number of circuits. If single, duplicate to create a list of that size.
    num_circuits = len(circuits)

    basis_gates = _parse_basis_gates(basis_gates, backend, circuits)

    coupling_map = _parse_coupling_map(coupling_map, backend, num_circuits)

    backend_properties = _parse_backend_properties(backend_properties, backend,
                                                   num_circuits)

    initial_layout = _parse_initial_layout(initial_layout, circuits)

    seed_transpiler = _parse_seed_transpiler(seed_transpiler, num_circuits)

    optimization_level = _parse_optimization_level(optimization_level,
                                                   num_circuits)

    pass_manager = _parse_pass_manager(pass_manager, num_circuits)

    output_name = _parse_output_name(output_name, circuits)

    transpile_configs = []
    for args in zip(basis_gates, coupling_map, backend_properties,
                    initial_layout, seed_transpiler, optimization_level,
                    pass_manager, output_name):
        transpile_config = TranspileConfig(basis_gates=args[0],
                                           coupling_map=args[1],
                                           backend_properties=args[2],
                                           initial_layout=args[3],
                                           seed_transpiler=args[4],
                                           optimization_level=args[5],
                                           pass_manager=args[6],
                                           callback=callback,
                                           output_name=args[7])
        transpile_configs.append(transpile_config)

    return transpile_configs
Esempio n. 2
0
 def setUp(self):
     coupling = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]
     coupling_map = CouplingMap(couplinglist=coupling)
     qr = QuantumRegister(7, 'q')
     layout = Layout({qr[i]: i for i in range(coupling_map.size())})
     self.config = TranspileConfig(optimization_level=1,
                                   basis_gates=['u1', 'u3', 'u2', 'cx'],
                                   initial_layout=layout,
                                   coupling_map=coupling_map,
                                   seed_transpiler=987,
                                   backend_properties=None)
Esempio n. 3
0
    def test_default_pass_manager_two(self):
        """Test default_pass_manager.run(circuitS).

        circuit1 and circuit2:
        qr0:-[H]--.------------  -> 1
                  |
        qr1:-----(+)--.--------  -> 2
                      |
        qr2:---------(+)--.----  -> 3
                          |
        qr3:-------------(+)---  -> 5

        device:
        0  -  1  -  2  -  3  -  4  -  5  -  6

              |     |     |     |     |     |

              13 -  12  - 11 -  10 -  9  -  8  -   7
        """
        qr = QuantumRegister(4, 'qr')
        circuit1 = QuantumCircuit(qr)
        circuit1.h(qr[0])
        circuit1.cx(qr[0], qr[1])
        circuit1.cx(qr[1], qr[2])
        circuit1.cx(qr[2], qr[3])

        circuit2 = QuantumCircuit(qr)
        circuit2.cx(qr[1], qr[2])
        circuit2.cx(qr[0], qr[1])
        circuit2.cx(qr[2], qr[3])

        coupling_map = FakeMelbourne().configuration().coupling_map
        basis_gates = FakeMelbourne().configuration().basis_gates
        initial_layout = [None, qr[0], qr[1], qr[2], None, qr[3]]

        pass_manager = level_1_pass_manager(
            TranspileConfig(
                basis_gates=basis_gates,
                coupling_map=CouplingMap(coupling_map),
                initial_layout=Layout.from_qubit_list(initial_layout),
                seed_transpiler=42,
                optimization_level=1))
        new_circuits = pass_manager.run([circuit1, circuit2])

        for new_circuit in new_circuits:
            for gate, qargs, _ in new_circuit.data:
                if isinstance(gate, CnotGate):
                    self.assertIn([x.index for x in qargs], coupling_map)