Skip to content

Native macOS build

mpaterno edited this page Feb 26, 2020 · 59 revisions

These are instructions for getting going with the macOS native build, and our Y3 galaxy cluster analysis software.

This macOS Native installation works with macOS version of 10.14+ (Mojave), and especially Xcode Version 10+ (comes with the macOS Mojave updates). Do not try to build on systems with lower versions. It won't work.

Read the instructions carefully. Do not skip any steps.

Please report any errors in the instructions to Marc (paterno@fnal.gov).

Make sure your Xcode installation is up-to-date

We rely on several features of C++ that are only available in recent Xcode installations. In addition, we rely on several Homebrew packages, and Homebrew requires and up-to-date Xcode for correct behavior.

To obtain the software

You only have to do this once. Of course, you’ll periodically need to update your copy of the various git repositories, using git pull, etc.

You are expected to have the Homebrew packages, and python modules required by CosmoSIS.

For our Y3 galaxy clusters analysis, we need some additional software. Note that we update our Homebrew installation before doing anything else -- failure to keep your Homebrew installation up-to-date is a common cause of build failures, especially of hard-to-diagnose link-time failures. If you have a Homebrew installation that hasn't been updated in weeks, this may take a while.

#!bash

brew update
brew upgrade
# If the following install commands tell you that you already have some of these things
# installed and up-to-date, that is not a problem.
brew install git gcc gsl cfitsio fftw minuit2 openblas # these are required for CosmoSIS itself
brew install eigen cmake gperftools                    # these are required for Y3 galaxy cluster code
brew install python3                                   # you know you want to
brew install wget                                      # you know you want to

Next, you need to build libcuba.dylib. There is a Homebrew installation of cuba available; it does not build a dynamic library, and it does not use the optimization level we want. Do not use it. Do the following instead:

#!bash

pushd /tmp
wget http://www.feynarts.de/cuba/Cuba-4.2.tar.gz
tar xf Cuba-4.2.tar.gz
rm Cuba-4.2.tar.gz
cd Cuba-4.2
CC=clang CFLAGS="-O3 -funsafe-math-optimizations -march=native -fPIC" ./configure
cp cuba.h /usr/local/include/cuba.h
make lib
ar x libcuba.a
clang -shared *.o -o libcuba.dylib
mv libcuba.dylib /usr/local/lib
popd
rm -r /tmp/Cuba-4.2

Now we’re on to building CosmoSIS and the CSL:

#!bash

git clone http://bitbucket.org/joezuntz/cosmosis
cd cosmosis
git checkout develop # Release v1.6.2 fails on current macOS
git clone http://bitbucket.org/joezuntz/cosmosis-standard-library
cd cosmosis-standard-library
git checkout neutrinoless_mass_function # This branch has an update CSL module we require
git clone git@bitbucket.org:mpaterno/y3_cluster_cpp.git
cd y3_cluster_cpp
cd ../..
source config/setup-cosmosis-mac
pip3 install --user -r config/requirements.txt
make        # This builds cosmosis and the CSL, but not our Y3 galaxy cluster software

Next, we need cubacpp. This is a header-only library, so all you need to do is clone the repository. We do this in the top-level cosmosis directory.

#!bash

source config/setup-cosmosis-mac # only if you haven’t already done it in this shell session
git clone git@bitbucket.org:mpaterno/cubacpp.git

To build and use our Y3 galaxy cluster software

Because CosmoSIS is built using hand-written Makefiles, and y3_cluster_cpp uses CMake-generated Makefiles, building is a bit more complicated than it would be with a single build system. Marc is working on getting CMake to be used by CosmoSIS; this will only happen if the CosmoSIS user community is comfortable with using CMake. Feel free to spread the word with our DES colleagues.

#!bash

source config/setup-cosmosis-mac # only if you haven’t already done it in this shell session
cd cosmosis-standard-library/y3_cluster_cpp
cmake -DCMAKE_MODULE_PATH="${COSMOSIS_SRC_DIR}/cosmosis-standard-library/y3_cluster_cpp/CMake;${COSMOSIS_SRC_DIR}/cubacpp/cmake/modules" -DCUBACPP_DIR=${COSMOSIS_SRC_DIR}/cubacpp -DCUBA_DIR=/usr/local -DCMAKE_BUILD_TYPE=Release .
make -j2 # or -j4, if you have a 4-core laptop. Don’t use -j (without a number)
ctest -j2 # or -j4, if you have a 4-core laptop. 

If you encounter a compilation failure that says:

fatal error: 'optional' file not found

this is an indication that your Xcode installation is out-of-date. You will need to upgrade Xcode before you can continue.

To install cluster_toolkit

Some Y3 galaxy cluster pipelines use the Python module cluster_toolkit. Installing this is not done with pip3; you must do it more manually. Note that there is a quirk in the installation script that requires an unusual syntax. Make sure you do not put a space after the final = for this command.

#!bash

mkdir -p /tmp/cluster_toolkit_tmp
pushd /tmp/cluster_toolkit_tmp
git clone https://github.com/tmcclintock/cluster_toolkit.git
cd cluster_toolkit
python3 setup.py install --user --prefix=
popd
rm -rf /tmp/cluster_toolkit_tmp

The --prefix= flag, in our case, installs the cluster_toolkit in the standard python location in the cosmosis directory tree.

For day-to-day work

As noted several times above, every time you want to work with CosmoSIS in a new shell session, you need to source the setup script:

#!bash

source config/setup-cosmosis-mac # only if you haven’t already done it in this shell session; also, only this path, otherwise the setup doesnt work!
cosmosis-py3 #  to run any cosmosis job, one wants to access the python3 installation, use cosmosis-py3

You should be doing most of your work (editing code, building, running cosmosis) from the y3_cluster_cpp directory, or some directory below that. Pay careful attention to what directory you are in when using git commands: different parts of the cosmosis directory tree are under version control in different repositories!

Clone this wiki locally