diff --git a/science/py-kliff/Makefile b/science/py-kliff/Makefile index 52f3f8368887..023e89202e43 100644 --- a/science/py-kliff/Makefile +++ b/science/py-kliff/Makefile @@ -1,38 +1,54 @@ PORTNAME= kliff -DISTVERSION= 0.4.4 -PORTREVISION= 3 +DISTVERSIONPREFIX= v +DISTVERSION= 1.0.1-45 +DISTVERSIONSUFFIX= -gdf2d4de CATEGORIES= science python # chemistry -MASTER_SITES= PYPI +#MASTER_SITES= PYPI # release 1.0.1 is faulty: it has the numpy<2 requirement PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX} MAINTAINER= yuri@FreeBSD.org COMMENT= KIM-based Learning-Integrated Fitting Framework WWW= https://kliff.readthedocs.io/en/latest/ \ https://github.com/openkim/kliff LICENSE= LGPL21 LICENSE_FILE= ${WRKSRC}/LICENSE BUILD_DEPENDS= ${PYTHON_PKGNAMEPREFIX}pybind11>0:devel/py-pybind11@${PY_FLAVOR} -RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}loguru>0:devel/py-loguru@${PY_FLAVOR} \ +RUN_DEPENDS= ${PYTHON_PKGNAMEPREFIX}ase>0:science/py-ase@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}loguru>0:devel/py-loguru@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}monty>0:devel/py-monty@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}numpy>0:math/py-numpy@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}requests>0:www/py-requests@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}scipy>0:science/py-scipy@${PY_FLAVOR} \ ${PYTHON_PKGNAMEPREFIX}pyyaml>0:devel/py-pyyaml@${PY_FLAVOR} -RUN_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}emcee>0:math/py-emcee@${PY_FLAVOR} \ - ${PYTHON_PKGNAMEPREFIX}numpy>=1.16:math/py-numpy@${PY_FLAVOR} \ - ${PYTHON_PKGNAMEPREFIX}kimpy>0:science/py-kimpy@${PY_FLAVOR} \ +RUN_DEPENDS_torch= \ ${PYTHON_PKGNAMEPREFIX}pytorch>0:misc/py-pytorch@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}pytorch-lightning>0:misc/py-pytorch-lightning@${PY_FLAVOR} + # missing: torch_geometric, torch_scatter, tensorboard, tensorboardx +RUN_DEPENDS+= ${RUN_DEPENDS_torch} +TEST_DEPENDS+= ${PYTHON_PKGNAMEPREFIX}emcee>0:math/py-emcee@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}kimpy>0:science/py-kimpy@${PY_FLAVOR} \ + ${PYTHON_PKGNAMEPREFIX}pytest-cov>0:devel/py-pytest-cov@${PY_FLAVOR} + # libdescriptor is missing + # also need 'torch' dependency USES= compiler:c++11-lang python USE_PYTHON= distutils autoplist pytest # tests fail to run, see https://github.com/openkim/kliff/issues/81, and https://github.com/openkim/kliff/issues/197 +USE_GITHUB= yes +GH_ACCOUNT= openkim + TEST_ENV= ${MAKE_ENV} PYTHONPATH=${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} TEST_WRKSRC= ${WRKSRC}/tests +TEST_ARGS= --disable-plugin-autoload post-install: @${FIND} ${STAGEDIR}${PYTHONPREFIX_SITELIBDIR} -name "*.so" | ${XARGS} ${STRIP_CMD} +test-quick: + @cd ${TEST_WRKSRC} && ${SETENV} ${TEST_ENV} ${PYTHON_CMD} ${FILESDIR}/example.py + # tests as of 0.4.4: 17 failed, 29 passed, 16 errors in 14.58s, see https://github.com/openkim/kliff/issues/210 .include diff --git a/science/py-kliff/distinfo b/science/py-kliff/distinfo index 4faca49b1df5..8c15976866dd 100644 --- a/science/py-kliff/distinfo +++ b/science/py-kliff/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1744348783 -SHA256 (kliff-0.4.4.tar.gz) = 0644eebadfe21b77389eaa6e001ebb166bd95ed06993c309293190991ff76980 -SIZE (kliff-0.4.4.tar.gz) = 3172741 +TIMESTAMP = 1790233395 +SHA256 (openkim-kliff-v1.0.1-45-gdf2d4de_GH0.tar.gz) = c32dbff4d1118dfa8f64ecb2f89520047d405e91a270f3a2b6e0c6f1480f80f6 +SIZE (openkim-kliff-v1.0.1-45-gdf2d4de_GH0.tar.gz) = 3846602 diff --git a/science/py-kliff/files/example.py b/science/py-kliff/files/example.py new file mode 100644 index 000000000000..f7595a28607a --- /dev/null +++ b/science/py-kliff/files/example.py @@ -0,0 +1,44 @@ +from kliff.dataset import Dataset +from kliff.models import NeuralNetwork +from kliff.utils import download_dataset + +# 1. Using the legacy/imperative modules for custom configuration setup +from kliff.legacy import nn +from kliff.legacy.calculators import CalculatorTorch +from kliff.legacy.descriptors import SymmetryFunction +from kliff.legacy.loss import Loss + +# 2. Define a descriptor to featurize atomic environments (e.g., for Silicon) +descriptor = SymmetryFunction( + cut_name="cos", + cut_dists={"Si-Si": 5.0}, + hyperparams="set51", + normalize=True +) + +# 3. Create a multi-layer Neural Network potential using the descriptor +model = NeuralNetwork(descriptor) +model.add_layers( + nn.Linear(descriptor.get_size(), 10), # First hidden layer (10 units) + nn.Tanh(), + nn.Linear(10, 10), # Second hidden layer (10 units) + nn.Tanh(), + nn.Linear(10, 1), # Output layer (Energy prediction) +) + +# 4. Download and parse a crystal structure training dataset +dataset_path = download_dataset(dataset_name="Si_training_set") +dataset_path = dataset_path.joinpath("varying_alat") +train_set = Dataset.from_path(dataset_path) +configs = train_set.get_configs() + +# 5. Initialize the calculator (using PyTorch backend) to compute energy/forces +calc = CalculatorTorch(model, gpu=False) +calc.create(configs) + +# 6. Define the optimizer loss function +loss = Loss(calc) + +print(f"Total configurations loaded: {len(configs)}") +print("KLIFF environment successfully configured for potential fitting.") +