-
Notifications
You must be signed in to change notification settings - Fork 376
SummedOp updates & optimization converters to use Opflow #1059
Conversation
…to summed-op-compare
leads to problems if the coeff is exponentitated and not supposed to be complex
I checked the performance with some Hamiltonians of molecules and confirmed that it works well. |
…to summed-op-compare
* explicitly raise an error upon ListOp input * return identity op instead of the int 0
@Cryoris seems like this PR causes troubles in the build pipeline. |
Indeed there seems the word From the CI log:
Thanks for the info! |
Haven't looked into details but some other PRs(including my own) are failing at
|
Not sure why that happens, but in #1100 @manoelmarques also had to change the input to |
Just curious, something in this PR caused this behavior or the problem somewhere else? |
Pretty sure this is from somewhere else, as this PR didn't touch |
Thanks for the update, a pretty large PR in terra as I see. |
…unity#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
…unity#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
…unity/qiskit-aqua#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
…unity/qiskit-aqua#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
…unity/qiskit-aqua#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
…unity/qiskit-aqua#1059) * simplify and reduce, add equals to SummedOp, update tests * directly use new opflow, no need to go via WPO * update comments and docstrings * directly use opflow * don't do equality check in add * directly use opflow * change order in reduce * fix qaoa * add short test on summed op equality * rm prints * use set comparison, rename simplify to collapse_summands * fix expected value, should be sqrt(2), not 2 * cast coeffs to complex * add reno on equals * fix mypy * fix spell * fix lint * dont cast coefficient to complex leads to problems if the coeff is exponentitated and not supposed to be complex * use sum instead of reduce * rm unused import * move __hash__ to primitive op and base on repr * use != over not == * add summed op test for different primitives * check for opbase, not summedop * adress changes from review * explicitly raise an error upon ListOp input * return identity op instead of the int 0 * fix spell * add note that equals is not mathematically sound Co-authored-by: Manoel Marques <[email protected]>
Summary
#1077 should be merged first.
Update the converters in the optimization module to accept and return
OperatorBase
objects (WeightedPauliOperator
is supported as before). Also adds anequals
implementation toSummedOp
which was necessary for the tests to work and movessimplify
intoreduce
as suggested in #1000 (comment).Marked ason hold
to give @t-imamichi time for some performance checks.WIP: Need to fix set comparison if\SummedOp
contains other primitives than justPauliOp
.Details and comments
equals
has been updated such that expressions such asX + X == 2*X
andX + Z == Z + X
evaluate to True, unlike before. This callsreduce
on the operators and is is slower than the previousequals
used inListOp
I removed two lines ofadd
which checked if other is equal to self, as this adds a lot of overhead e.g. if many Pauli terms are summed. Since the opflow focuses on ease-of-use and intuitive syntax close to math, I think it is very important to haveX + X = 2X
andXZ = ZX
equivalencies.simplify
has been renamed tocollapse_summands
to be more descriptive and such that users have one distinct method they should call to reduce/simplify the operator, namelyreduce
.