Skip to content

Installation

COLLAPSO1D supports gfortran and Intel's Classic Fortran ifort. The latter runs ~70% faster, but requires a more involved installation. Instruction are given for Linux (tested on Ubuntu 20.04 and 22.04), with Mac specific commands in spoilers.

Defendencies

pybind11

Python bindings for C++, which are necessary for the PyTorch wrapper.

pip install pybind11

CMake

Make sure you have cmake or install it by (tested on cmake==3.22.1)

sudo apt install cmake

Mac OS
brew install cmake

PyTorch

To install the latest PyTorch 1.X or 2.X for CPU, follow the official instructions. Explicitly, the code has been tested with torch==1.13.1 and 2.0.1. I would highly recommend installing it in a dedicated conda environemnt. As an example, here is how to create one and install PyTorch:

1
2
3
4
5
conda create -n py310 python=3.10
conda activate py310

# check the pytorch installation instructions!
pip install torch --index-url https://download.pytorch.org/whl/cpu

Warning

torch>=1.13.1 will work for inferencing, hence for the CCSN code will be fine, but loading and training the model will fail. Thus, resnet_forward will still work, but polynomial example will fail.

EOS Tables

You will also need to download the SFHo EOS Table and put it in the executable directory.

Mac OS
brew install wget

cd project/1dmlmix
wget https://su.drive.sunet.se/index.php/s/FQkikyGcRnHTZNL/download/Hempel_SFHoEOS_rho222_temp180_ye60_version_1.3_20190605.h5
Click to learn more about the EOS Tables in COLLAPSO1D.


GFORTRAN

Both the main CCSN code and the PyTorch wrapper can be compiled with gfortran >= 9.4.0. If missing, install it via:

sudo apt install gfortran

Mac OS
brew install gfortran

In the Makefile, set

COMPILER=gfortran

HDF5

EOS tables (SFHo by default) require an hdf5 installation. If missing, get it via:

sudo apt-get install libhdf5-dev
Then you need to provide paths to the hdf5 libraries in the Makefile. If yours differ from default, edit:
HDF5PATH = /usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5INCS = -I/usr/include/hdf5/serial

Mac OS

brew install hdf5
The paths will most likely be as follows:
HDF5PATH = /opt/homebrew/lib
HDF5INCS = -I/opt/homebrew/include

Add the following to you ~/.bashrc and then source ~/.bashrc:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.

Mac OS

You should add the above line to .bash_profile instead. Create it if it doesn't exist.

Test Installation

Run the following to test your installation

make


Intel ifort

I would highly recommend installing Intel's oneAPI through APT. Even though there are many options listed, a good number of them are bugged. In addition, we need to install a full basekit, instead of only the Fortran compiler, as there are issues with individual packages.

Please follow APT Installation Guide on Intel's website to install intel-hpckit. After the pre-installation steps, you should run the following:

sudo apt install intel-hpckit
Next you will need to add executables to PATH. The easiest way is to run:
source /opt/intel/oneapi/setvars.sh
Add this line to your ~/.bashrc to avoid re-running the above initialization on every start-up.

In the Makefile, set

COMPILER=ifort

Warning

The readout.f90 to convert unformatted binary output to readable text will still be compiled with gfortran (hardcoded in the Makefile), since ifort is ~x20 slower at parsing unformatted binary files for some reason. These slow downs have no effect of the actual CCSN calculation, hence ifort remains vastly superior for the main code.

HDF5 with ifort

To use COLLAPSO1D with EOS Tables, we will also need to re-compile the hdf5 library with ifort. For that, we need to do a custom installation of hdf5. I tested on hdf5-1.12.2.

  1. Download the latest HDF5 Source Code.
  2. Configure
    FC=ifort FCFLAGS="-O3" CC=icc CFLAGS="-O3" ./configure --enable-fortran --enable-shared
    
  3. Install
    make install
    
  4. Check
    make check-install
    
  5. Add library path
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:{path_to_hdf5}/hdf5/lib
    
    Add the above to your ~/.bashrc to avoid re-running the above initialization on every start-up

Full installation instructions detailing all of the available commands and flag can be found inside your hdf5 directory in release_docs/INSTALL.

Lastly, don't forget to change in the COLLAPSO1D's Makefile.

HDF5PATH={path_to_hdf5}/hdf5/lib
HDF5INCS=-I{path_to_hdf5}/hdf5/include


Troubleshoot

No CMAKE_CXX_COMPILER could be found

CMake can't find your C compiler. Either check your GCC path or if you are on Ubuntu, run:

sudo apt-get update && sudo apt-get install build-essential

Version Compatibility Issues

If you are having trouble getting the dependencies and COLLAPSO1D to work, please check the GitHub compilation test. The script sets up a clean Linux environment with explicitely defined package versions. It checks if COLLAPSO1D compiles correctly with gfortran on every push to the repo.

compilation_test.yml
name: CompilationTest

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: ['3.10']
        gcc_v: [11]
        torch_v: ['1.13.1']

    steps:
    - uses: actions/checkout@v1
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }} 
    - name: Install essentials
      run: |
        sudo apt-get update
        sudo apt-get install -y build-essential
    - name: Install GFortran
      run: |
        sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
        sudo apt-get install -y gcc-${{ matrix.gcc_v }} gfortran-${{ matrix.gcc_v }}
        gfortran --version
    - name: Install CMake
      run: |
        sudo apt install -y cmake
    - name: Install HDF5
      run: |
        sudo apt-get install -y libhdf5-dev
    - name: Install PyTorch
      run: |
        sudo apt install -y python3-pip
        pip3 install torch==${{ matrix.torch_v }}+cpu --extra-index-url https://download.pytorch.org/whl/cpu
    - name: Install pybind11
      run: |
        pip3 install pybind11
    - name: Env vars
      run: |
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
    - name: Download EOS tables
      run: |
        wget https://su.drive.sunet.se/index.php/s/FQkikyGcRnHTZNL/download/Hempel_SFHoEOS_rho222_temp180_ye60_version_1.3_20190605.h5 -P ./project/1dmlmix/        
    - name: Test compilation
      run: |
        make test
    # - name: Run polynomial example
    #   run: |
    #     make examples
    #     cd examples/polynomial/
    #     python setup_model.py
    #     ./polynomial traced_model.pt test.pt
    # - name: Run resnet-forward example
    #   run: |
    #     make examples
    #     cd examples/resnet-forward/
    #     python setup_model.py
    #     ./resnet-forward traced_model.pt