This repository has been archived by the owner on Dec 7, 2021. It is now read-only.
Error in Operator() addition/subtraction in- and out-of-place #622
Labels
type: bug
Something isn't working
Informations
What is the current behavior?
When adding or subtracting Operator() objects, the output is not the result of the operation, but the original operator.
Steps to reproduce the problem
from qiskit.quantum_info import Pauli
from qiskit.aqua import Operator
import copy
aux = Operator(paulis=[(1.0,Pauli(label='II'))])
aux.to_matrix()
print('op1=',aux.matrix)
aux2 = Operator(paulis=[(1.0,Pauli(label='ZI'))])
aux2.to_matrix()
print('op2=',aux2.matrix)
print('---Out-of-place subtraction')
print(aux.matrix-aux2.matrix)
aux3 = aux - aux2
print(aux3.matrix)
print('---Out-of-place addition')
print(aux.matrix+aux2.matrix)
aux3 = aux + aux2
print(aux3.matrix)
print('---In-place subtraction')
aux3 = copy.deepcopy(aux)
print(aux3.matrix)
print(aux.matrix-aux2.matrix)
aux3 -= aux2
print(aux3.matrix)
print('---In-place addition')
aux3 = copy.deepcopy(aux)
print(aux3.matrix)
print(aux3.matrix+aux2.matrix)
aux3 += aux2
print(aux3.matrix)
What is the expected behavior?
The expected solution is that the third row of each example should be equal to the second row.
Suggested solutions
Fix the Operator() method auxiliary function _extend_or_combine()
The text was updated successfully, but these errors were encountered: