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.
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
Duration
type in classical expressions. #13844[Stretch] Support
Duration
type in classical expressions. #13844Changes from 93 commits
af4ba52
e423bf9
0a5917b
a97434d
1afc965
86655f1
aaeae9b
a2a444b
8ac2dc3
9f8313c
db9d9cb
71b7e7a
2091557
7307be9
9b30284
ce1faf1
4fee48f
88ab046
c5a230f
7c88d88
c58a7b8
d9e9a8c
4a56150
23b5961
8bf2e4f
111eb32
a839d51
a19b39a
7f02e56
55af327
86b7af9
9b3c821
69eab91
971cc26
25508bf
2c8ce43
ccf9441
c6eab02
edd7806
8afa92e
4e0f2df
15ba943
81c5833
50c31d3
7e43322
2449ee6
e55e189
1d51022
eb8f150
415f62e
d38f3e9
fd66c1d
e9b6d97
52da3cc
a3be688
07771f1
9332ed3
17241c6
ca91bfd
ad87e78
d3bca5f
50deb93
f1dc1a1
1f439a0
166d7b2
10b2c8d
9d6cf39
8021e00
a15141b
ca2785d
e902009
16475c3
6b5930d
be73180
25f1693
ecc343b
b32e6f0
864506d
6bc728a
2d38178
42258b8
481700a
e09762f
cbd55db
f12afb4
8d059cd
e05d9ff
0f14cca
7db8222
34e615b
bbe67a6
0acc450
7fea216
78b2951
97bbeba
49f2af8
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a nuisance in Python 3.9. Perhaps cleaner to add a
unit
pyfunction that returns the string name, so you can dispatch on it? E.g.then Python-space has a cheaper way of doing the dispatch programmatically, and it maybe provides a slightly easier link with the legacy
(value, unit)
2-tuple.I'd say that ^that particular one is a candidate for doing in this PR (if you think it's worthwhile), but ones that would certainly be follow-ups if we wanted them to be: this class is a sensible place to add methods like
as_seconds(self) -> f64
,as_dt(self, dt_in_seconds) -> u64
, etc, which would be useful if/when we swap to using this more in the internals.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 78b2951.
I also added a
py_value
method to get the int or float (exposed in Python asDuration.value()
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just semantics: my reading was we give-or-take decided to interpret the OQ3 spec as saying that
stretch x;
didn't involve a typestretch
so much as just being a special keyword for aduration
-typed declaration. I'm also fine to leave it the way we have (heaven knows this AST is a jumble), but in another world: would it make more sense to handlestretch x (= Expr)?;
as arather than a type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, that makes a ton more sense. We don't use this in this PR anyway, so if it's alright, I'll leave it for now and make the switch in the PR that actually does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
circuit.Duration
is still a Python type, tbfI think there's a risk with using
t
: I think that type code is already used elsewhere to represent "tuple", and there's a risk of a clash (despite the organisational structure ontype_keys.py
, the enums in there are not necessarily separate namespaces in QPY land). That said, I thinkEXPR_VALUE
is localised enough that it can never hit the clash, butPARAM_TYPE
would. Up to you if you think it's worth changing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not be understanding. Are you saying that we should try to have unique characters across all of
type_keys.py
in case we introduce a bug that reads/writes a byte in the wrong place? My understanding of these is that we're manually reading / writing a byte that can only be one of e.g.TypeKeys.ExprType.<KEYS>
in the place that we're reading / writing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember the exact circumstances, but I remember having trouble with QPY at one point because there were locations where type keys from more than one
TypeKeys.<Thing>
were valid choices - I think the abstraction is leaky.That said, given that I added the
ExprType
ones after that, I'm relatively sure that it's not a problem here, so it's ok to leave.