Description
Hello,
I was playing with the trotterize_exp_qubop_to_qasm
function, and I think it may be outputting incorrect circuits. I have constructed the following minimal broken example to demonstrate.
If we consider the Hamiltonian
To perform this evolution, we can use the first order Trotter formula
If we approximate this series using
According to the documentation for Cirq, the definition for cirq.Rx
is Rx(rads) = exp(-i X rads / 2)
and the definition for cirq.Rz
is Rz(rads) = exp(-i Z rads / 2)
. This means that the qasm circuit for the above described problem would be the following (note that I am using the identity that Rx(rads) = H Rz(rads) H to be consistent with the output of trotterize_exp_qubop_to_qasm
)
H 0
Rz 2.0 0
H 0
Rz 2.0 0
However, when I implement the circuit in openfermion using the following code:
import openfermion as of
H = of.QubitOperator('X0') + of.QubitOperator('Z0')
trotter_generator = of.trotterize_exp_qubop_to_qasm(H, evolution_time = 1)
[print(op) for op in trotter_generator]
the output is the following:
H 0
Rz 1.0 0
H 0
Rz 1.0 0
which implies that the rotation angles are half of what they should be. I believe that the bug arises from src/openfermion/circuits/trotter_exp_to_qgates.py
in the function pauli_exp_to_qasm
at lines 250 and 254. In these lines, the factor of 2 is not multiplied in and seems to cause the issue.
I am not sure whether there are more instances of this potential mistake in the code base. Hopefully my logic is sound, and I am not just missing something.
Thank you.