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

Allow float/angle interaction in gate-parameter contexts #35

Merged
merged 3 commits into from
Jun 13, 2024

Conversation

jakelishman
Copy link
Member

This allows technically invalid OpenQASM 3, but is in practice what Qiskit's OpenQASM 3 exporter outputs due to problems in how it represents symbolic expressions. It's probably better for users to allow the technically invalid OpenQASM 3 than to punish them for things that are actually Qiskit's fault.

Fix #25.

This allows technically invalid OpenQASM 3, but is in practice what
Qiskit's OpenQASM 3 exporter outputs due to problems in how it
represents symbolic expressions.  It's probably better for users to
allow the technically invalid OpenQASM 3 than to punish them for things
that are actually Qiskit's fault.
This is the same as the multiplication/division part. While it's much
less likely for these to appear from the Qiskit export, it makes sense
to allow them in non-strict mode for symmetry.
mtreinish
mtreinish previously approved these changes Jun 13, 2024
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-wise this LGTM, it's a pretty straightforward relaxation of the type rules for the arithmetic operations in non-strict mode. I just had one #nit in the release note otherwise I think it's good to merge.

@@ -233,6 +241,13 @@ def visit_BinaryExpression(self, node: ast.BinaryExpression):
elif isinstance(rhs_type, types.Angle):
const = lhs_type.const and rhs_type.const
out_type = types.Uint(const, None)
# We allow `angle / float` in non-strict mode, because the Qiskit OQ3 exporter does
# not / cannot handle `ParameterExpression` well on output, and often outputs things
# like that. That's invalid OQ3, but it's better to support Qiskit's dodgy output
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue tracking this in the language specification? Or was this already discussed and decided that this should not be allowed. It seems odd to me though if this was the decision since it seems pretty natural to perform arithmetic operations between an angle and a float.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An angle is an integer-like representation as fractions of $2\pi$, and was more intended for exact calculations and for close-to-QPU classical hardware that doesn't have floating-point calculations at runtime, so when it's been previously discussed, it was deliberate that float doesn't interact with angle. That said, there's still awkwardnesses in the whole model around the angle type being naturally defined on a ring.

@jakelishman jakelishman merged commit 286176e into Qiskit:main Jun 13, 2024
6 checks passed
@jakelishman jakelishman deleted the float-context branch June 13, 2024 09:07
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

Successfully merging this pull request may close these issues.

Computations within gate parameters leads to Parsing Error
2 participants