Commit 56d2b104 authored by zhangqha's avatar zhangqha
Browse files

BladeDISC DeePMD code update

parent 6b33aeb8
Pipeline #180 failed with stages
in 0 seconds
# Install script for directory: /root/deepmd-kit/source/op
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/root/deepmd-kit/_skbuild/linux-x86_64-3.6/cmake-install")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "Release")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "1")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()
# Set default install directory permissions.
if(NOT DEFINED CMAKE_OBJDUMP)
set(CMAKE_OBJDUMP "/usr/bin/objdump")
endif()
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so" AND
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so")
file(RPATH_CHECK
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so"
RPATH "$ORIGIN")
endif()
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/deepmd/op" TYPE MODULE FILES "/root/deepmd-kit/_skbuild/linux-x86_64-3.6/cmake-build/op/libop_abi.so")
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so" AND
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so")
file(RPATH_CHANGE
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so"
OLD_RPATH "/root/deepmd-kit/_skbuild/linux-x86_64-3.6/cmake-build/lib:/usr/local/lib/python3.6/dist-packages/tensorflow:"
NEW_RPATH "$ORIGIN")
if(CMAKE_INSTALL_DO_STRIP)
execute_process(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_abi.so")
endif()
endif()
endif()
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so" AND
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so")
file(RPATH_CHECK
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so"
RPATH "$ORIGIN")
endif()
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/deepmd/op" TYPE MODULE FILES "/root/deepmd-kit/_skbuild/linux-x86_64-3.6/cmake-build/op/libop_grads.so")
if(EXISTS "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so" AND
NOT IS_SYMLINK "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so")
file(RPATH_CHANGE
FILE "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so"
OLD_RPATH "/root/deepmd-kit/_skbuild/linux-x86_64-3.6/cmake-build/lib:/usr/local/lib/python3.6/dist-packages/tensorflow:"
NEW_RPATH "$ORIGIN")
if(CMAKE_INSTALL_DO_STRIP)
execute_process(COMMAND "/usr/bin/strip" "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/deepmd/op/libop_grads.so")
endif()
endif()
endif()
if(CMAKE_INSTALL_COMPONENT STREQUAL "Unspecified" OR NOT CMAKE_INSTALL_COMPONENT)
file(INSTALL DESTINATION "${CMAKE_INSTALL_PREFIX}/deepmd/op" TYPE FILE FILES
"/root/deepmd-kit/source/op/_gelu.py"
"/root/deepmd-kit/source/op/_map_nvnmd_grad.py"
"/root/deepmd-kit/source/op/_matmul_nvnmd_grad.py"
"/root/deepmd-kit/source/op/_prod_force_grad.py"
"/root/deepmd-kit/source/op/_prod_force_se_a_grad.py"
"/root/deepmd-kit/source/op/_prod_force_se_r_grad.py"
"/root/deepmd-kit/source/op/_prod_virial_grad.py"
"/root/deepmd-kit/source/op/_prod_virial_se_a_grad.py"
"/root/deepmd-kit/source/op/_prod_virial_se_r_grad.py"
"/root/deepmd-kit/source/op/_quantize_nvnmd_grad.py"
"/root/deepmd-kit/source/op/_soft_min_force_grad.py"
"/root/deepmd-kit/source/op/_soft_min_virial_grad.py"
"/root/deepmd-kit/source/op/_tabulate_grad.py"
"/root/deepmd-kit/source/op/_tanh2_nvnmd_grad.py"
"/root/deepmd-kit/source/op/_tanh4_nvnmd_grad.py"
)
endif()
"""Root of the deepmd package, exposes all public classes and submodules."""
try:
from importlib import metadata
except ImportError: # for Python<3.8
import importlib_metadata as metadata
import deepmd.utils.network as network
from . import cluster, descriptor, fit, loss, utils, nvnmd
from .env import set_mkl
from .infer import DeepEval, DeepPotential
from .infer.data_modifier import DipoleChargeModifier
set_mkl()
try:
from ._version import version as __version__
except ImportError:
from .__about__ import __version__
# load third-party plugins
for ep in metadata.entry_points().get('deepmd', []):
ep.load()
__all__ = [
"descriptor",
"fit",
"loss",
"utils",
"cluster",
"network",
"DeepEval",
"DeepPotential",
"DipoleChargeModifier",
"nvnmd",
]
"""Package dp entry point."""
from .entrypoints.main import main
if __name__ == '__main__':
main()
# coding: utf-8
# file generated by setuptools_scm
# don't change, don't track in version control
version = '2.1.6.dev0+ng6e3d4a62.d20230313'
"""ASE calculator interface module."""
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Optional, Union
from ase.calculators.calculator import (
Calculator, all_changes, PropertyNotImplementedError
)
from deepmd import DeepPotential
if TYPE_CHECKING:
from ase import Atoms
__all__ = ["DP"]
class DP(Calculator):
"""Implementation of ASE deepmd calculator.
Implemented propertie are `energy`, `forces` and `stress`
Parameters
----------
model : Union[str, Path]
path to the model
label : str, optional
calculator label, by default "DP"
type_dict : Dict[str, int], optional
mapping of element types and their numbers, best left None and the calculator
will infer this information from model, by default None
Examples
--------
Compute potential energy
>>> from ase import Atoms
>>> from deepmd.calculator import DP
>>> water = Atoms('H2O',
>>> positions=[(0.7601, 1.9270, 1),
>>> (1.9575, 1, 1),
>>> (1., 1., 1.)],
>>> cell=[100, 100, 100],
>>> calculator=DP(model="frozen_model.pb"))
>>> print(water.get_potential_energy())
>>> print(water.get_forces())
Run BFGS structure optimization
>>> from ase.optimize import BFGS
>>> dyn = BFGS(water)
>>> dyn.run(fmax=1e-6)
>>> print(water.get_positions())
"""
name = "DP"
implemented_properties = ["energy", "free_energy", "forces", "virial", "stress"]
def __init__(
self,
model: Union[str, "Path"],
label: str = "DP",
type_dict: Dict[str, int] = None,
**kwargs
) -> None:
Calculator.__init__(self, label=label, **kwargs)
self.dp = DeepPotential(str(Path(model).resolve()))
if type_dict:
self.type_dict = type_dict
else:
self.type_dict = dict(
zip(self.dp.get_type_map(), range(self.dp.get_ntypes()))
)
def calculate(
self,
atoms: Optional["Atoms"] = None,
properties: List[str] = ["energy", "forces", "virial"],
system_changes: List[str] = all_changes,
):
"""Run calculation with deepmd model.
Parameters
----------
atoms : Optional[Atoms], optional
atoms object to run the calculation on, by default None
properties : List[str], optional
unused, only for function signature compatibility,
by default ["energy", "forces", "stress"]
system_changes : List[str], optional
unused, only for function signature compatibility, by default all_changes
"""
if atoms is not None:
self.atoms = atoms.copy()
coord = self.atoms.get_positions().reshape([1, -1])
if sum(self.atoms.get_pbc()) > 0:
cell = self.atoms.get_cell().reshape([1, -1])
else:
cell = None
symbols = self.atoms.get_chemical_symbols()
atype = [self.type_dict[k] for k in symbols]
e, f, v = self.dp.eval(coords=coord, cells=cell, atom_types=atype)
self.results['energy'] = e[0][0]
# see https://gitlab.com/ase/ase/-/merge_requests/2485
self.results['free_energy'] = e[0][0]
self.results['forces'] = f[0]
self.results['virial'] = v[0].reshape(3, 3)
# convert virial into stress for lattice relaxation
if "stress" in properties:
if sum(atoms.get_pbc()) > 0:
# the usual convention (tensile stress is positive)
# stress = -virial / volume
stress = -0.5 * (v[0].copy() + v[0].copy().T) / atoms.get_volume()
# Voigt notation
self.results['stress'] = stress.flat[[0, 4, 8, 5, 2, 1]]
else:
raise PropertyNotImplementedError
"""Module that reads node resources, auto detects if running local or on SLURM."""
from .local import get_resource as get_local_res
from .slurm import get_resource as get_slurm_res
import os
from typing import List, Tuple, Optional
__all__ = ["get_resource"]
def get_resource() -> Tuple[str, List[str], Optional[List[int]]]:
"""Get local or slurm resources: nodename, nodelist, and gpus.
Returns
-------
Tuple[str, List[str], Optional[List[int]]]
nodename, nodelist, and gpus
"""
if "SLURM_JOB_NODELIST" in os.environ:
return get_slurm_res()
else:
return get_local_res()
"""Get local GPU resources."""
import os
import socket
import subprocess as sp
import sys
from deepmd.env import tf
from typing import List, Tuple, Optional
__all__ = ["get_gpus", "get_resource"]
def get_gpus():
"""Get available IDs of GPU cards at local.
These IDs are valid when used as the TensorFlow device ID.
Returns
-------
Optional[List[int]]
List of available GPU IDs. Otherwise, None.
"""
test_cmd = 'from tensorflow.python.client import device_lib; ' \
'devices = device_lib.list_local_devices(); ' \
'gpus = [d.name for d in devices if d.device_type == "GPU"]; ' \
'print(len(gpus))'
with sp.Popen([sys.executable, "-c", test_cmd], stderr=sp.PIPE, stdout=sp.PIPE) as p:
stdout, stderr = p.communicate()
if p.returncode != 0:
decoded = stderr.decode('UTF-8')
raise RuntimeError('Failed to detect availbe GPUs due to:\n%s' % decoded)
decoded = stdout.decode('UTF-8').strip()
num_gpus = int(decoded)
return list(range(num_gpus)) if num_gpus > 0 else None
def get_resource() -> Tuple[str, List[str], Optional[List[int]]]:
"""Get local resources: nodename, nodelist, and gpus.
Returns
-------
Tuple[str, List[str], Optional[List[int]]]
nodename, nodelist, and gpus
"""
nodename = socket.gethostname()
nodelist = [nodename]
gpus = get_gpus()
return nodename, nodelist, gpus
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment