-
Notifications
You must be signed in to change notification settings - Fork 12
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
Implement parsing measure
from text through ASG
#42
Merged
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
jakelishman
reviewed
Jan 17, 2024
Comment on lines
+575
to
+585
// FIXME: type may not be correct here. | ||
// This assumes a single qubit is measured. | ||
pub fn to_texpr(self) -> TExpr { | ||
TExpr::new(Expr::MeasureExpression(self), Type::Bit(IsConst::False)) | ||
} |
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 think the type map should be fairly straightforwards, if the program is semantically correct:
let out_type = match self.operand.get_type() {
Type::Qubit => Ok(Type::Bit(IsConst::False)),
Type::QubitArray(dims) => Ok(Type::BitArray(dims.clone(), IsConst::False)),
_ => Err(<type error>),
}?;
Statements like `c = measure q` are analyzed correctly. But `c[0] = measure q` is not analyzed correctly. The code that builds the assignment statement assumes the LHS is an identifier. The ASG should be able to handle valid lvalues. But we cannot yet construct statements with them.
This is done twice and is several lines, so it is a function now.
jlapeyre
force-pushed
the
measure-panic
branch
from
January 18, 2024 20:47
f5f6a40
to
300efc7
Compare
This is unrelated to measurement.
jlapeyre
changed the title
Partially implement parsing
Implement parsing Jan 19, 2024
measure
from text through ASGmeasure
from text through ASG
`GateOperand` is a qubit argument to gate call. And arguments to `measure` have the same spec. Identifier, hardware identifier, or indexed identifier. So we reuse the code from gate call. The code in oq3_parser is a bit mysterious. I added some comments to make it easier to locate next time, I hope.
jlapeyre
force-pushed
the
measure-panic
branch
from
January 19, 2024 00:42
43cacee
to
c2ce523
Compare
This was referenced Jan 19, 2024
jlapeyre
added a commit
that referenced
this pull request
Jan 19, 2024
All of the failing examples given in #38 are included as (passing) tests. Either in this PR or in earlier PRs. Part of the fix for #38 was done in #42, which implemented measure. The other part of the fix for #38 is in the present PR, which allows indexed identifiers as lvalues in assignment. Closes #38
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.
Statements like
c = measure q
are analyzed correctly. Butc[0] = measure q
is not analyzed correctly. The code that builds the assignment statement assumes the LHS is an identifier. The ASG should be able to handle valid lvalues. But we cannot yet construct statements with them.EDIT: This will address part of issue #38. But not all
This PR is intended to allow
measure
to work properly. But assignment to an indexed identifier is still broken. However, the latter is a more general issue and will be fixed in a future PR.See the tests in "Files changed" to see examples of what has been fixed.