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

SummedOp: chop summands with a coefficient of 0 #5745

Closed
Cryoris opened this issue Jul 3, 2020 · 11 comments
Closed

SummedOp: chop summands with a coefficient of 0 #5745

Cryoris opened this issue Jul 3, 2020 · 11 comments
Labels
good first issue Good for newcomers mod: opflow Related to the Opflow module

Comments

@Cryoris
Copy link
Contributor

Cryoris commented Jul 3, 2020

What is the expected enhancement?

>>> from qiskit.aqua.operators import I, X
>>> (0 * X + I) == I
False  # should be True

A possible solution would be to add a SummedOp.chop_summands(threshold=0) method that is added as default call in SummedOp.reduce, analogous to collapse_summands. With the threshold argument the user can choose what to chop: all summands with a coefficient smaller than threshold are removed.

This is equivalent to WeightedPauliOperator.chop.

@spencerking
Copy link

@Cryoris I'd like to work on this issue, if that's fine with you

@Cryoris
Copy link
Contributor Author

Cryoris commented Jul 6, 2020

Sure, that would be great! Feel free to reach out for questions, if you have any 🙂 Once you have a draft ready you can also open a pull-request for us to look at.

@VANRao-Stack
Copy link

Hey @spencerking how is this going? Mind if I try?

@spencerking
Copy link

@VANRao-Stack I actually just got started on this yesterday. If I don't make progress this weekend I'll let you know and you can give it a shot.

@VANRao-Stack
Copy link

VANRao-Stack commented Jul 18, 2020

@VANRao-Stack I actually just got started on this yesterday. If I don't make progress this weekend I'll let you know and you can give it a shot.

Any updates @spencerking?

@spencerking
Copy link

@VANRao-Stack I'm going to make a WIP PR to get some feedback. I think I've got the general idea but haven't gotten much feedback on Slack.

@shifubear
Copy link
Contributor

Hey! I might have come up with a new method to resolve this problem. Can I open a pull request?

@JosephDenman
Copy link

JosephDenman commented Sep 21, 2020

@shifubear I just finished implementing it. I'm writing tests, then I'll have a PR out.

@shifubear
Copy link
Contributor

shifubear commented Sep 21, 2020

@JosDenmark Dang, I was in the process of writing tests as well. In that case, I'll keep an eye out for your PR before I do anything else. :)

@JosephDenman
Copy link

Many thanks 🙏

JosephDenman referenced this issue in JosephDenman/qiskit-aqua Sep 21, 2020
Fixes #1096

`>>> from qiskit.aqua.operators import I, X
>>> (0 * X + I) == I
False  # should be True`

Now, we have `(0 * X + I).filter_ops_by_coeff(0, 0) == I` is true.
JosephDenman referenced this issue in JosephDenman/qiskit-aqua Sep 22, 2020
Fixes #1096

`>>> from qiskit.aqua.operators import I, X
>>> (0 * X + I) == I
False  # should be True`

Now, we have `(0 * X + I).filter_ops_by_coeff(0, 0) == I` or `(0 * X + I).collapse_summands() == I` is true.
@woodsp-ibm woodsp-ibm transferred this issue from qiskit-community/qiskit-aqua Jan 29, 2021
@woodsp-ibm woodsp-ibm added mod: opflow Related to the Opflow module good first issue Good for newcomers labels Jan 29, 2021
@1ucian0
Copy link
Member

1ucian0 commented May 21, 2022

I think this is closed via #7681

@1ucian0 1ucian0 closed this as completed May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers mod: opflow Related to the Opflow module
Projects
None yet
Development

No branches or pull requests

7 participants