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

ACE grid computes with validation examples #5

Open
wants to merge 11 commits into
base: mala
Choose a base branch
from
Open
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
50 changes: 50 additions & 0 deletions build_note.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

mkdir build && cd build
# Build and compile to use the fix python/gridforceace
#NOTE first add your numpy include dir to your cplus include path
export CPLUS_INCLUDE_PATH=$(python -c "import numpy; print(numpy.get_include())")

cmake ../cmake -DLAMMPS_EXCEPTIONS=yes \
-DBUILD_SHARED_LIBS=yes \
-DBUILD_MPI=no \
-DBUILD_OMP=no \
-DPKG_PYTHON=yes \
-DPKG_ML-SNAP=yes \
-DPKG_ML-PACE=yes \
-DPKG_ML-IAP=yes \
-DPKG_MLIAP_ENABLE_PYTHON=yes \
-DPYTHON_EXECUTABLE:FILEPATH=`which python` \
-DPYTHON_INCLUDE_DIR=$(python -c "import sysconfig; print(sysconfig.get_path('include'))") \
-DPYTHON_LIBRARY=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

make -j
make install-python

# To compile and build when only using the ace grid computes

cmake ../cmake -DLAMMPS_EXCEPTIONS=yes \
-DBUILD_SHARED_LIBS=yes \
-DBUILD_MPI=yes \
-DBUILD_OMP=yes \
-DPKG_PYTHON=yes \
-DPKG_ML-SNAP=yes \
-DPKG_ML-PACE=yes \
-DPKG_ML-IAP=yes \
-DPKG_MLIAP_ENABLE_PYTHON=yes \
-DPYTHON_EXECUTABLE:FILEPATH=`which python` \
-DPYTHON_INCLUDE_DIR=$(python -c "import sysconfig; print(sysconfig.get_path('include'))") \
-DPYTHON_LIBRARY=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

make -j
make install-python

#NOTE that the following dflags were optional in both cases above:
# -DPKG_ML-IAP=yes \
# -DPKG_MLIAP_ENABLE_PYTHON=yes \

#tested with:
#cmake version 3.26.5
#Python 3.10.13
#Numpy 1.26.4
#gcc (GCC) 8.5.0
53 changes: 30 additions & 23 deletions cmake/Modules/Packages/ML-PACE.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.01.3.fix.tar.gz" CACHE STRING "URL for PACE evaluator library sources")
set(PACELIB_URL "https://github.com/ICAMS/lammps-user-pace/archive/refs/tags/v.2023.11.25.fix.tar.gz" CACHE STRING "URL for PACE evaluator library sources")

set(PACELIB_MD5 "4f0b3b5b14456fe9a73b447de3765caa" CACHE STRING "MD5 checksum of PACE evaluator library tarball")
set(PACELIB_MD5 "b45de9a633f42ed65422567e3ce56f9f" CACHE STRING "MD5 checksum of PACE evaluator library tarball")
mark_as_advanced(PACELIB_URL)
mark_as_advanced(PACELIB_MD5)
GetFallbackURL(PACELIB_URL PACELIB_FALLBACK)

# download library sources to build folder
if(EXISTS ${CMAKE_BINARY_DIR}/libpace.tar.gz)
file(MD5 ${CMAKE_BINARY_DIR}/libpace.tar.gz DL_MD5)
endif()
if(NOT "${DL_MD5}" STREQUAL "${PACELIB_MD5}")
message(STATUS "Downloading ${PACELIB_URL}")
file(DOWNLOAD ${PACELIB_URL} ${CMAKE_BINARY_DIR}/libpace.tar.gz STATUS DL_STATUS SHOW_PROGRESS)
file(MD5 ${CMAKE_BINARY_DIR}/libpace.tar.gz DL_MD5)
if((NOT DL_STATUS EQUAL 0) OR (NOT "${DL_MD5}" STREQUAL "${PACELIB_MD5}"))
message(WARNING "Download from primary URL ${PACELIB_URL} failed\nTrying fallback URL ${PACELIB_FALLBACK}")
file(DOWNLOAD ${PACELIB_FALLBACK} ${CMAKE_BINARY_DIR}/libpace.tar.gz EXPECTED_HASH MD5=${PACELIB_MD5} SHOW_PROGRESS)
endif()
# LOCAL_ML-PACE points to top-level dir with local lammps-user-pace repo,
# to make it easier to check local build without going through the public github releases
if(LOCAL_ML-PACE)
set(lib-pace "${LOCAL_ML-PACE}")
else()
message(STATUS "Using already downloaded archive ${CMAKE_BINARY_DIR}/libpace.tar.gz")
endif()
# download library sources to build folder
if(EXISTS ${CMAKE_BINARY_DIR}/libpace.tar.gz)
file(MD5 ${CMAKE_BINARY_DIR}/libpace.tar.gz DL_MD5)
endif()
if(NOT "${DL_MD5}" STREQUAL "${PACELIB_MD5}")
message(STATUS "Downloading ${PACELIB_URL}")
file(DOWNLOAD ${PACELIB_URL} ${CMAKE_BINARY_DIR}/libpace.tar.gz STATUS DL_STATUS SHOW_PROGRESS)
file(MD5 ${CMAKE_BINARY_DIR}/libpace.tar.gz DL_MD5)
if((NOT DL_STATUS EQUAL 0) OR (NOT "${DL_MD5}" STREQUAL "${PACELIB_MD5}"))
message(WARNING "Download from primary URL ${PACELIB_URL} failed\nTrying fallback URL ${PACELIB_FALLBACK}")
file(DOWNLOAD ${PACELIB_FALLBACK} ${CMAKE_BINARY_DIR}/libpace.tar.gz EXPECTED_HASH MD5=${PACELIB_MD5} SHOW_PROGRESS)
endif()
else()
message(STATUS "Using already downloaded archive ${CMAKE_BINARY_DIR}/libpace.tar.gz")
endif()


# uncompress downloaded sources
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove_directory lammps-user-pace*
COMMAND ${CMAKE_COMMAND} -E tar xzf libpace.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
get_newest_file(${CMAKE_BINARY_DIR}/lammps-user-pace-* lib-pace)
# uncompress downloaded sources
execute_process(
COMMAND ${CMAKE_COMMAND} -E remove_directory lammps-user-pace*
COMMAND ${CMAKE_COMMAND} -E tar xzf libpace.tar.gz
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
get_newest_file(${CMAKE_BINARY_DIR}/lammps-user-pace-* lib-pace)
endif()

add_subdirectory(${lib-pace} build-pace)
set_target_properties(pace PROPERTIES CXX_EXTENSIONS ON OUTPUT_NAME lammps_pace${LAMMPS_MACHINE})
Expand Down
71 changes: 71 additions & 0 deletions examples/python/betas_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from __future__ import print_function
from lammps import lammps
import ctypes
import numpy as np
from ctypes import *

#NOTE you may import mala functions here
#import mala.

flat_beta = True
def get_grid(ngrid):
igrid = 0
for nx in range(ngrid):
for ny in range(ngrid):
for nz in range(ngrid):
igrid += 1
return igrid

from numpy.random import RandomState
def pre_force_callback(lmp):
L = lammps(ptr=lmp)

def _extract_compute_np(lmp, name, compute_style, result_type, array_shape=None):
if array_shape is None:
array_np = lmp.numpy.extract_compute(name,compute_style, result_type)
else:
ptr = lmp.extract_compute(name, compute_style, result_type)
if result_type == 0:

# no casting needed, lammps.py already works

return ptr
if result_type == 2:
ptr = ptr.contents
total_size = np.prod(array_shape)
buffer_ptr = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_double * total_size))
array_np = np.frombuffer(buffer_ptr.contents, dtype=float)
array_np.shape = array_shape
return array_np

#-------------------------------------------------------------
# variables to access fix pointer in python if needed
#-------------------------------------------------------------
#fid = 'python/gridforceace' # id for the fix
fid = '4'
ftype = 2 # 0 for scalar 1 for vector 2 for array
result_type = 2
compute_style = 0
fstyle = 0

ncolbase = 0
nrow = (get_grid(ngrid=3)) #for now add a dE_I/dB_{I,K}row for ALL gridpoints (global)
ncoef = int(368/2) #number of ace descriptors per atom - may be obtained from ACE functions in mala
ncol = ncoef + ncolbase
# set to 1 if including energy row
#base_array_rows = 1
base_array_rows=0
#-------------------------------------------------------------
# dummy function to get dE_I/dB_{I,k} for a
#-------------------------------------------------------------
prng = RandomState(3481)
betas_row = prng.uniform(-1,1,ncoef)*1.e-2 #np.arange(ncoef)*1.e-6
betas = np.repeat(np.array([betas_row]),repeats = nrow+base_array_rows,axis=0)

#-------------------------------------------------------------
if flat_beta:
betas = betas.flatten()
return np.ascontiguousarray(betas)
else:
return betas

Loading