Qiskit-terra: compiling multiple circuits on a real device backend

Created on 31 Jul 2018  路  10Comments  路  Source: Qiskit/qiskit-terra

Informations

  • Qiskit (Python SDK) version: 0.5.6
  • Python version: 3.6.2
  • Operating system: Windows 10

What is the current behavior?

When using the transpiler "compile" function, with multiple circuits (a circuit array), on a real device (such as "ibmq_16_rueschlikon"), the following error is returned:
MapperError: 'initial_layout qubit q0[0] not in input DAGCircuit'

This error does not happen when compiling only one circuit, or when compiling on a simulator backend.

Steps to reproduce the problem

backend = "ibmq_16_rueschlikon"
my_backend = get_backend(backend)
circuits = []
for i in range(2):
    qr = QuantumRegister(2)
    cr = ClassicalRegister(2)
    circuit = QuantumCircuit(qr,cr)
    circuit.h(qr[0])
    circuit.cx(qr[0], qr[1])
    circuit.measure(qr,cr)
    circuits.append(circuit)

job_exp = compile(circuits, backend=backend, shots=1024)

Log of the error

---------------------------------------------------------------------------
MapperError                               Traceback (most recent call last)
<ipython-input-7-c4740bc3ff07> in <module>()
     27 my_backend = get_backend(backend)
---> 28 qobj = compile(circuits, backend=my_backend, shots=1024)
     29 job = my_backend.run(qobj)

~\Anaconda3\lib\site-packages\qiskit\wrapper\_wrapper.py in compile(circuits, backend, config, basis_gates, coupling_map, initial_layout, shots, max_credits, seed, qobj_id, hpc, skip_transpiler)
    242                               config, basis_gates, coupling_map, initial_layout,
    243                               shots, max_credits, seed, qobj_id, hpc,
--> 244                               pass_manager)
    245 
    246 

~\Anaconda3\lib\site-packages\qiskit\transpiler\_transpiler.py in compile(circuits, backend, config, basis_gates, coupling_map, initial_layout, shots, max_credits, seed, qobj_id, hpc, pass_manager)
    120             get_layout=True,
    121             seed=seed,
--> 122             pass_manager=pass_manager)
    123 
    124         # step 3c: dag -> json

~\Anaconda3\lib\site-packages\qiskit\transpiler\_transpiler.py in transpile(dag_circuit, basis_gates, coupling_map, initial_layout, get_layout, format, seed, pass_manager)
    212             logger.info("initial layout: %s", initial_layout)
    213             dag_circuit, final_layout = swap_mapper(
--> 214                 dag_circuit, coupling, initial_layout, trials=20, seed=seed)
    215             logger.info("final layout: %s", final_layout)
    216             # Expand swaps

~\Anaconda3\lib\site-packages\qiskit\mapper\_mapping.py in swap_mapper(circuit_graph, coupling_graph, initial_layout, basis, trials, seed)
    461             if k not in circ_qubits:
    462                 raise MapperError("initial_layout qubit %s[%d] not in input "
--> 463                                   "DAGCircuit" % (k[0], k[1]))
    464             if v not in coup_qubits:
    465                 raise MapperError("initial_layout qubit %s[%d] not in input "

MapperError: 'initial_layout qubit q0[0] not in input DAGCircuit'
bug

Most helpful comment

I believe that if you explicitly name your quantum register, e.g. name='q', the same for all circuits, then it should work.

All 10 comments

I think this is related to some of the errors in the complie that I posted as #704. Ie I think we are using the layout from first circuit and in later ones the gates are not supported on the layout. Thanks for pointing this out it鈥檚 a good test and we try to fix it with the other errors in #704

Do you have an idea to work around this issue in the meantime? Without having to run N seperate jobs, and thus having to wait for the ibmqx5 queue N times.

Yeah by giving it the layout you want to use for all circuits. Let me try to prof of concept and I post here later.

Thanks!

I believe that if you explicitly name your quantum register, e.g. name='q', the same for all circuits, then it should work.

Yes @nonhermitian is correct. I thought the cX was changing by one each time. Which also would fail

Indeed, explicitly naming all circuits quantum registers with name = 'q', and specifying an initial_layout seems to work. Thank you very much for your help!

Great. This will be fixed in the next update.

@nonhermitian can you move the example into my #704 so we track it and use it as a test with the transpiler work and I think we can close this now that @tibaloo has a solution.

Closing this now. The fix has been added and tested in #704.

Was this page helpful?
0 / 5 - 0 ratings