Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trotter evolution time may be off by a factor of 2 #876

Open
zmorrell opened this issue Apr 10, 2024 · 2 comments
Open

Trotter evolution time may be off by a factor of 2 #876

zmorrell opened this issue Apr 10, 2024 · 2 comments

Comments

@zmorrell
Copy link

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 $H = \sigma^x + \sigma^z$, then the expected time evolution of $H$ is given by

$$| \psi(t) \rangle = \exp \left( -i H t \right) | \psi(0) \rangle.$$

To perform this evolution, we can use the first order Trotter formula

$$\exp \left( A + B \right) = \lim_{n \to \infty} \left( \exp{\left( \frac{A}{n} \right)} \exp{\left(\frac{B}{n} \right )} \right)^n.$$

If we approximate this series using $n = 1$ (perform the evolution using a single trotter step) and consider an evolution time of $t = 1$, we obtain

$$|\psi(1) \rangle \approx \exp(-i \sigma^x) \exp(-i \sigma^z) |\psi(0) \rangle$$

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.

@fdmalone fdmalone added the bug label May 11, 2024
@fdmalone
Copy link
Collaborator

This certainly looks like an error or should at least be clarified.

@fdmalone
Copy link
Collaborator

This looks like a duplicate of #721, which should definitely be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants