-
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
[Stretch] Support Float
type in classical expressions.
#13832
Open
kevinhartman
wants to merge
45
commits into
Qiskit:main
Choose a base branch
from
kevinhartman:expr-float
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This reverts commit e2b3221.
Types that have some natural order no longer have an ordering when one of them is strictly greater but has an incompatible const-ness (i.e. when the greater type is const but the other type is not).
We need to reject types with const=True in QPY until it supports them. For now, I've also made the Index and shift operator constructors lift their RHS to the same const-ness as the target to make it less likely that existing users of expr run into issues when serializing to older QPY versions.
This is probably a better default in general, since we don't really have much use for const except for timing stuff.
Since we're going for using a Cast node when const-ness differs, this will be fine.
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 13444665656Details
💛 - Coveralls |
I wasn't going to have this, but since we have DANGEROUS Float => Int, and we have Int => Bool, I think this makes the most sense.
7ef1159
to
a19b39a
Compare
7 tasks
Also removes the assumption that a const-type can never be an l-value in favor of just restricting l-values with const types from being added to circuits for now. We will (in a separate PR) add support for adding stretch variables to circuits, which are const. However, we may track those differently, or at least not report them as variable when users query the circuit for variables.
This one I'd added thinking I ought to block store from using a const var target. But since I figured it's better to just restrict adding vars to the circuit that are const (and leave the decision of whether or not a const var can be an l-value till later), this test no longer makes sense.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
Float
type to the classical expression system. This is necessary to express timing relationships between durations and stretches in expressions.In a follow-up(s), I'll add
Duration
andStretch
types as well as binary operators for+
,-
,*
and/
, and then plumb all of this into the existing circuit variable tracking infra, integrate with theDelay
instruction, support serialization, etc.Details and comments
Currently based on #13811. Here's a readable diff in the meantime.
Float
type is considered of an "unspecified width", in accordance with the machine-precisionfloat
in OpenQASM3. If we add a fixed-width float (similar to what we've got forUint
), then it shouldn't be difficult to add an optional constructor argument toFloat
forwidth
, defaulted toNone
. I didn't opt to do this since I imagine fixed-width floats aren't desperately needed for stretches, and they would've taken too long to stamp out.expr.lift
now supports Python floats.Uint
orBool
toFloat
to be unsafe.Float
cannot be mixed withUint
in binary operations. You must cast one of them, first.Float
for one reason or another (e.g. not losslessly coercable toBool
). The arithmetic operations to come (+
,-
,*
and/
) will support them.To-do