Skip to content

Commit

Permalink
Formatting and changed tests to functional (#2)
Browse files Browse the repository at this point in the history
* Fixed all test for new format
* Restructured utils functions

---------

Co-authored-by: Anders S. Christensen <andersbiceps@gmail.com>
Co-authored-by: Lars Andersen Bratholm <larsbratholm@gmail.com>
  • Loading branch information
3 people authored Mar 17, 2024
1 parent 68eaf19 commit 6b2c2df
Show file tree
Hide file tree
Showing 44 changed files with 3,014 additions and 3,322 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO Added grep test for src; no print allowed, no assert allowed

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ format:
${python} -m pre_commit run --all-files

test:
${python} -m pytest -rs \
./tests/test_kernels.py \
./tests/test_solvers.py \
./tests/test_distance.py \
./tests/test_slatm.py
${python} -m pytest -rs ./tests

types:
${python} -m monkeytype run $(which pytest) ./tests/
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ applications, but without the high-level abstraction, for example SKLearn.

This package is and should stay free-function design oriented.

Breaking changes from `qml`:

- FCHL representations callable interface to be consistent with other representations (e.i. atoms, coordinates)


====
How to install
====
Expand Down
5 changes: 4 additions & 1 deletion _compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"representations/frepresentations": ["frepresentations.f90"],
"representations/facsf": ["facsf.f90"],
"representations/fslatm": ["fslatm.f90"],
"representations/arad/farad_kernels": ["farad_kernels.f90"],
"representations/fchl/ffchl_module": [
"ffchl_module.f90",
"ffchl_scalar_kernels.f90",
Expand Down Expand Up @@ -41,7 +42,9 @@ def find_flags(fcc: str):
# "-Wno-maybe-uninitialized", "-Wno-unused-function", "-Wno-cpp"]
# LINKER_FLAGS = ["-lgomp"]

flags = ["-L/usr/lib/", "-lblas", "-llapack"]
extra_flags = ["-lgomp", "-lpthread", "-lm", "-ldl"]

flags = ["-L/usr/lib/", "-lblas", "-llapack"] + extra_flags

return flags

Expand Down
1 change: 1 addition & 0 deletions environment_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies:
- monkeytype
- numpy
- pandas
- pyarrow
- pip
- pre-commit
- pytest
Expand Down
6 changes: 3 additions & 3 deletions src/qmllib/kernels/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .distance import *
from .gradient_kernels import *
from .kernels import *
from qmllib.kernels.distance import * # noqa:F403
from qmllib.kernels.gradient_kernels import * # noqa:F403
from qmllib.kernels.kernels import * # noqa:F403
6 changes: 3 additions & 3 deletions src/qmllib/kernels/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def p_distance(A, B, p=2):
The value of the keyword argument ``p =`` sets the norm order.
E.g. ``p = 1.0`` and ``p = 2.0`` with yield the Manhattan and L2 distances, respectively.
.. math:: D_{ij} = \|A_i - B_j\|_p
.. math:: D_{ij} = \\|A_i - B_j\\|_p
Where :math:`A_{i}` and :math:`B_{j}` are representation vectors.
D is calculated using an OpenMP parallel Fortran routine.
Expand All @@ -104,13 +104,13 @@ def p_distance(A, B, p=2):

D = np.empty((na, nb), order="F")

if type(p) == type(1):
if isinstance(p, int):
if p == 2:
fl2_distance(A, B, D)
else:
fp_distance_integer(A.T, B.T, D, p)

elif type(p) == type(1.0):
elif isinstance(p, float):
if p.is_integer():
p = int(p)
if p == 2:
Expand Down
40 changes: 10 additions & 30 deletions src/qmllib/kernels/gradient_kernels.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import ctypes

import numpy as np

from qmllib.utils.environment_manipulation import (
mkl_get_num_threads,
mkl_reset_num_threads,
mkl_set_num_threads,
)

from .fgradient_kernels import (
fatomic_local_gradient_kernel,
fatomic_local_kernel,
Expand All @@ -18,33 +22,6 @@
)


def mkl_set_num_threads(cores):

if cores is None:
return

try:
mkl_rt = ctypes.CDLL("libmkl_rt.so")
mkl_rt.mkl_set_num_threads(ctypes.byref(ctypes.c_int(cores)))

except:

pass


def mkl_get_num_threads():

try:
mkl_rt = ctypes.CDLL("libmkl_rt.so")
mkl_num_threads = mkl_rt.mkl_get_max_threads()

return mkl_num_threads

except:

return None


def get_global_kernel(X1, X2, Q1, Q2, SIGMA):
"""Calculates the Gaussian kernel matrix K with the local decomposition where :math:`K_{ij}`:
Expand Down Expand Up @@ -427,7 +404,10 @@ def get_atomic_local_gradient_kernel(X1, X2, dX2, Q1, Q2, SIGMA):
)

# Reset MKL_NUM_THREADS back to its original value
mkl_set_num_threads(original_mkl_threads)
if original_mkl_threads is not None:
mkl_set_num_threads(original_mkl_threads)
else:
mkl_reset_num_threads()

return K

Expand Down
187 changes: 0 additions & 187 deletions src/qmllib/kernels/wrappers.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/qmllib/representations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .representations import *
from .representations import * # noqa:F403
23 changes: 23 additions & 0 deletions src/qmllib/representations/arad/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# MIT License
#
# Copyright (c) 2017 Anders S. Christensen and Felix A. Faber
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from .arad import *
Loading

0 comments on commit 6b2c2df

Please sign in to comment.