Skip to content

Commit

Permalink
Merge branch 'fix_release_issues' of https://github.com/qiboteam/qibo…
Browse files Browse the repository at this point in the history
…chem into fix_release_issues
  • Loading branch information
TL231 committed Dec 18, 2023
2 parents c795067 + 8e54ffe commit 5550a85
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def setup(app):
app.add_css_file("css/style.css")
# Register a sphinx.ext.autodoc.between listener to ignore everything
# between lines that contain the word IGNORE
app.connect('autodoc-process-docstring', between('^.*IGNORE.*$', exclude=True))
app.connect("autodoc-process-docstring", between("^.*IGNORE.*$", exclude=True))
return app


Expand Down
4 changes: 0 additions & 4 deletions lih.xyz

This file was deleted.

2 changes: 1 addition & 1 deletion src/qibochem/driver/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def hamiltonian(
if ham_type in ("s", "sym"):
# Qibo SymbolicHamiltonian
return symbolic_hamiltonian(ham)
raise NameError(f"Unknown {ham_type}!") # Shouldn't ever reach here
# raise NameError(f"Unknown {ham_type}!") # Shouldn't ever reach here

@staticmethod
def eigenvalues(hamiltonian):
Expand Down
4 changes: 4 additions & 0 deletions tests/data/h2.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2

H 0.0 0.0 0.0
H 0.0 0.0 0.7
4 changes: 4 additions & 0 deletions tests/data/lih.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
2
0 1
Li 0.0 0.0 0.0
H 0.0 0.0 1.2
47 changes: 44 additions & 3 deletions tests/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,59 @@ def test_run_pyscf():

def test_run_pyscf_molecule_xyz():
"""Pyscf driver with xyz file"""
path = "./lih.xyz"
path = "./tests/data/lih.xyz"
check_file = os.path.exists(path)
if check_file == False:
with open("lih.xyz", "a") as file:
with open("./tests/data/lih.xyz", "a") as file:
file.write("2\n 0 1\n Li 0.0 0.0 0.0\n H 0.0 0.0 1.2")
lih_ref_energy = -7.83561582555692
lih = Molecule(xyz_file="lih.xyz")
lih = Molecule(xyz_file="./tests/data/lih.xyz")
lih.run_pyscf()

assert lih.e_hf == pytest.approx(lih_ref_energy)


def test_run_pyscf_molecule_xyz_charged():
path = "./tests/data/h2.xyz"
check_file = os.path.exists(path)
if check_file == False:
with open("./tests/data/h2.xyz", "a") as file:
file.write("2\n \n H 0.0 0.0 0.0\n H 0.0 0.0 0.7")
h2_ref_energy = -1.117349035
h2 = Molecule(xyz_file="./tests/data/h2.xyz")
h2.run_pyscf()

assert h2.e_hf == pytest.approx(h2_ref_energy)


def test_molecule_custom_basis():
mol = Molecule([("Li", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 1.2))], 0, 1, "6-31g")
mol.run_pyscf()
assert np.isclose(mol.e_hf, -7.94129296352493)


def test_hf_embedding_1():
mol = Molecule([("Li", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 1.2))])
mol.run_pyscf()
ref_oei = mol.oei
ref_tei = mol.tei
mol.hf_embedding()
embed_oei = mol.embed_oei
embed_tei = mol.embed_tei
assert np.allclose(embed_oei, ref_oei)
assert np.allclose(embed_tei, ref_tei)


def test_hf_embedding_2():
mol = Molecule([("Li", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 1.2))])
mol.run_pyscf()
mol.frozen = [0]
mol.active = [1, 2]
mol.hf_embedding()
assert mol.n_active_orbs == 4
assert mol.n_active_e == 2


def test_fermionic_hamiltonian():
h2 = Molecule([("H", (0.0, 0.0, 0.0)), ("H", (0.0, 0.0, 0.7))])
h2.run_pyscf()
Expand Down

0 comments on commit 5550a85

Please sign in to comment.