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

Check for multiples of pi at operator construction time #993

Closed
wants to merge 2 commits into from

Conversation

notmgsk
Copy link
Contributor

@notmgsk notmgsk commented Sep 12, 2019

Rather than trying to figure it out at the time of printing.

Closes #943.

Checklist

  • The above description motivates these changes.
  • There is a unit test that covers these changes.
  • All new and existing tests pass locally and on Semaphore.
  • Parameters have type hints with PEP 484 syntax.
  • Functions and classes have useful sphinx-style docstrings.
  • (New Feature) The docs have been updated accordingly.
  • (Bugfix) The associated issue is referenced above using auto-close keywords.
  • The changelog is updated, including author and PR number (@username, gh-xxx).

@notmgsk notmgsk changed the title Check for multiples of pi at op construction time Check for multiples of pi at arithmetic operator construction time Sep 12, 2019
@notmgsk notmgsk marked this pull request as ready for review September 13, 2019 15:05
@notmgsk notmgsk requested a review from a team as a code owner September 13, 2019 15:05
@notmgsk notmgsk added this to the v2.12 milestone Sep 13, 2019
Copy link
Contributor

@ecpeterson ecpeterson left a comment

Choose a reason for hiding this comment

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

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

@@ -549,11 +552,11 @@ def _check_for_pi(element):
elif abs(num) == 1 and den == 1:
return sign + "pi"
elif abs(num) == 1:
return sign + "pi/" + repr(den)
Copy link
Contributor

Choose a reason for hiding this comment

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

update the docstring to reflect the return type

@notmgsk
Copy link
Contributor Author

notmgsk commented Sep 13, 2019

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

Does pyQVM support parameteric programs? Even so, I should better understand the parameter model and make sure I'm not polluting it.

@notmgsk notmgsk added the work in progress 🚧 This PR is not ready to be merged. label Sep 13, 2019
@karalekas
Copy link
Contributor

@notmgsk you're going to want to pull this branch when you start working again. also, can you come up with a PR title that is a bit shorter (~50 chars)? thanks!

@karalekas karalekas added the bug 🐛 An issue that needs fixing. label Sep 15, 2019
@notmgsk notmgsk changed the title Check for multiples of pi at arithmetic operator construction time Check for multiples of pi at operator construction time Sep 23, 2019
@notmgsk
Copy link
Contributor Author

notmgsk commented Sep 23, 2019

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

In retrospect, I don't think this is an issue. Expressions already consumed strings, and it hasn't been an issue thus far. I don't think this is the most pleasant solution, but I also don't want to this to snowball into a much larger rewrite. Closing #995 will probably ease some concern.

Rather than trying to figure it out before printing.

ffffflake
@notmgsk notmgsk removed the work in progress 🚧 This PR is not ready to be merged. label Sep 23, 2019
@appleby
Copy link
Contributor

appleby commented Sep 25, 2019

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

In retrospect, I don't think this is an issue. Expressions already consumed strings, and it hasn't been an issue thus far. ...

Over in my type hints PR, I assumed they only consumed Union[Expression, int, float, complex]. I certainly might have got the type wrong. Do you have an example in mind of when they take a string? I assumed that all parameters or memory references would already be boxed into the corresponding Parameter and MemoryReference classes by the time an Expression sees them.

@notmgsk
Copy link
Contributor Author

notmgsk commented Sep 25, 2019

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

In retrospect, I don't think this is an issue. Expressions already consumed strings, and it hasn't been an issue thus far. ...

Over in my type hints PR, I assumed they only consumed Union[Expression, int, float, complex]. I certainly might have got the type wrong. Do you have an example in mind of when they take a string? I assumed that all parameters or memory references would already be boxed into the corresponding Parameter and MemoryReference classes by the time an Expression sees them.

Sure: Div("pi")

@appleby
Copy link
Contributor

appleby commented Sep 25, 2019

One concrete comment. Also, one nebulous concern: is there any danger in adding str to the possible types of the operands for Mul and Div and then using the resulting trees (say, in pyQVM) to evaluate parameters? Do all interested parties know how to convert "pi" back out to pi?

In retrospect, I don't think this is an issue. Expressions already consumed strings, and it hasn't been an issue thus far. ...

Over in my type hints PR, I assumed they only consumed Union[Expression, int, float, complex]. I certainly might have got the type wrong. Do you have an example in mind of when they take a string? I assumed that all parameters or memory references would already be boxed into the corresponding Parameter and MemoryReference classes by the time an Expression sees them.

Sure: Div("pi")

You can pass the Div constructor anything because it doesn't check the types.

In [139]: pq.quilatom.Div(range(3), range(3))
Out[148]: Div(range(0, 3),range(0, 3))

What I meant was are there any examples where a BinaryExpr actually winds up getting an unboxed string in current pyquil usage. I will do another grep search. Previously I was trying to be clever and grep for occurrence with string literals, but I should probably just do an exhaustive search. Hopefully there aren't too many places where these get instantiated...

@notmgsk
Copy link
Contributor Author

notmgsk commented Sep 25, 2019

Closing out of frustration. The solution is ugly and I can't decide whether it will break other stuff. Will return another day.

@notmgsk notmgsk closed this Sep 25, 2019
@karalekas karalekas removed this from the v2.12 milestone Sep 26, 2019
@karalekas karalekas deleted the fix/parens-order-of-ops-div branch December 30, 2019 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue that needs fixing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pretty-printed pi-products are not properly parenthesized
4 participants