The easiest way to install
21cmFAST is to use
conda. Simply use
conda install -c conda-forge 21cmFAST. With this method, all dependencies are taken
care of, and it should work on either Linux or MacOS. If for some reason this is not
possible for you, read on.
We try to have as many of the dependencies automatically installed as possible.
21cmFAST relies on some C libraries, this is not always possible.
The C libraries required are:
fftw(compiled with floating-point enabled, and
A C-compiler with compatibility with the
-fopenmpflag. Note: it seems that on OSX, if using
gcc, you will need
As it turns out, though these are fairly common libraries, getting them installed in a
21cmFAST understands on various operating systems can be slightly non-trivial.
These libraries will often be available on a HPC environment by using the
module load gsl and similar commands. Note that just because they are loaded
doesn’t mean that
21cmFAST will be able to find them. You may have to point to the
include/ folders for both
fftw (these should
be available using
module show gsl etc.)
Note also that while
fftw may be available to load, it may not have the correct
compilation options (i.e. float-enabled and multiprocessing-enabled). In this case,
Most linux distros come with packages for the requirements, and also
gcc by default,
-fopenmp. As long as these packages install into the standard location,
a standard installation of
21cmFAST will be automatically possible (see below).
If they are installed to a place not on the
INCLUDE paths, then you
must use the compilation options (see below) to specify where they are.
there exists the option of installing
This is discussed below in the context of MacOSX, where it is often the
easiest way to get the dependencies, but it is equally applicable to linux.
On MacOSX, obtaining
fftw is typically more difficult, and in addition,
the newer native
clang does not offer
conda users (which we recommend using), the easiest way to get
is by doing
conda install -c conda-forge gsl fftw in your environment.
if you use
conda to install
fftw, then you will need to point at
their location when installing 21cmFAST (see compiler options below for details).
In this case, the installation command should simply be prepended with:
gcc, either use
homebrew, or again,
conda install -c anaconda gcc.
If you get the
conda version, you still need to install the headers:
On older versions then you need to do:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_<input version>.pkg
For newer versions, you may need to prepend the following command to your
pip install command
21cmFAST (see later instructions):
CFLAGS="-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX<input version>.sdk"
See faqs/installation_faq for more detailed questions on installation. If you are on MacOSX and are having trouble with installation (or would like to share a successful installation strategy!) please see the open issue.
With the dependencies installed, follow the instructions below, depending on whether you are a user or a developer.
conda users may want to pre-install the following packages before running
the below installation commands:
conda install numpy scipy click pyyaml cffi astropy h5py
Then, at the command line:
pip install git+git://github.com/21cmFAST/21cmFAST.git
If developing, from the top-level directory do:
pip install -e .
Note the compile options discussed below!
If you are developing
21cmFAST, we highly recommend using
conda to manage your
environment, and setting up an isolated environment. If this is the case, setting up
a full environment (with all testing and documentation dependencies) should be as easy
as (from top-level dir):
conda env create -f environment_dev.yml
Otherwise, if you are using
pip install -e .[dev]
[dev] “extra” here installs all development dependencies. You can instead use
[tests] if you only want dependencies for testing, or
[docs] to be able to
compile the documentation.
Various options exist to manage compilation via environment variables. Basically,
any variable with “INC” in its name will add to the includes directories, while
any variable with “lib” in its name will add to the directories searched for
libraries. To change the C compiler, use
CC. Finally, if you want to compile
the C-library in dev mode (so you can do stuff like valgrid and gdb with it),
install with DEBUG=True. So for example:
CC=/usr/bin/gcc DEBUG=True GSL_LIB=/opt/local/lib FFTW_INC=/usr/local/include pip install -e .
In addition, the
BOXDIR variable specifies the default directory that any
data produced by 21cmFAST will be cached. This value can be updated at any time by
changing it in the
$CFGDIR/config.yml file, and can be overwritten on a
-e option will keep your library up-to-date with any (Python)
changes, this will not work when changing the C extension. If the C code
changes, you need to manually run
rm -rf build/* then re-install as above.
Logging in C-Code¶
By default, the C-code will only print to stderr when it encounters warnings or critical errors. However, there exist several levels of logging output that can be switched on, but only at compilation time. To enable these, use the following:
LOG_LEVEL=<log_level> pip install -e .
<log_level> can be any non-negative integer, or one of the following
NONE, ERROR, WARNING, INFO, DEBUG, SUPER_DEBUG, ULTRA_DEBUG
If an integer is passed, it corresponds to the above levels in order (starting from zero). Be careful if the level is set to 0 (or NONE), as useful error and warning messages will not be printed. By default, the log level is 2 (or WARNING), unless the DEBUG=1 environment variable is set, in which case the default is 4 (or DEBUG). Using very high levels (eg. ULTRA_DEBUG) can print out a lot of information and make the run time much longer, but may be useful in some specific cases.