SummedOp updates & optimization converters to use Opflow#1059
Conversation
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. |
* 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 <manoel@us.ibm.com>
…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 <manoel@us.ibm.com>
…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 <manoel@us.ibm.com>
…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 <manoel@us.ibm.com>
…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 <manoel@us.ibm.com>
…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 <manoel@us.ibm.com>
Summary
#1077 should be merged first.
Update the converters in the optimization module to accept and return
OperatorBaseobjects (WeightedPauliOperatoris supported as before). Also adds anequalsimplementation toSummedOpwhich was necessary for the tests to work and movessimplifyintoreduceas suggested in #1000 (comment).Marked ason holdto give @t-imamichi time for some performance checks.WIP: Need to fix set comparison if\SummedOpcontains other primitives than justPauliOp.Details and comments
equalshas been updated such that expressions such asX + X == 2*XandX + Z == Z + Xevaluate to True, unlike before. This callsreduceon the operators and is is slower than the previousequalsused inListOpI removed two lines ofaddwhich 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 = 2XandXZ = ZXequivalencies.simplifyhas been renamed tocollapse_summandsto be more descriptive and such that users have one distinct method they should call to reduce/simplify the operator, namelyreduce.