Skip to content

Commit

Permalink
add tests for hamiltonian f, q
Browse files Browse the repository at this point in the history
  • Loading branch information
damarkian committed Dec 18, 2023
1 parent b6e7ba4 commit 121dad5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
import pytest
import openfermion
from qibo import gates, models
from qibo.hamiltonians import SymbolicHamiltonian
from qibo.symbols import X, Y, Z
Expand Down Expand Up @@ -101,6 +102,25 @@ def test_fermionic_hamiltonian():
assert np.allclose(h2_ferm_ham.one_body_tensor, ref_one_body_tensor)


def test_fermionic_hamiltonian_2():

h2 = Molecule([("H", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 0.7414))])
h2.run_pyscf()

h2_ferm_ham_1 = h2.hamiltonian("f", h2.oei, h2.tei)
h2_qub_ham_jw_1 = h2.hamiltonian("q", h2.oei, h2.tei, ferm_qubit_map="jw")
h2_qub_ham_bk_1 = h2.hamiltonian("q", h2.oei, h2.tei, ferm_qubit_map="bk")
# h2_mol_ham has format of InteractionOperator
h2_mol_ham = hamiltonian.fermionic_hamiltonian(h2.oei, h2.tei, h2.e_nuc)
h2_ferm_ham_2 = openfermion.transforms.get_fermion_operator(h2_mol_ham)
h2_qub_ham_jw_2 = openfermion.jordan_wigner(h2_mol_ham)
h2_qub_ham_bk_2 = openfermion.bravyi_kitaev(h2_mol_ham)

assert h2_ferm_ham_2.isclose(h2_ferm_ham_1)
assert h2_qub_ham_jw_2.isclose(h2_qub_ham_jw_1)
assert h2_qub_ham_bk_2.isclose(h2_qub_ham_bk_1)


def test_parse_pauli_string_1():
pauli_string = ((0, "X"), (1, "Y"))
qibo_pauli_string = hamiltonian.parse_pauli_string(pauli_string, 0.5)
Expand Down

0 comments on commit 121dad5

Please sign in to comment.