From 121dad5767e983fbddd95120e519a73c30e1e666 Mon Sep 17 00:00:00 2001 From: Adrian Mak Date: Mon, 18 Dec 2023 19:23:36 +0800 Subject: [PATCH] add tests for hamiltonian f, q --- tests/test_molecule.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/test_molecule.py b/tests/test_molecule.py index d690de4..77735fc 100644 --- a/tests/test_molecule.py +++ b/tests/test_molecule.py @@ -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 @@ -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)