Closed nonhermitian closed 3 years ago
Hi @nonhermitian !
This is an interesting issue. I would love to fix this, but this is my first time contributing to Qiskit, so a lot of guidance will be helpful.
@nonhermitian Can you share the steps to reproduce this problem?
Simply transpile the H gate using optimization level 0
@nonhermitian I transpiled it with optimization level 0, but all I get is the H
gate back
qc = QuantumCircuit(1)
qc.h(0)
a = transpile(qc,optimization_level = 0)
a.draw(output='mpl')
Yeah sorry, you need to target an IBM backend or set the basis gates to be the same.
By backend, do you mean the actual hardware or the simulator? qasm_simulator
gave me the same output as above, and so did basis_gates=['h']
A real backend
I used ibmq_belem
as the backend, and I got this error. What am I doing wrong? (the code is same as above)
Cannot unroll the circuit to the given basis, ['id', 'rz', 'sx', 'x', 'cx', 'reset']. No rule to expand instruction h.
This works on the latest release:
qc = QuantumCircuit(1)
qc.h(0)
backend = provider.backend.ibmq_belem
trans_qc = transpile(qc, backend, optimization_level=0)
trans_qc.draw()
If it is not working on master than it is a bug.
Ah..I see. My bad, I was checking on PyPi
version
The latest pypi version should work.
The latest is version number 0.26.2
, and I checked my code on this version. But I wasn't able to reproduce the problem.
The IBM Quantum website is at Qiskit 0.26.2
and give me:
I am not sure what you are seeing or not
I see. Wonder why I'm not getting it. Btw, I tried it on a Jupyter Notebook. This is the full code
from qiskit import QuantumCircuit, Aer, IBMQ
from qiskit.compiler import transpile
from qiskit.providers.ibmq import least_busy
qc = QuantumCircuit(1)
qc.h(0)
provider = IBMQ.get_provider(hub='ibm-q')
small_devices = provider.backends(filters=lambda x: x.configuration().n_qubits == 5
and not x.configuration().simulator)
backend = least_busy(small_devices)
a = transpile(qc,optimization_level = 0,backend = backend) # gives error
@nonhermitian Can I take up this issue?
Sure thing
Thanks!
Thanks for your interest @Avhijit-codeboy ! Closing as this was already resolved as part of #4837 :
>>> qc = qk.QuantumCircuit(1)
>>> qc.h(0)
>>> qk.transpile(qc, basis_gates=['rz', 'sx'], optimization_level=0).draw()
global phase: π/4
┌─────────┐┌────┐┌─────────┐
q_0: ┤ RZ(π/2) ├┤ √X ├┤ RZ(π/2) ├
└─────────┘└────┘└─────────┘
Please feel free to re-open if you're still seeing this behavior.
Information
What is the current behavior?
An H gate does not get decomposed correctly. It is easy to see this at optimization level 0:
becomes
when it should involve no more than one
sx
gate and tworz
gates.Steps to reproduce the problem
What is the expected behavior?
An
H
gate gets decomposed into the correct minimal set of basis gates.Suggested solutions
It looks like the decomposition for
s
andsdg
does not know they are simple z-axis rotations.