-
Notifications
You must be signed in to change notification settings - Fork 2.5k
#10360 New sign feature in parameterexpression.py #10571
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
Conversation
Thank you for opening a new pull request. Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone. One or more of the the following people are requested to review this:
|
Closes #10360 |
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.
Besides in-line comments, please make sure you follow the bot's comment above about the CLA and add a release note as described here.
It would also be good to have a test in test_parameters.py that uses sign
, though looking now I don't see a test that uses exp
or log
there either.
from sympy import sign | ||
val = self._symbol_expr | ||
sign_value = sign(val) | ||
return sign_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.
In qiskit-terra, we try to use symengine (for performance) and fall back to sympy. You can deal with this the way other functions do by referencing _optionals.HAS_SYMENGINE
. Also, you want to use self._call(func)
rather than just func(val)
because the operation should return another ParameterExpression
.
So I think it should be something like this, though it would be good to check (with and without symengine):
from sympy import sign | |
val = self._symbol_expr | |
sign_value = sign(val) | |
return sign_value | |
if _optionals.HAS_SYMENGINE: | |
import symengine | |
return self._call(symengine.sign) | |
else: | |
from sympy import sign as _sign | |
return self._call(_sign) |
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.
So I did not do self._call(func)
on purpose because the issue requires the return type to be numeric. Other methods like log
would return a ParameterExpression
but I need a numeric.
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.
Why do you need a numeric return type? If the parameter expression is a symbol, don't you need the sign of it to also be a parameter expression until the symbol is assigned a numeric value?
I don't see a file |
The file is here. |
Hi, I made a few changes and created a PR again. I forgot how to do it here directly but I think PR initiated it somewhere else. Here is the link to it: I've signed the CLA. I'm not sure what the second part about adding my email address to this commit to my account is though. |
|
|
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 looking close to ready. Thanks for your work, @SamD-1998!
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
Also, like Raghav noted, the tests are failing because you need to run |
Hey, I ran black and I think the formatting issues are now fixed. Just a couple questions:
|
|
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 this is pretty ready to merge! We just need to clean up the release note a bit and deal the CLA issue as discussed previously.
I put some suggestions in for the release note. Mostly these are pointing out syntax issues. The release notes get rendered with Sphinx, so they should follow Sphinx syntax. See here for a Sphinx reference.
It is a little tricky to test if the release notes syntax is correct. You need to run sphinx to build the docs to look at. In the Azure Pipelines docs run here, there is an artifact that you can download with the docs from the CI run as well, but currently the release notes are missing (until #10656 is merged).
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
from qiskit.circuit import Parameter | ||
|
||
b = Parameter("phi") | ||
sign_value = b.sign() | ||
print("sign of Parameter is: ", sign_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.
from qiskit.circuit import Parameter | |
b = Parameter("phi") | |
sign_value = b.sign() | |
print("sign of Parameter is: ", sign_value) | |
from qiskit.circuit import Parameter | |
b = Parameter("phi") | |
sign_value = b.sign() | |
print("sign of Parameter is: ", sign_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.
I wonder if you want to say something like:
print("Sign of an unassigned Parameter is:", sign_value)
print("Sign of a Parameter assigned to -3 is:", sign_value.assign(b, -3))
--- | ||
features: | ||
- | | ||
Introduced a new feature that adds support for calculating the sign of the Parameter of the value of an expression of a Parameter class. |
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.
Introduced a new feature that adds support for calculating the sign of the Parameter of the value of an expression of a Parameter class. | |
Added support for expressing the sign of a :class:`ParameterExpression`. |
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.
Instead of using numpy or other libraries, the user can use the instance of the ParameterExpression class to calculate the sign. | |
Instead of assigning a concrete value and using ``numpy.sign`` or other library functions, the user can use the instance of the ParameterExpression class to calculate the sign and can work with the sign before the expression is fully assigned. |
Reviewed all recommended changes and pushed a new commit while changing the author information to resolve the CLA issue. I hope it all works out now. Thank you for walking me through all of this! |
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 PR looks almost ready. Something funny might have happened with your editor. Some of the `
that I suggested were '
in your changes. The `
is a special character used by Sphinx. I put some inline suggestions to switch them to what Sphinx needs.
Your name and email looked good on your most recent commit, but that does not rewrite the history for the older commits GitHub is complaining about. We still need to squash down / rewrite the old commits to update the author information. I can do this at the end if you want, but I think part of the goal with this PR is to help your learn the processes around submitting PR's, so I am happy to keep helping you do this on your side.
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
releasenotes/notes/added-sign-feature-parameterexpression-57693dd69103dc8c.yaml
Outdated
Show resolved
Hide resolved
Sorry, @SamD-1998, what you did here is not a viable way to fix the CLA issue. Yet, somehow the CLA check has a green checkmark which I don't understand. Did you add the pop-os.localdomain email address to your GitHub account? I am not sure precisely what you did, but I think you rebased with changes from the main branch merged in which cause those commits to be rewritten and now appear as new commits. This makes it look now like this PR is changing many extra files and has extra authors. I recommend we roll back and try again. I think the commit before was 981c470, so the next steps would be:
if you are calling this branch Sorry about the confusion. I forgot how messy a rebase was after a large branch has been merged in. I think the simplest solution might be to follow the steps given here. In our case, after doing my previous suggestion, this would be something like
Let me know if that works for you. If will squash all the previous work down to one commit which you can write a commit message for. When the pull request is approved and merged, it will be squashed to a single commit any way. |
981c470
to
d751c5d
Compare
Oh that looks essentially like rebasing but manually creating a new branch and merging with the older branch. That's clever. Funnily enough, I'm not sure if I added the pop-os.localdomain to my GitHub at this point since I read a lot of things, tried a lot of things and don't remember all the history. I hope this resolves all the issues. |
The current diff looks good to me. We have your changes with no extra changes. Some of my last suggestions for the release notes formatting have not been applied, but they still show up in GitHub as in-line comments, so please look at those. Also, I still see the pop-os.localdomain email in the first commit c1cd914. It looks like that is a left over initial commit that didn't get squashed. All the changes we want are squashed together in the most recent commit. Maybe you can try the |
Can I ask for some help? The first commit c1cd914 was unaffected because I missed changing its My plan is this:
This order because I had accommodated your formatting suggestions multiple times but the Could you please tell me how to resolve this? |
I would leave the first commit as Did all the commands run without error for the |
fe5b261
to
981c470
Compare
Hmm, you pushed back to an older version without the commits squashed (but still the same final content). Another option you could try (requires
This avoids rebasing and trying rewrite history and just writes your changes to a patch file, resets your branch to upstream/main, and then dumps you changes back out for you to commit as a new clean commit. |
Yes, all commands ran without errors for My The patch file method did not work because the patch file was blank. I read that this indicates that there is no difference between those branches. I feel rebasing is quite hard with a large number of commits present which give a lot of conflicts while interactive rebasing. |
Hmm, there are differences, as long as you didn't reset your local branch to upstream/main. If you want, you can try generating the patch again and try to figure out why it doesn't show your changes. If you want to skip the |
Hi, I ran these commands. I'm not sure if it worked this time around although I've been trying to push the releasenotes with the suggested changes for quite some time now. If the issue still persists, is there a possibility of resolving it on your end? |
53e6676
to
5eaba01
Compare
This method allows applying the sign operation to an expression with possibly unassigned parameters.
5eaba01
to
0c318c2
Compare
Okay, I force pushed a commit with the patch that I shared above with your information for the commit author that matches what the CLA check accpets. This restores the state to the last state you had pushed changes to. I still had some suggestions in-line for the release notes that are valid. Can you address them? You can just accept and commit my suggestions if you want. |
…3dd69103dc8c.yaml Co-authored-by: Will Shanks <wshaos@posteo.net>
…3dd69103dc8c.yaml Co-authored-by: Will Shanks <wshaos@posteo.net>
…3dd69103dc8c.yaml Co-authored-by: Will Shanks <wshaos@posteo.net>
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.
All good now, thanks for working on this!
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.
(proxying Will's approval, since the PR touches files Will's not codeowner on)
Pull Request Test Coverage Report for Build 6265770562
💛 - Coveralls |
Added a new feature in parameterexpression.py to display the sign of an expression
…the expression inputted
Summary
I've added a feature that allows a user to display the sign of an inputted expression using an object of the Parameter class.
Details and comments