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

OpenQASM 3 exporter outputs invalid integer/float expressions #11071

Open
eginez opened this issue Oct 20, 2023 · 2 comments
Open

OpenQASM 3 exporter outputs invalid integer/float expressions #11071

eginez opened this issue Oct 20, 2023 · 2 comments

Comments

@eginez
Copy link

eginez commented Oct 20, 2023

Hi there while using the parser we notice the following circuit excerpt fails to parse

OPENQASM 3;
include "stdgates.inc";
input float[64] _x_0_;
gate ZZFeatureMap(_x_0_) _gate_q_0 {
h _gate_q_0;
p(2*(3 - _x_0_)*(3 -_x_0_)) _gate_q_0;
}

It seems like there are couple of unspecified cases in the logic to handle binary expressions?

@jakelishman
Copy link
Member

That particular failure is slightly different; that's because the input OQ3 (that looks like Qiskit generated it) is not valid - it attempts to interact integers with floats (3 - _x_0_), which isn't allowed. I'll move this over to the Qiskit repository because strictly it's a bug against the exporter.

That said, we currently don't have a path to fixing this with the current ParameterExpression model of Qiskit; those are symbolic parameters, and our current method of exporting them is pretty much "call str and hope for the best", because it's very difficult to work with the sympy/symengine tree in a coherent manner.

The way we will be moving with this is likely a pivot away from the ParameterExpression as the "default" type of parameter in favour of the explicit runtime expressions and variables (where appropriate) - see #10922 - and ParameterExpression will be more for places where a symbolic expression is required, with them expected to be resolved before attempting to interoperate with OpenQASM 3, etc. The story on this isn't fully fleshed out, though.

@jakelishman jakelishman transferred this issue from Qiskit/qiskit-qasm3-import Oct 20, 2023
@jakelishman jakelishman changed the title QASM3 parser can not handle expressions with floats and angles. OpenQASM 3 exporter outputs invalid integer/float expressions Oct 20, 2023
@Cryoris
Copy link
Contributor

Cryoris commented Nov 9, 2023

Is this the same reason why loading a gate definition where a float is multiplied by a parameter does not work?

E.g. the following snippet cannot be imported if the RZ angle is float * parameter but it works correctly for int * parameter. I'm a bit confused about this, since it is only an issue in a gate definition. Using rz(float * parameter) outside works fine.

Here's a snippet:

OPENQASM 3;
include "stdgates.inc";
input float[64] a;
gate rzz(a) _gate_q_0, _gate_q_1 {
  cx _gate_q_0, _gate_q_1;
  rz(2.0*a) _gate_q_1;              // <---- works if it is defined as rz(2*a)
  cx _gate_q_0, _gate_q_1;
}
qubit[2] q;
rzz(2.0*a) q[0], q[1];

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