Forward-time population genetic simulation in Python
Project description
This is the README for fwdpy11, which is a Python package for forward-time population genetic simulation. It uses fwdpp as its C++ back-end.
Build status
Master:
Development:
Manual
Latest/master:
Development branch:
Miscellaneous
Python code style:
Features
Picklable population objects
Parallel computation via multiprocessing or concurrent.futures.
Custom temporal samplers to analyze populations during a simulation may be written in pure Python.
Flexible interface for simulating models with multiple populations.
Dependencies
The following must be present on your system:
GSL. This is a C library. It is available via conda. fwdpy11 requires version 2.3 or greater.
pybind11. This should be installed conda as appropriate for your system, or via your system’s package manager or manually. See note below.
cmake. This should be installed by conda or your favorite package manager.
License
GPLv3 or later (See COPYING)
Suppored Python version
fwdpy11 is written for Python 3. We will not modify the package to be compatible with Python 2.7.
Installation
Building from the git repository:
git submodule init
git submodule update
python setup.py build_ext -i
python -m unittest discover tests
Using pip on macOS and Linux (or pip3 as appropriate for your system):
pip install --upgrade fwdpy11
It is possible that the cmake macros to detect the GSL can fail to detect the correct version. Issues like this are a basic weakness of cmake. I’ve seen this in conda environments, where the macro prefers the system version over the newer version in the environment. To “fix” this, give it a hint:
GSL_ROOT_DIR=/path/to/gsl python3 setup.py build_ext -i
macOS
On Apple’s macOS, we strongly encourage that you use conda with their compiler packages:
conda install clang_osx-64 clangxx_osx-64
Installing these packages will mean that you can get away from the relatively old versions of these compilers that ship with Xcode. However, you do need to add the following flag when building the package:
On macOS versions prior to “Mojave”:
CONDA_BUILD_SYSROOT=/ python3 setup.py build_ext -i
For later versions, you may omit the environment variable prefix.
Do the same for a pip install from the source directory.
Windows
We have heard positive reports of using fwdpy11 on Windows 10 with the Ubuntu subsystem installed. For such a system, you may use a Linux conda installer and then install fwdpy11 via bioconda.
The developers do not have access to this platform, but we are keen to hear of any issues.
Caution
We use the GitHub “release” mechanism to make stable versions available. However, GitHub releases to not include the sub-modules, meaning that the releases themselves cannot be used for installation. (A related irony is that the Zenodo DOI for the releases are somewhat meaningless.)
To install a specific release:
Use pip (see above). This is the recommended approach if you do not use conda.
Install from bioconda. This is the recommended approach.
Clone the repo, checkout the release, and update submodules:
git clone http://github.com/molpopgen/fwdpy11
cd fwdpy11
git submodule init
git submodule update
The latter method is probably the least appealing.
We have a strict policy of putting releases on PyPi and bioconda. If there is a release on PyPi but not on bioconda, then that is because we identified a bug and pushed a new release before the bioconda build happend. It happens. That’s life.
Enabling code profiling
By default, fwdpy11 is compiled with aggressive optimizations to help reduce the library size. One side effect is that it becomes impossible to accurately profile the code. To override these defaults:
python setup.py build_ext -i --enable-profiling
Disabling link-time optimization (LTO)
LTO is enabled by default and reduced the final library size substantially. However, it takes a long time and is therefore a drag during development. To disable it:
python setup.py build_ext -i --disable_lto
Enabling debugging symbols in the C++ code
python setup.py build_ext -i --debug
Debug mode disables all compiler optimizations, allows C-like assertions, and generated debug symbols.
Enabling assertions in the C++ code
The fwdpp library code uses C’s assert macros in several places. These are disabled by default. However, it can be useful to enable them when hacking the code. To do so, you must manually set your compiler flags with cmake:
cmake . -DCMAKE_CXX_FLAGS="-UNDEBUG -O2 -g"
When compiling this way, fwdpy11 makes some extra checks that will throw RuntimeError if they fail. The fwdpp back end also makes extra checks. If those fail, abort will be called, which will crash the Python interpreter. Thus, compiling with this option is a “serious debugging mode only” option.
Enabling aggressive debugging of C++ STL templates using GCC
Use the following flags to enable an “extreme” debugging mode of the C++ standard template library:
CXXFLAGS="-D_GLIBCXX_CONCEPT_CHECKS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC" \
CPPFLAGS="-D_GLIBCXX_CONCEPT_CHECKS -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC" python3 setup.py build_ext -i
Static analysis using clang-tidy
It is sometimes useful to go through the code and to a “static” analysis to look for problems. The clang-tidy tool is especially useful. For example:
find fwdpy11/src/ -name '*.cc' | xargs -I {} clang-tidy -checks='performance-*' {} -- -I/usr/include/python3.7m -I./fwdpy11/headers/fwdpp -I./fwdpy11/headers
Bioconda
fwdpy11 is available through bioconda for Linux and for macOS:
conda install -c bioconda fwdpy11
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.