-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also add support for packaging with scikit-build
- Loading branch information
Showing
24 changed files
with
540 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
_skbuild/ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cmake | ||
ninja | ||
scikit-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (C) 2019 Pablo Hernandez-Cerdan | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef PERM_COMMON_TYPES_HPP | ||
#define PERM_COMMON_TYPES_HPP | ||
#include <iostream> | ||
#include <vector> | ||
|
||
namespace perm { | ||
/// float type (hard-coded better than templated for now) | ||
using float_t = double; | ||
|
||
template <typename T> | ||
struct vec3D_t { | ||
T x; | ||
T y; | ||
T z; | ||
void print(std::ostream &os) const { | ||
os << x << " " << y << " " << z << std::endl; | ||
} | ||
friend bool operator==(const vec3D_t<T> &lhs, const vec3D_t<T> &rhs) { | ||
return lhs.x == lhs.x && lhs.y == lhs.y && lhs.z == lhs.z; | ||
} | ||
T &operator[](const size_t index) { | ||
return (index == 0 ? x : (index == 1 ? y : z)); | ||
} | ||
const T &operator[](const size_t index) const { | ||
return (index == 0 ? x : (index == 1 ? y : z)); | ||
} | ||
constexpr size_t size() { return 3; }; | ||
}; | ||
|
||
template <typename T> | ||
vec3D_t<T> plus(const vec3D_t<T> &lhs, const vec3D_t<T> &rhs) { | ||
vec3D_t<T> out; | ||
out.x = lhs.x + rhs.x; | ||
out.y = lhs.y + rhs.y; | ||
out.z = lhs.z + rhs.z; | ||
return out; | ||
} | ||
|
||
template <typename T> | ||
struct single_chain_t { | ||
/// Number of monomers in the single-chain polymer | ||
size_t monomers = 0; | ||
/** Ordered collection of points, | ||
* start: points[0], | ||
* end: points[num_monomers - 1] | ||
*/ | ||
std::vector<vec3D_t<T>> points; | ||
void print(std::ostream &os) const { | ||
os << "chain.monomers= " << monomers << std::endl; | ||
for (const auto &p : points) { | ||
p.print(os); | ||
} | ||
} | ||
}; | ||
} // namespace perm | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* Copyright (C) 2019 Pablo Hernandez-Cerdan | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef PERM_RNG_HPP | ||
#define PERM_RNG_HPP | ||
|
||
#include "perm_common_types.hpp" | ||
#include <random> | ||
namespace RNG { | ||
|
||
inline std::mt19937 &engine() { | ||
/// seed generation | ||
static thread_local std::random_device rdev{}; | ||
/// engine instantiation: e | ||
static thread_local std::mt19937 e{rdev()}; | ||
// static thread_local std::mt19937 e{4342}; | ||
return e; | ||
} | ||
|
||
/// Randomize reseed the input engine with a random generate seed. | ||
inline void randomize_engine(std::mt19937 &eng) { | ||
std::random_device rd{}; | ||
eng.seed(rd()); | ||
} | ||
|
||
/// Uniform random distribution from double [0.0,1) | ||
inline double rand01() { | ||
static thread_local std::uniform_real_distribution<double> uid(0.0, 1.0); | ||
return uid(engine()); | ||
} | ||
|
||
/** | ||
* Return 1 with probability p | ||
* @param p must be lesser or equal than 1 | ||
* @return 1 with probability p, 0 if not. | ||
*/ | ||
inline bool random_bool(const double p) { return (rand01() < p) ? 1 : 0; } | ||
|
||
/** | ||
* Uniform random distribution from int [min,max] | ||
* @param min | ||
* @param max | ||
* @return int from [min,max] | ||
*/ | ||
inline int rand_range_int(const int &min, const int &max) { | ||
// note that inside function static variables doesn't interfer if they have | ||
// the same name | ||
std::uniform_int_distribution<int> uid(min, max); | ||
return uid(engine()); | ||
} | ||
|
||
inline perm::vec3D_t<int> rand_lattice_2D() { | ||
// note that inside function static variables doesn't interfer if they have | ||
// the same name | ||
std::uniform_int_distribution<int> uid(0, 3); | ||
const auto lattice_int = uid(engine()); | ||
switch (lattice_int) { | ||
case 0 /* -x */: | ||
return perm::vec3D_t<int>{-1, 0, 0}; | ||
break; | ||
case 1 /* +x */: | ||
return perm::vec3D_t<int>{1, 0, 0}; | ||
break; | ||
case 2 /* -y */: | ||
return perm::vec3D_t<int>{0, -1, 0}; | ||
break; | ||
case 3 /* +y */: | ||
return perm::vec3D_t<int>{0, 1, 0}; | ||
break; | ||
} | ||
// Not really needed, unreachable, but warnings if removed in gcc | ||
return perm::vec3D_t<int>{999, 999, 999}; | ||
} | ||
} // namespace RNG | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build-system] | ||
requires = ["setuptools", "wheel", "scikit-build", "cmake", "ninja"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import print_function | ||
from os import sys, path | ||
|
||
try: | ||
from skbuild import setup | ||
except ImportError: | ||
print('scikit-build is required to build from source.', file=sys.stderr) | ||
print('Please run:', file=sys.stderr) | ||
print('', file=sys.stderr) | ||
print(' python -m pip install scikit-build') | ||
sys.exit(1) | ||
|
||
sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) | ||
|
||
with open('README.md', 'r') as fp: | ||
readme = fp.read() | ||
with open('developer_requirements.txt', 'r') as fp: | ||
developer_requirements = list(filter(bool, (line.strip() for line in fp))) | ||
|
||
setup( | ||
name='perm', | ||
version='0.1', | ||
author='Pablo Hernandez-Cerdan', | ||
author_email='[email protected]', | ||
packages=['perm'], | ||
download_url=r'https://github.com/phcerdan/perm/releases', | ||
description=r'PERM: Prune and Enrichment Rosenbluth Method', | ||
long_description=readme, | ||
classifiers=[ | ||
"OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", | ||
"Programming Language :: Python", | ||
"Programming Language :: C++", | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Developers", | ||
"Intended Audience :: Education", | ||
"Intended Audience :: Science/Research", | ||
"Topic :: Scientific/Engineering", | ||
"Topic :: Scientific/Engineering :: Physics", | ||
"Topic :: Scientific/Engineering :: Information Analysis", | ||
"Topic :: Software Development :: Libraries", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: POSIX", | ||
"Operating System :: Unix", | ||
"Operating System :: MacOS" | ||
], | ||
license='MPL2', | ||
keywords='PERM montecarlo SAW polymer simulation', | ||
url=r'https://github.com/phcerdan/perm', | ||
install_requires=[], | ||
cmake_args=[ | ||
'-DBUILD_SHARED_LIBS:BOOL=TRUE', | ||
'-DPERM_BUILD_TESTING:BOOL=FALSE', | ||
'-DPERM_WRAP_PYTHON:BOOL=TRUE', | ||
# '-DCMAKE_BUILD_TYPE:STRING=Release', | ||
] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* Copyright (C) 2019 Pablo Hernandez-Cerdan | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "perm_common_types.hpp" | ||
|
||
namespace perm {} // end namespace perm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(test_files | ||
test_perm.cpp | ||
) | ||
perm_add_gtests() |
Oops, something went wrong.