0
$\begingroup$

I have the problem when I run my code

# define Hamiltonian
from qiskit.opflow import PauliSumOp, X, I, Z, Y
H = ((X^(I)^I))+ (X^I^I) + ((X^(I^(2))*2/2)/2) + (X^I^I) + (X^Z^I) + (X^I^I/3)
H += (I^I^X)

print(H)

the result is

3.5 * XII
+ 1.0 * XZI
+ 0.3333333333333333 * XII
+ 1.0 * IIX

The problem is I don't know why the qiskit.opflow doesn't combine two terms of XII tensor together. I have worked on it for a while but have not worked, so I hope for your help, tks.

$\endgroup$

1 Answer 1

2
$\begingroup$

You will need to call reduce() method to simplify it:

print(H.reduce())
$\endgroup$
1
  • $\begingroup$ Oh, thanks. Really appreciate $\endgroup$ Feb 28, 2023 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.