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

Transpiler with target unrolls even if gate is natively supported #10592

Closed
burgholzer opened this issue Aug 8, 2023 · 3 comments
Closed

Transpiler with target unrolls even if gate is natively supported #10592

burgholzer opened this issue Aug 8, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@burgholzer
Copy link
Contributor

burgholzer commented Aug 8, 2023

Environment

  • Qiskit Terra version: 0.25.0
  • Python version: 3.11
  • Operating system: Ubuntu 22.04

What is happening?

Calling transpile with a custom target on a circuit causes transpilation even though all gates of a circuit are in the target's list of supported operations. See the below MRE that demonstrates the issue.
The underlying issue is much broader than that. Given a target that contains the U3Gate and any other single-qubit gate, the transpiled circuit will always contain a u3 gate instead of the original gate.

How can we reproduce the issue?

import qiskit.circuit.library as qcl
from qiskit import QuantumCircuit, transpile
from qiskit.circuit import Parameter
from qiskit.transpiler import Target

target = Target(num_qubits=1)
target.add_instruction(qcl.XGate())
target.add_instruction(qcl.U3Gate(Parameter("theta"), Parameter("phi"), Parameter("lam")))

qc = QuantumCircuit(1)
qc.x(0)
qc_transpiled = transpile(qc, target=target)
print(qc_transpiled.data[0][0])

yields

u3

What should happen?

The X gate is in the list of supported instructions. As such, I would have expected no transpilation to take place and that qc == qc_transpiled.

Interestingly, using

qc_transpiled = transpile(qc, basis_gates=["x", "u3"])

produces the desired result.

Any suggestions?

If the behavior above is not desired, it is at least unexpected and some clarification would be great.
If this is really a bug, I suspect that some early stopping criterion is missing somewhere.

@mtreinish
Copy link
Member

I came across the same thing too, I had opened: #10568 to track it. I'm going to close this as a duplicate of it. The specific issue is basically this function: https://github.com/Qiskit/qiskit/blob/main/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py#L152-L180 isn't taking into account that the default should be to not translate the gate if the all have the same error rates (which in a simulator will be None).

@mtreinish mtreinish closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2023
@burgholzer
Copy link
Contributor Author

I came across the same thing too, I had opened: #10568 to track it. I'm going to close this as a duplicate of it. The specific issue is basically this function: https://github.com/Qiskit/qiskit/blob/main/qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py#L152-L180 isn't taking into account that the default should be to not translate the gate if the all have the same error rates (which in a simulator will be None).

Ah thanks for bringing that up and sorry for the noise. Is that something you have on the radar internally and are working on a fix or would you appreciate a community contribution there?

@mtreinish
Copy link
Member

I haven't started to work on it besides identifying the root cause a few weeks ago. If you have the bandwidth to work on it that would be greatly appreciated. If you leave a comment on #10568 I can assign the issue to you.

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

No branches or pull requests

2 participants