Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled with numpy 2.0 #12

Merged
merged 11 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
exclude: ^tests/resources/
Expand All @@ -23,7 +23,7 @@ repos:
args: ['--maxkb=3000']

- repo: https://github.com/myint/autoflake
rev: v2.2.0
rev: v2.3.1
hooks:
- id: autoflake
name: Removes unused variables
Expand All @@ -48,15 +48,15 @@ repos:
]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.10.0
hooks:
- id: black
name: Fixes formatting
language_version: python3
args: ["--line-length=99"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
name: Checks pep8 style
Expand All @@ -71,7 +71,7 @@ repos:
"--ignore=E501,E203,W503,E741",
]

- repo: https://github.com/pseewald/fprettify
- repo: https://github.com/fortran-lang/fprettify
rev: v0.3.7
hooks:
- id: fprettify
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test:

types:
${python} -m monkeytype run $$(which ${pytest}) ./tests
${python} -m monkeytype list-modules | grep ${pkg} | parallel -j${j} "${python} -m monkeytype apply {}"
${python} -m monkeytype list-modules | grep ${pkg} | parallel -j${j} "${python} -m monkeytype apply {} > /dev/null && echo {}"

cov:
${python} -m pytest -vrs --cov=${pkg} --cov-report html tests
Expand Down
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ Breaking changes from ``qml``:

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


==============
How to install
==============

You need a fortran compiler and math library. Default is `gfortran` and `openblas`.


.. code-block:: bash

sudo apt install libopenblas-dev gcc


A proper pip-package is on the way, for now

.. code-block:: bash
Expand Down
78 changes: 47 additions & 31 deletions _compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,85 @@
import sys
from pathlib import Path

import numpy as np

f90_modules = {
"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",
"ffchl_kernel_types.f90",
"ffchl_module.f90",
"ffchl_module_ef.f90",
"ffchl_kernels.f90",
"ffchl_electric_field_kernels.f90",
"ffchl_scalar_kernels.f90",
"ffchl_kernels_ef.f90",
"ffchl_force_kernels.f90",
],
"solvers/fsolvers": ["fsolvers.f90"],
"kernels/fdistance": ["fdistance.f90"],
"kernels/fkernels": ["fkernels.f90", "fkpca.f90"],
"kernels/fkernels": [
"fkernels.f90",
"fkpca.f90",
"fkwasserstein.f90",
],
"kernels/fgradient_kernels": ["fgradient_kernels.f90"],
"utils/fsettings": ["fsettings.f90"],
}


def find_mkl():

return
raise NotImplementedError()


def find_flags(fcc: str):
def find_env() -> dict[str, str]:
"""Find compiler flags"""

# TODO Find ifort flags, choose from FCC
# TODO Find math lib
# TODO Find os

# -lgomp", "-lpthread", "-lm", "-ldl
# ["-L${MKLROOT}/lib/intel64", "-lmkl_rt"]

# COMPILER_FLAGS = ["-O3", "-fopenmp", "-m64", "-march=native", "-fPIC",
# "-Wno-maybe-uninitialized", "-Wno-unused-function", "-Wno-cpp"]
# LINKER_FLAGS = ["-lgomp"]
COMPILER_FLAGS = [
"-O3",
"-fopenmp",
"-m64",
"-march=native",
"-fPIC",
"-Wno-maybe-uninitialized",
"-Wno-unused-function",
"-Wno-cpp",
]

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

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

return flags


def find_fcc():
"""Find the fortran compiler. Either gnu or intel"""

# fcc = "ifort"
fflags = [] + COMPILER_FLAGS
ldflags = [] + extra_flags + math_flags
fcc = "gfortran"

return fcc
env = {"FFLAGS": " ".join(fflags), "LDFLAGS": " ".join(ldflags), "FCC": fcc}

return env


def main():
"""Compile f90 in src/qmllib"""

fcc = find_fcc()
flags = find_flags(fcc)
print(f"Using numpy {np.__version__}")

# Find and set Fortran compiler, compiler flags and linker flags
env = find_env()
for key, value in env.items():
print(f"export {key}='{value}'")
os.environ[key] = value

f2py = [sys.executable, "-m", "numpy.f2py"]

os.environ["FCC"] = fcc
meson_flags = [
"--backend",
"meson",
]

for module_name, module_sources in f90_modules.items():

Expand All @@ -74,9 +92,7 @@ def main():
stem = path.stem

cwd = Path("src/qmllib") / parent
cmd = (
[sys.executable, "-m", "numpy.f2py", "-c"] + flags + module_sources + ["-m", str(stem)]
)
cmd = f2py + ["-c"] + module_sources + ["-m", str(stem)] + meson_flags
print(cwd, " ".join(cmd))

proc = subprocess.run(cmd, cwd=cwd, capture_output=True, text=True)
Expand All @@ -85,9 +101,9 @@ def main():
exitcode = proc.returncode

if exitcode > 0:
print(stdout)
print()
print(stderr)
print()
print(stdout)
exit(exitcode)


Expand Down
33 changes: 18 additions & 15 deletions environment_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ channels:
- defaults
dependencies:
- python==3.12
- jupytext
- monkeytype
- numpy<2.0.0
- pandas
- pip
- pre-commit
- pyarrow
- pytest
- scikit-learn
- scipy
# build
- build
- meson
- ninja
# publish
- twine
- pip:
- jupytext
- monkeytype
- numpy<2.0.0
- pandas
- pandas
- pip
- pre-commit
- pyarrow
- pytest
- scikit-learn
- scipy
# build
- build
- meson
- ninja
# publish
- twine
Loading
Loading