-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganise unit tests to better match source layout (#122)
* rename test files * default to showing 10 slowest tests * move pyscf interop tests * move ipu tests * remove duplicated test case * remove redundant parametrize on test_gto
- Loading branch information
1 parent
9ca8e13
commit 8b0ee07
Showing
5 changed files
with
94 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[pytest] | ||
addopts = -s -v | ||
addopts = -s -v --durations=10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright (c) 2023 Graphcore Ltd. All rights reserved. | ||
import jax.numpy as jnp | ||
import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
from pyscf_ipu.experimental.device import has_ipu, ipu_func | ||
from pyscf_ipu.experimental.integrals import kinetic_primitives, overlap_primitives | ||
from pyscf_ipu.experimental.primitive import Primitive | ||
|
||
|
||
@pytest.mark.skipif(not has_ipu(), reason="Skipping ipu test!") | ||
def test_overlap(): | ||
from pyscf_ipu.experimental.integrals import _overlap_primitives | ||
|
||
a, b = [Primitive()] * 2 | ||
actual = ipu_func(_overlap_primitives)(a, b) | ||
assert_allclose(actual, overlap_primitives(a, b)) | ||
|
||
|
||
@pytest.mark.skipif(not has_ipu(), reason="Skipping ipu test!") | ||
def test_kinetic(): | ||
from pyscf_ipu.experimental.integrals import _kinetic_primitives | ||
|
||
a, b = [Primitive()] * 2 | ||
actual = ipu_func(_kinetic_primitives)(a, b) | ||
assert_allclose(actual, kinetic_primitives(a, b)) | ||
|
||
|
||
@pytest.mark.skipif(not has_ipu(), reason="Skipping ipu test!") | ||
def test_nuclear(): | ||
from pyscf_ipu.experimental.integrals import _nuclear_primitives | ||
|
||
# PyQuante test case for nuclear attraction integral | ||
a, b = [Primitive()] * 2 | ||
c = jnp.zeros(3) | ||
actual = ipu_func(_nuclear_primitives)(a, b, c) | ||
assert_allclose(actual, -1.595769, atol=1e-5) | ||
|
||
|
||
@pytest.mark.skipif(not has_ipu(), reason="Skipping ipu test!") | ||
def test_eri(): | ||
from pyscf_ipu.experimental.integrals import _eri_primitives | ||
|
||
# PyQuante test cases for ERI | ||
a, b, c, d = [Primitive()] * 4 | ||
actual = ipu_func(_eri_primitives)(a, b, c, d) | ||
assert_allclose(actual, 1.128379, atol=1e-5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright (c) 2023 Graphcore Ltd. All rights reserved. | ||
import jax.numpy as jnp | ||
import numpy as np | ||
import pytest | ||
from numpy.testing import assert_allclose | ||
|
||
from pyscf_ipu.experimental.basis import basisset | ||
from pyscf_ipu.experimental.interop import to_pyscf | ||
from pyscf_ipu.experimental.mesh import electron_density, uniform_mesh | ||
from pyscf_ipu.experimental.structure import molecule | ||
|
||
|
||
@pytest.mark.parametrize("basis_name", ["sto-3g", "6-31g**"]) | ||
def test_to_pyscf(basis_name): | ||
mol = molecule("water") | ||
basis = basisset(mol, basis_name) | ||
pyscf_mol = to_pyscf(mol, basis_name) | ||
assert basis.num_orbitals == pyscf_mol.nao | ||
|
||
|
||
def test_gto(): | ||
from pyscf.dft.numint import eval_rho | ||
|
||
# Atomic orbitals | ||
basis_name = "6-31+g" | ||
structure = molecule("water") | ||
basis = basisset(structure, basis_name) | ||
mesh, _ = uniform_mesh() | ||
actual = basis(mesh) | ||
|
||
mol = to_pyscf(structure, basis_name) | ||
expect_ao = mol.eval_gto("GTOval_cart", np.asarray(mesh)) | ||
assert_allclose(actual, expect_ao, atol=1e-6) | ||
|
||
# Molecular orbitals | ||
mf = mol.KS() | ||
mf.kernel() | ||
C = jnp.array(mf.mo_coeff, dtype=jnp.float32) | ||
actual = basis.occupancy * C @ C.T | ||
expect = jnp.array(mf.make_rdm1(), dtype=jnp.float32) | ||
assert_allclose(actual, expect, atol=1e-6) | ||
|
||
# Electron density | ||
actual = electron_density(basis, mesh, C) | ||
expect = eval_rho(mol, expect_ao, mf.make_rdm1(), "lda") | ||
assert_allclose(actual, expect, atol=1e-6) |
File renamed without changes.