Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpilation does not take place if an instruction with {None: None} properties is added to the target #8971

Closed
hay-k opened this issue Oct 20, 2022 · 0 comments · Fixed by #8977
Assignees
Labels
bug Something isn't working

Comments

@hay-k
Copy link
Contributor

hay-k commented Oct 20, 2022

Environment

  • Qiskit Terra version: 0.22.0
  • Python version: 3.9.12
  • Operating system: Windows 10

What is happening?

Tranpilation return a not-properly-routed circuit.

How can we reproduce the issue?

The documentation of qiskit.transpiler.Target.add_instruction says If there are no constraints on the instruction (as in a noisless/ideal simulation) this can be set to {None, None} which will indicate it runs on all qubits (or all available permutations of qubits for multi-qubit gates)..

So, let's create a target and add a single-qubit instruction to it by specifying {None: None} as its properties

from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.circuit.library import CXGate, RXGate
from qiskit.compiler import transpile
from qiskit.transpiler import Target

n_qubits = 3
target = Target()
target.add_instruction(CXGate(), {(i, i+1): None for i in range(n_qubits - 1)})
target.add_instruction(RXGate(Parameter('theta')), {None: None})

assert target.build_coupling_map() is None

qc = QuantumCircuit(3)
qc.cx(0, 1)
qc.cx(1, 2)
qc.cx(2, 0)

qc_transpiled = transpile(qc, target=target, optimization_level=2, layout_method='trivial')
print(qc_transpiled.draw())

This code prints the following circuit

               ┌───┐
q_0: ──■───────┤ X ├
     ┌─┴─┐     └─┬─┘
q_1: ┤ X ├──■────┼──
     └───┘┌─┴─┐  │  
q_2: ─────┤ X ├──■──
          └───┘    

which is clearly not routed against the target.

The root cause seems to be, that in this scenario the transpiler target fails to generate the coupling map. Note how the assert line in the above code snippet passes, meaning that the coupling map is None.

What should happen?

Transpiler target should have a properly defined coupling map and transpilation should work correctly

Any suggestions?

No response

@hay-k hay-k added the bug Something isn't working label Oct 20, 2022
@mtreinish mtreinish self-assigned this Oct 20, 2022
mtreinish added a commit to mtreinish/qiskit-core that referenced this issue Oct 20, 2022
This commit fixes the handling of the `build_coupling_map()` method so
that it correctly handles edge cases around a mix of ideal globally
available gates and gates that have qubit/connectivity constraints.
Previously, the method would incorrectly treat the presence of a
globally defined ideal gate as meaning there were no connectivity
constraints, even if that global gate was only on 1 qubit. While if the
gate operates on two qubits this is correct behavior.

Fixes Qiskit#8971
1ucian0 pushed a commit that referenced this issue Oct 31, 2022
…8977)

* Fix handling of global ideal gates for target build_coupling_map()

This commit fixes the handling of the `build_coupling_map()` method so
that it correctly handles edge cases around a mix of ideal globally
available gates and gates that have qubit/connectivity constraints.
Previously, the method would incorrectly treat the presence of a
globally defined ideal gate as meaning there were no connectivity
constraints, even if that global gate was only on 1 qubit. While if the
gate operates on two qubits this is correct behavior.

Fixes #8971

* Add test for single qarg non-ideal case
mergify bot pushed a commit that referenced this issue Oct 31, 2022
…8977)

* Fix handling of global ideal gates for target build_coupling_map()

This commit fixes the handling of the `build_coupling_map()` method so
that it correctly handles edge cases around a mix of ideal globally
available gates and gates that have qubit/connectivity constraints.
Previously, the method would incorrectly treat the presence of a
globally defined ideal gate as meaning there were no connectivity
constraints, even if that global gate was only on 1 qubit. While if the
gate operates on two qubits this is correct behavior.

Fixes #8971

* Add test for single qarg non-ideal case

(cherry picked from commit f6a343b)
mergify bot added a commit that referenced this issue Oct 31, 2022
…8977) (#9040)

* Fix handling of global ideal gates for target build_coupling_map()

This commit fixes the handling of the `build_coupling_map()` method so
that it correctly handles edge cases around a mix of ideal globally
available gates and gates that have qubit/connectivity constraints.
Previously, the method would incorrectly treat the presence of a
globally defined ideal gate as meaning there were no connectivity
constraints, even if that global gate was only on 1 qubit. While if the
gate operates on two qubits this is correct behavior.

Fixes #8971

* Add test for single qarg non-ideal case

(cherry picked from commit f6a343b)

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants