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

Add __pos__ for Parameter #12496

Merged
merged 7 commits into from
Jun 4, 2024
Merged

Conversation

eendebakpt
Copy link
Contributor

Summary

Add __pos__ for Parameter and ParameterExpression

Details and comments

The implementation is simular to the __neg__

@eendebakpt eendebakpt requested a review from a team as a code owner June 3, 2024 16:10
@qiskit-bot qiskit-bot added the Community PR PRs from contributors that are not 'members' of the Qiskit repo label Jun 3, 2024
@qiskit-bot
Copy link
Collaborator

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 following people are relevant to this code:

  • @Qiskit/terra-core

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

This seems sensible in spirit to me, thanks.

I guess it would have made more sense if we were able to use operator.pos in the _apply_operation, but that function seems to be set up to assume binary operations, so never mind on that front.

I'm not wild about introducing a floating-point number with this, though, and the same goes for __neg__. Definitely feels like we might at least want to make them multiplication by integers rather than floats (if we can't just use operator.pos and operator.neg directly) to avoid introducing imprecisions into the evaluation contexts.

Please could you also add a circuits feature release note about this?

qiskit/circuit/parameterexpression.py Outdated Show resolved Hide resolved
eendebakpt and others added 2 commits June 3, 2024 18:35
Co-authored-by: Jake Lishman <jake@binhbar.com>
@eendebakpt
Copy link
Contributor Author

This seems sensible in spirit to me, thanks.

I guess it would have made more sense if we were able to use operator.pos in the _apply_operation, but that function seems to be set up to assume binary operations, so never mind on that front.

I'm not wild about introducing a floating-point number with this, though, and the same goes for __neg__. Definitely feels like we might at least want to make them multiplication by integers rather than floats (if we can't just use operator.pos and operator.neg directly) to avoid introducing imprecisions into the evaluation contexts.

Please could you also add a circuits feature release note about this?

Multiplication with an int seems nicer indeed. I can change it for this PR, but I am not sure whether there are any implications for __neg__. Let me know

@coveralls
Copy link

coveralls commented Jun 3, 2024

Pull Request Test Coverage Report for Build 9358258610

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.007%) to 89.591%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 1 92.88%
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 88.2%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9327235113: -0.007%
Covered Lines: 62360
Relevant Lines: 69605

💛 - Coveralls

@jakelishman
Copy link
Member

Let's make at least __pos__ be multiplication by integer here. I think we ought to change __neg__ too - if the tests don't complain about it (and hopefully nothing in our test suite depends on that questionable behaviour...), but happy to do that in a follow-up if you prefer.

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Ace, thanks!

@jakelishman jakelishman added Changelog: New Feature Include in the "Added" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Jun 3, 2024
@jakelishman jakelishman added this to the 1.2.0 milestone Jun 3, 2024
@jakelishman jakelishman added this pull request to the merge queue Jun 3, 2024
Merged via the queue into Qiskit:main with commit 797bb28 Jun 4, 2024
15 checks passed
jlapeyre pushed a commit to jlapeyre/qiskit-core that referenced this pull request Jun 5, 2024
* Add __pos__ for ParameterExpression

* docstring

* Update qiskit/circuit/parameterexpression.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Add release note

* replace 1.0 by 1

* black

* Reword release note

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Procatv pushed a commit to Procatv/qiskit-terra-catherines that referenced this pull request Aug 1, 2024
* Add __pos__ for ParameterExpression

* docstring

* Update qiskit/circuit/parameterexpression.py

Co-authored-by: Jake Lishman <jake@binhbar.com>

* Add release note

* replace 1.0 by 1

* black

* Reword release note

---------

Co-authored-by: Jake Lishman <jake@binhbar.com>
Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog Community PR PRs from contributors that are not 'members' of the Qiskit repo mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants