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

Bug in QuadraticHamiltonian diagonalization #771

Closed
kevinsung opened this issue Feb 7, 2022 · 0 comments · Fixed by #772
Closed

Bug in QuadraticHamiltonian diagonalization #771

kevinsung opened this issue Feb 7, 2022 · 0 comments · Fixed by #772
Labels

Comments

@kevinsung
Copy link
Collaborator

The following code raises an error:

import numpy as np
import openfermion as of

hermitian_part = np.array(
    [[0.0, 1.0, 0.0],
     [1.0, 0.0, 1.0],
     [0.0, 1.0, 0.0]],
    dtype=complex
)
antisymmetric_part = np.array(
    [[0.0, 1.0j, 0.0],
     [-1.0j, 0.0, 1.0j],
     [0.0, -1.0j, 0.0]],
    dtype=complex
)

hamiltonian_quad = of.QuadraticHamiltonian(hermitian_part, antisymmetric_part)
hamiltonian = of.get_fermion_operator(hamiltonian_quad)
hamiltonian_jw = of.get_sparse_operator(of.jordan_wigner(hamiltonian))

orbital_energies, transformation_matrix, constant = hamiltonian_quad.diagonalizing_bogoliubov_transform()
occupied_orbitals = (1,)
eig = np.sum(orbital_energies[list(occupied_orbitals)]) + constant

circuit = of.prepare_gaussian_state(
    cirq.LineQubit.range(3),
    hamiltonian_quad,
    occupied_orbitals=occupied_orbitals)
state = cirq.final_state_vector(circuit, dtype=np.complex128)

np.testing.assert_allclose(hamiltonian_jw @ state, eig * state, atol=1e-8)

This is due to an incorrect assumption in the QuadraticHamiltonian code regarding the format of the Schur decomposition.

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

Successfully merging a pull request may close this issue.

1 participant