-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 bug encountered #7042
Comments
It seems duplicated with #7033. |
You mean the warnings? or is there an error? |
@1ucian0 Hi Luciano, sorry it's a warning. It keeps showing up and asking me to report this issue. |
I don't think I can reproduce this without an example value of |
It's hard to reproduce it because I think it connects to the value I assigned to theta. Once I changed the value the warning disappears. It's hard to reproduce in my algorithm where thousands circuits have been submitted and ran with such warnings appearing for several times. But fortunately in the end I reproduced it. Here is one example for you:
The warning I got: |
Thanks so much! I can reproduce that. |
@levbishop Since you have strong opinions about
re-synthesizes to have ZXZ angle values This is sensitive to the complex difference in the definition of I see two options:
|
I understand the issue and like you I also lean away from simply raising the tolerance without thinking through carefully. |
It's not yet clear if it's a related issue, but the first line in the log from #7041 shows a single gate (supposedly belonging to |
I had a start at doing this based on estimated infidelity. Here's where I got to before I had to switch to other things. @staticmethod
def _circuit_psx_gen_fid(tgt, theta, phi, lam, phase, infid, pfun, xfun, xpifun=None):
"""
Generic X90, phase decomposition
"""
qr = QuantumRegister(1, "qr")
circuit = QuantumCircuit(qr, global_phase=phase)
mintr2 = 4 - 6 * infid # Minimum acceptable |Tr(Ud.Uapprox)|^2
# Shift theta and phi to turn the decomposition from
# RZ(phi).RY(theta).RZ(lam) = RZ(phi).RX(-pi/2).RZ(theta).RX(pi/2).RZ(lam)
# into RZ(phi+pi).SX.RZ(theta+pi).SX.RZ(lam) .
theta, phi = theta + np.pi, phi + np.pi
phase -= np.pi / 2
tr2_none = 4 * math.sin(theta / 2) ** 2 * math.sin((lam + phi) / 2) ** 2
if tr2_none > mintr2:
return circuit
tr2_p = 2 - 2 * math.cos(theta)
if tr2_p > mintr2:
pfun(circuit, qr, lam + phi + np.pi)
return circuit
tr2_x = (
1
+ math.cos(theta) * math.cos(phi) * math.cos(lam)
+ math.sin(phi) * math.sin(lam)
- math.sin(theta) * (math.sin(phi) + math.sin(lam))
)
if tr2_x > mintr2:
xfun(circuit, qr)
return circuit
angle_px = (
math.atan2(math.sin(theta) - math.sin(phi), math.cos(theta) * math.cos(phi)) + lam
)
tr2_px = (
math.cos((-theta - phi + lam - angle_px) / 2)
+ math.cos((theta - phi + lam - angle_px) / 2)
- 2 * math.sin(theta / 2) * math.sin((phi + lam - angle_px) / 2)
) ** 2 / 2
angle_xp = (
math.atan2(math.sin(theta) - math.sin(lam), math.cos(theta) * math.cos(lam)) + phi
)
tr2_xp = (
math.cos((-theta - phi + lam + angle_xp) / 2)
+ math.cos((theta - phi + lam + angle_xp) / 2)
- 2 * math.sin(theta / 2) * math.sin((phi + lam - angle_xp) / 2)
) ** 2 / 2
if max(tr2_px, tr2_xp) > mintr2:
if tr2_px > tr2_xp:
pfun(circuit, qr, angle_px)
xfun(circuit, qr)
else:
xfun(circuit, qr)
pfun(circuit, qr, angle_xp)
return circuit
tr2_pxp = 2 * (1 + abs(math.sin(theta)))
if tr2_pxp > mintr2:
offset = np.pi / 2 if theta < 0 else -np.pi / 2
pfun(circuit, qr, lam + offset)
xfun(circuit, qr)
pfun(circuit, qr, phi + offset)
return circuit
tr2_xx = 4 * math.cos(theta / 2) ** 2 * math.cos((lam - phi) / 2) ** 2
if tr2_xx > mintr2:
if xpifun:
xpifun(circuit, qr)
else:
xfun(circuit, qr)
xfun(circuit, qr)
return circuit
tr2_xxp = 2 + 2 * math.cos(theta)
if tr2_xxp > mintr2:
if xpifun:
xpifun(circuit, qr)
else:
xfun(circuit, qr)
xfun(circuit, qr)
pfun(circuit, qr, -lam + phi)
return circuit
angle_xpx = math.atan2(
math.sin(theta) * (math.cos(phi) + math.cos(lam)),
math.cos(theta) * (1 + math.cos(phi) * math.cos(lam)) + math.sin(phi) * math.sin(lam),
)
tr2_xpx = (
4
* (
math.cos(theta / 2) * math.cos(angle_xpx / 2) * math.cos((phi - lam) / 2)
+ math.cos((phi + lam) / 2) * math.sin(theta / 2) * math.sin(angle_xpx / 2)
)
** 2
)
if tr2_xpx > mintr2:
xfun(circuit, qr)
pfun(circuit, qr, angle_xpx)
xfun(circuit, qr)
return circuit
# FIXME: figure out angles and traces for this case
angle1_xpxp = 0
angle2_xpxp = 0
tr2_xpxp = 0
angle1_pxpx = 0
angle2_pxpx = 0
tr2_pxpx = 0
if max(tr2_pxpx, tr2_xpxp) > mintr2:
if tr2_pxpx > tr2_xpxp:
pfun(circuit, qr, angle1_pxpx)
xfun(circuit, qr)
pfun(circuit, qr, angle2_pxpx)
xfun(circuit, qr)
else:
xfun(circuit, qr)
pfun(circuit, qr, angle2_xpxp)
xfun(circuit, qr)
pfun(circuit, qr, angle1_xpxp)
return circuit
# No special case applies, use the generic pxpxp decomposition
pfun(circuit, qr, lam)
xfun(circuit, qr)
pfun(circuit, qr, theta)
xfun(circuit, qr)
pfun(circuit, qr, phi)
return circuit It gives optimal approximations for nearly all special cases.
Anyone want to pick this up? otherwise I'll try to find time but not likely in time for 0.19 |
I'm happy to pick this up. I think coupling fidelity estimation and approximation dodges my worry about Similarly no guarantees about 0.19, but it could conceivably happen. |
Information
What is the current behavior?
Got following errors while using crx and rx gates:
/gpfs/software/Anaconda/envs/psifour/lib/python3.7/site-packages/ipykernel_launcher.py:72: RuntimeWarning: invalid value encountered in double_scalars
/gpfs/home/yuluwang/.local/lib/python3.7/site-packages/qiskit/transpiler/runningpassmanager.py:166: UserWarning: Resynthesized [<qiskit.dagcircuit.dagnode.DAGNode object at 0x2aaba5022b40>, <qiskit.dagcircuit.dagnode.DAGNode object at 0x2aaba5022280>, <qiskit.dagcircuit.dagnode.DAGNode object at 0x2aaba5022910>, <qiskit.dagcircuit.dagnode.DAGNode object at 0x2aaba72f9d70>] and got global phase: π
┌───────┐┌────┐┌─────────────┐┌────┐┌──────────┐
qr_0: ┤ Rz(π) ├┤ √X ├┤ Rz(-3.1415) ├┤ √X ├┤ Rz(-π/2) ├
└───────┘└────┘└─────────────┘└────┘└──────────┘, but the original was native and the new value is longer. This indicates an efficiency bug in synthesis. Please report it by opening an issue here: https://github.com/Qiskit/qiskit-terra/issues/new/choose
new_dag = pass_.run(dag)
Steps to reproduce the problem
Using Rx and Crx gates. I applied parameter binding and noise model at the same time.
transpiled_circ = transpile(circ, backend=backend,optimization_level=3)
circ = transpiled_circ.bind_parameters(para_dict)
job = execute(circ, backend=backend, shots=shots,coupling_map=coupling_map, basis_gates=basis_gates, noise_model=noise_model)
What is the expected behavior?
Suggested solutions
The text was updated successfully, but these errors were encountered: