Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.04k stars 2.32k forks source link

Transpiling with AerSimulator with coupling map gives TypeError: 'NoneType' object is not iterable #12353

Open kevinsung opened 4 months ago

kevinsung commented 4 months ago

Environment

What is happening?

If the coupling map is not passed, it transpiles with no issue.

How can we reproduce the issue?

from qiskit.circuit.library import EfficientSU2
from qiskit.transpiler import CouplingMap
from qiskit.transpiler.preset_passmanagers import generate_preset_pass_manager
from qiskit_aer import AerSimulator

# Construct circuit
n_qubits = 5
circuit = EfficientSU2(n_qubits, entanglement="pairwise")

# Initialize simulator backend
coupling_map = CouplingMap.from_line(n_qubits)
backend = AerSimulator(
    basis_gates=["ecr", "id", "rz", "sx", "x"],
    coupling_map=coupling_map,
    n_qubits=coupling_map.size(),
)

# Transpile circuit
pass_manager = generate_preset_pass_manager(
    optimization_level=3, backend=backend, seed_transpiler=1234
)
pass_manager.run(circuit)
Traceback (most recent call last):
  File "/home/kevinsung/projects/documentation/scratch/repro.py", line 22, in <module>
    pass_manager.run(circuit)
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/transpiler/passmanager.py", line 397, in run
    return super().run(circuits, output_name, callback, num_processes=num_processes)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/transpiler/passmanager.py", line 420, in wrapper
    return meth(*meth_args, **meth_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/transpiler/passmanager.py", line 182, in run
    return super().run(
           ^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/passmanager/passmanager.py", line 229, in run
    out_program = _run_workflow(
                  ^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/passmanager/passmanager.py", line 292, in _run_workflow
    passmanager_ir, final_state = flow_controller.execute(
                                  ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/passmanager/base_tasks.py", line 218, in execute
    passmanager_ir, state = next_task.execute(
                            ^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/passmanager/base_tasks.py", line 218, in execute
    passmanager_ir, state = next_task.execute(
                            ^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/passmanager/base_tasks.py", line 98, in execute
    ret = self.run(passmanager_ir)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kevinsung/.local/share/virtualenvs/env-documentation/lib64/python3.12/site-packages/qiskit/transpiler/passes/layout/vf2_layout.py", line 149, in run
    has_operations = set(itertools.chain.from_iterable(self.target.qargs))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

What should happen?

Should work.

Any suggestions?

No response

t-imamichi commented 4 months ago

I guess it is due to convert_to_target. I made a patch in the past, but it is not accepted https://github.com/Qiskit/qiskit/pull/11333. We might need to update the transpiler side.