Skip to content

Commit

Permalink
Merge branch 'master' into fix-rtd-build
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodr authored Aug 25, 2023
2 parents e754035 + 415c083 commit e306e70
Show file tree
Hide file tree
Showing 21 changed files with 276 additions and 67 deletions.
36 changes: 24 additions & 12 deletions .github/workflows/binder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@ name: Build Notebook Container

on:
push:
branches:
- master
- release/*
workflow_dispatch:
pull_request:

concurrency:
group: latest-repo2docker-group
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
name: Run repo2docker

permissions:
contents: read
packages: write

steps:

- name: checkout files in repo
uses: actions/checkout@v3
- name: checkout files in repo
uses: actions/checkout@v3

- name: downcase repository name
run: |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
- name: update jupyter dependencies with repo2docker
uses: jupyterhub/repo2docker-action@master
with:
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DOCKER_REGISTRY: ghcr.io
MYBINDERORG_TAG: ${{ github.event.ref }}
PUBLIC_REGISTRY_CHECK: true
- name: update jupyter dependencies with repo2docker
uses: jupyterhub/repo2docker-action@master
with:
DOCKER_USERNAME: ${{ github.repository_owner }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DOCKER_REGISTRY: ghcr.io
MYBINDERORG_TAG: ${{ github.event.ref }}
IMAGE_NAME: ${{ env.REPO }}
PUBLIC_REGISTRY_CHECK: true
11 changes: 9 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
types:
- created

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
BUILD_TYPE: Release

Expand All @@ -22,7 +26,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v3
Expand All @@ -44,7 +52,6 @@ jobs:
environment-file: environment.yml
channel-priority: true
python-version: ${{ matrix.python-version }}
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!

- name: Configure
shell: bash -l {0}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
BUILD_TYPE: Debug

Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/pip-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ on:
types:
- created

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- uses: actions/checkout@v3
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![License](https://img.shields.io/badge/license-%20LGPLv3-blue.svg)](../master/LICENSE)
![Build and test VAMPyR](https://github.com/MRChemSoft/vampyr/workflows/Build%20and%20test%20VAMPyR/badge.svg)
[![codecov](https://codecov.io/gh/MRChemSoft/vampyr/branch/master/graph/badge.svg)](https://codecov.io/gh/MRChemSoft/vampyr)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/MRChemSoft/vampyr/master?urlpath=lab%2Ftree%2Fdocs%2Fnotebooks)

The Very Accurate Multiresolution Python Routines (VAMPyR) package is a high
level Python interface to the [MRCPP](https://github.com/MRChemSoft/mrcpp) code.
Expand Down Expand Up @@ -65,3 +66,34 @@ Note that the conda-forge package is _always_ built with OpenMP support enabled
in the MRCPP backend.

The VAMPyR module is now available whenever you have activated the `myenv` environment.

### Creating a Conda environment from a .yml file

You can also create a Conda environment from a .yml file that already specifies VAMPyR and
other useful packages such as numpy, and matplotlib. Here's how:

1. Write an `environment.yml` file, for example:

```yaml
name: myenv
channels:
- conda-forge
dependencies:
- vampyr
- numpy
- matplotlib
- jupyterlab
```
2. Create the environment from the `environment.yml` file:

```sh
$ conda env create -f environment.yml
```
3. Activate the environment:

```sh
$ conda activate myenv
```
The VAMPyR module, along with numpy and matplotlib, is now available whenever
you have activated the myenv environment.
2 changes: 2 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
dependencies:
- cmake
- cxx-compiler
- eigen
#- mrcpp
- matplotlib
- ninja
Expand All @@ -11,3 +12,4 @@ dependencies:
- pybind11
- pytest
- pytest-cov
- python >=3.8
2 changes: 2 additions & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euxo

type -P python

# install current version of VAMPyR
python -m pip install -vvv .

Expand Down
2 changes: 1 addition & 1 deletion cmake/compiler_flags/Intel.CXX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if(NOT DEFINED ENV{CXXFLAGS})
if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftz -fp-speculation=fast -fp-model fast -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -debug -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -debug -DNDEBUG -g3 -parallel-source-info=2")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -debug -DDEBUG")
endif()
endif()
4 changes: 2 additions & 2 deletions cmake/custom/fetch_mrcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(_build_type ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE Release)

find_package(MRCPP 1.4 CONFIG QUIET)
find_package(MRCPP 1.5 CONFIG QUIET)

# whether MRCPP was fetched and built locally
set(MRCPP_FETCHED FALSE)
Expand All @@ -18,7 +18,7 @@ else()
GIT_REPOSITORY
https://github.com/MRChemSoft/mrcpp.git
GIT_TAG
1a6d450ac356feffba5c5cb2d02b92a875dbb9aa
v1.5.0
)

set(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
Expand Down
5 changes: 2 additions & 3 deletions cmake/custom/fetch_pybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
find_package(pybind11 2.6 CONFIG QUIET)
find_package(pybind11 2.9 CONFIG QUIET)

set(PYBIND11_CPP_STANDARD "-std=c++${CMAKE_CXX_STANDARD}")

Expand All @@ -10,9 +10,8 @@ else()
FetchContent_Declare(pybind11
QUIET
URL
https://github.com/pybind/pybind11/archive/v2.7.1.tar.gz
https://github.com/pybind/pybind11/archive/v2.10.0.tar.gz
)
set(PYBIND11_TEST OFF CACHE BOOL "")
FetchContent_MakeAvailable(pybind11)
endif()

4 changes: 3 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ channels:
dependencies:
- cmake
- cxx-compiler
- mrcpp
- eigen
#- mrcpp
- ninja
- numpy
- pip
- pybind11
- pytest
- pytest-cov
- python >=3.8
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ classifiers =
License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: C++
Topic :: Scientific/Engineering :: Chemistry

[options]
python_requires = >= 3.7
python_requires = >= 3.8

setup_requires =
pybind11-global >= 2.6
Expand Down
2 changes: 2 additions & 0 deletions src/vampyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ target_link_libraries(_vampyr
# extra linking needed to use std::filesystem: https://en.cppreference.com/w/cpp/filesystem
# need to link against stdc++fs for GNU<9.1
"$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.1>>:-lstdc++fs>"
# same for Intel compiler because it uses whatever GNU standard C++ is around
"$<$<OR:$<CXX_COMPILER_ID:Intel>,$<CXX_COMPILER_ID:IntelLLVM>>:-lstdc++fs>"
# need to link against c++fs for LLVM<9.0
"$<$<AND:$<CXX_COMPILER_ID:Clang>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:-lc++fs>"
)
Expand Down
38 changes: 37 additions & 1 deletion src/vampyr/operators/convolutions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include <MRCPP/operators/HelmholtzOperator.h>
#include <MRCPP/operators/IdentityConvolution.h>
#include <MRCPP/operators/PoissonOperator.h>
#include <MRCPP/operators/CartesianConvolution.h>
#include <MRCPP/treebuilders/apply.h>

namespace vampyr {

void cartesian_convolution(pybind11::module &);
void helmholtz_operator(pybind11::module &);
void poisson_operator(pybind11::module &);

Expand All @@ -17,7 +19,19 @@ template <int D> void convolutions(pybind11::module &m) {
using namespace mrcpp;
using namespace pybind11::literals;

py::class_<ConvolutionOperator<D>>(m, "ConvolutionOperator");
py::class_<ConvolutionOperator<D>>(m, "ConvolutionOperator")
.def(py::init<const MultiResolutionAnalysis<D> &, GaussExp<1> &, double>(),
"mra"_a,
"kernel"_a,
"prec"_a)
.def(
"__call__",
[](ConvolutionOperator<D> &O, FunctionTree<D> *inp) {
auto out = std::make_unique<FunctionTree<D>>(inp->getMRA());
apply<D>(O.getBuildPrec(), *out, O, *inp);
return out;
},
"inp"_a);

py::class_<IdentityConvolution<D>, ConvolutionOperator<D>>(m, "IdentityConvolution")
.def(py::init<const MultiResolutionAnalysis<D> &, double>(), "mra"_a, "prec"_a)
Expand All @@ -35,10 +49,32 @@ template <int D> void convolutions(pybind11::module &m) {
},
"inp"_a);

if constexpr (D == 3) cartesian_convolution(m);
if constexpr (D == 3) helmholtz_operator(m);
if constexpr (D == 3) poisson_operator(m);
}

void cartesian_convolution(pybind11::module &m) {
namespace py = pybind11;
using namespace mrcpp;
using namespace pybind11::literals;

py::class_<CartesianConvolution, ConvolutionOperator<3>>(m, "CartesianConvolution")
.def(py::init<const MultiResolutionAnalysis<3> &, GaussExp<1> &, double>(),
"mra"_a,
"kernel"_a,
"prec"_a)
.def(
"__call__",
[](CartesianConvolution &O, FunctionTree<3> *inp) {
auto out = std::make_unique<FunctionTree<3>>(inp->getMRA());
apply<3>(O.getBuildPrec(), *out, O, *inp);
return out;
},
"inp"_a)
.def("setCartesianComponents", &CartesianConvolution::setCartesianComponents);
}

void poisson_operator(pybind11::module &m) {
namespace py = pybind11;
using namespace mrcpp;
Expand Down
1 change: 0 additions & 1 deletion src/vampyr/operators/derivatives.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ template <int D> void derivatives(pybind11::module &m) {
An abstract base class for derivative operators
)mydelimiter")
// clang-format on
.def(py::init<const MultiResolutionAnalysis<D> &>(), "mra"_a)
.def("getOrder", &DerivativeOperator<D>::getOrder)
.def(
"__call__",
Expand Down
20 changes: 20 additions & 0 deletions src/vampyr/tests/test_convolutions_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
ffunc = vp.GaussFunc(alpha=alpha, beta=beta, position=r0)


def test_GaussKernel():
beta = 1.0e5
alpha = (beta / np.pi) ** (1.0 / 2.0)
ifunc = vp.GaussFunc(alpha=alpha, beta=beta)
iexp = vp.GaussExp()
iexp.append(ifunc)
I = vp.ConvolutionOperator(mra, iexp, prec=epsilon)

ftree = vp.FunctionTree(mra)
vp.advanced.build_grid(out=ftree, inp=ffunc)
vp.advanced.project(prec=epsilon, out=ftree, inp=ffunc)

gtree = vp.FunctionTree(mra)
vp.advanced.apply(prec=epsilon, out=gtree, oper=I, inp=ftree)
assert gtree.integrate() == pytest.approx(ftree.integrate(), rel=epsilon)

gtree2 = I(ftree)
assert gtree2.integrate() == pytest.approx(ftree.integrate(), rel=epsilon)


def test_Identity():
I = vp.IdentityConvolution(mra, prec=epsilon)

Expand Down
Loading

0 comments on commit e306e70

Please sign in to comment.