Building Psi4 and Forte in 2022 on a Mac (arm64)


I have recently upgraded my local Psi4/Forte installation and wanted to share my setup. Since at this time conda does not support Apple’s new M1 architecture natively, I am installing conda with miniforge. These instructions are similar for older x86-based Macs, and I’ll try to point out differences along the way.

Step 1. Download miniforge

Go to the Miniforge GitHub page and download the shell script Miniforge3-MacOSX-arm64.sh. Copy this to your home folder and execute it to install miniforge:

> sh Miniforge3-MacOSX-arm64.sh
Step 2. Create a separate forte environment

I like to create a separate conda environment that includes all the dependencies of Psi4 and Forte. I store the list of dependencies for the new environment in the file forte-macos-arm64.yml. This list includes jupyter and pythreejs (so that you can later use fortecubeview).

name: forte

dependencies:
    - python=3.9
    - pip>=19.0
    - cmake
    - clang-format
    - numpy
    - scipy
    - boost
    - hdf5
    - yaml
    - jupyter
    - eigen
    - pytest
    - pydantic
    - pint
    - pybind11
    - pyyaml
    - pythreejs

On x86 systems, I would also recommend installing libint2 via conda as this will save a lot of compile time

conda install -c psi4/label/dev libint2
Step 3. CLONE, compile, and INSTALL AMBIT

Forte uses the tensor library ambit to store and perform tensor contractions. Installing ambit is optional if you plan on running only Psi4. First clone ambit in your source directory (in my case $HOME/Source)

Source> git clone git@github.com:jturney/ambit.git

To compile ambit, I use the following script ($HOME/Source/compile-ambit.sh) that compiles and installs ambit in the directory $HOME/Bin/ambit-Release. You can toggle the build type and adapt this script to your directory structure.

#! /bin/tcsh
# Script to compile ambit (compile-ambit.sh)

# Modify the following parameters
set srcdir = $HOME/Source/ambit   # <- location of source
set build_type = Release          # <- debug, release, or relwithdebinfo

# define object and prefix dirs
set prefix = $HOME/Bin/ambit-$build_type

# prepare to run cmake
cd $srcdir
rm -rf objdir
rm -rf $prefix

cmake -H. -Bobjdir \
-DCMAKE_BUILD_TYPE=$build_type \
-DCMAKE_INSTALL_PREFIX=$prefix \

cd objdir
make -j10
make install

Then compile ambit with

Source> tcsh compile-ambit.sh

There is one last important step: you need to define an environment variable used by Forte to detect ambit and include ambit in your PYTHONPATH environment variable. Add the following to your $HOME/.zshrc file (or equivalent for bash/tcsh)

# export the path to ambit (for Forte autodetection)
export AMBITPATH=$HOME/Bin/ambit-Release

# export ambit to python
export PYTHONPATH=$PYTHONPATH:$HOME/Bin/ambit-Release/lib
Step 4. CLONE, compile, and INSTALL Psi4

Next, we will compile psi4. This is the longest step in the process and will take some time (less than 20 minutes on my 10-core system), so once the compilation is set into motion, this is a good chance to grab a cup of your favorite ☕️. Start by cloning Psi4 in your source directory

Source> git clone git@github.com:psi4/psi4.git

To compile Psi4, I use the following script ($HOME/Source/compile-psi4.sh). You can toggle the build type and adapt this script to your directory structure. This will produce an optimized (Release) version of Psi4.

#! /bin/tcsh
# Script to compile psi4 (compile-psi4.sh)

# Modify the following four parameters
set srcdir = $HOME/Source/psi4    # <- location of psi4 source
set bindir = $HOME/Bin/psi4       # <- location of psi4 bin
set psi4type = Release            # <- debug, release, ...

# define object and prefix dirs
set objdir = $srcdir/objdir-$psi4type
set prefix = $bindir-$psi4type

# run cmake
cd $srcdir
cmake -H. -B$objdir \
-DCMAKE_BUILD_TYPE=$psi4type \
-DCMAKE_INSTALL_PREFIX=$prefix

cd $objdir
make -j10

Once you have created this file, we need to define one more environment variable to compile Psi4 (this step seems to be specific to the arm64 architecture). Add the following to your $HOME/.zshrc file. This also includes the path of psi4 and adds psi4 to the PYTHONPATH environment variable (so that you can run or import psi4 in python).

# this is required to compile psi4
export CPLUS_INCLUDE_PATH=$HOME/miniforge3/envs/forte/include

# export psi4 to python
export PYTHONPATH=$PYTHONPATH:$HOME/Source/psi4/objdir-Release/stage/lib

# export psi to path
path+=$HOME/Source/psi4/objdir-Release/stage/bin

Now we’re ready to compile psi4:

Source> tcsh compile-psi4.sh
Step 5. CLONE, compile, and INSTALL Forte

Hopefully, this should be the easiest step. Start by cloning Forte from your source directory:

Source> git clone https://github.com/evangelistalab/forte.git

Then you should be simply be able to change directory and run setup.py:

Source> cd forte
Source/forte> python setup.py develop

This will compile and add Forte to your python path. If you run pip list you should be able to see the following line

forte                         0.2.3.        $HOME/Source/forte

To verify that Forte works try to import it

> python -c "import forte"

You could also run the pytest suite:

Source/forte> cd tests/pytest
Source/forte/tests/pytest > pytest

I hope this helps you achieve a quick and smooth compilation of Psi4 and Forte!

,

How to reach us:
francesco.evangelista[at]emory.edu
Francesco Evangelista
Department of Chemistry
Emory University
1515 Dickey Dr. NE
Atlanta, GA 30322


Latest blog posts