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

Error loading the definition of rxx gate with the loads function #11

Open
TheGupta2012 opened this issue May 30, 2023 · 2 comments
Open

Comments

@TheGupta2012
Copy link

TheGupta2012 commented May 30, 2023

I was trying to make a mapping from the qasm2 standard gates present in qelib1.inc located in the terra lib. I am encountering the following error while loading the definition of the rxx gate as supplied in the .inc file -

ConversionError: 13,10: type error

The above exception was the direct cause of the following exception:

QASM3ImporterError                        Traceback (most recent call last)
Cell In[3], line 1
----> 1 circ = loads(qasm3)

File ~/Desktop/college/quantum/Unitary Fund/Unitary-Hack/qbraid-env/lib/python3.10/site-packages/qiskit/utils/lazy_tester.py:149, in LazyDependencyManager.require_in_call.<locals>.decorator.<locals>.out(*args, **kwargs)
    146 @functools.wraps(function)
    147 def out(*args, **kwargs):
    148     self.require_now(feature)
--> 149     return function(*args, **kwargs)

File ~/Desktop/college/quantum/Unitary Fund/Unitary-Hack/qbraid-env/lib/python3.10/site-packages/qiskit/qasm3/__init__.py:202, in loads(program)
    200     return qiskit_qasm3_import.parse(program)
    201 except qiskit_qasm3_import.ConversionError as exc:
--> 202     raise QASM3ImporterError(str(exc)) from exc

QASM3ImporterError: '13,10: type error'

I used the following script -

from qiskit.qasm3 import loads

 qasm3 = """
 OPENQASM 3.0;
 include "stdgates.inc";
 gate rxx(theta) a, b
 {
   u3(pi/2, theta, 0) a;
   h b;
   cx a,b;
   u1(-theta) b;
   cx a,b;
   h b;
   // why type error?
   u2(-pi, pi-theta) b;
 }
 qubit[3] q;
 rxx(0.5) q[0], q[1];
 """

 circ = loads(qasm3)

From the traceback, it looks like the line u2(-pi, pi-theta) b; is not getting parsed correctly. More specifically, the pi - theta parameter seems to be the source of the error.

@jakelishman
Copy link
Member

Thanks for the report - looks like I made mistake with the typing of the pi built-in, and also that there's no promotion rules from angle to float in the expression evaluator. I think that there's no implicit promotion allowed in OQ3 for that because it's quite a non-trivial bit-to-bit transformation (unlike integer promotions), but if I fix the typing of pi, that shouldn't be a problem within the gate context you're concerned about here.

@eginez
Copy link

eginez commented Oct 20, 2023

possibly related to: Qiskit/qiskit#11071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants