Skip to content

Mac M1 M2 installation

Bharat Medasani edited this page Oct 27, 2023 · 5 revisions

Find below the simsopt and VMEC installation instructions from source onto a mac with an M1 chip. The simsopt installation works as of March 21, 2021 and the VMEC installation works as of July 11, 2022. Installation with only conda-toolchain works as of Oct 25, 2023 (preferred) on Mac OS Ventura.

Much of this installation is similar to the standard Mac installation instructions, but for completeness the entire instruction set will be included here.

Conda toolchain only.

The following instructions for installing simsopt with dependencies obtained from conda work for installing vmec also.

  1. Install conda. The installation instructions can be found here.

  2. Add conda-forge channel.

    conda config --add channels conda-forge
  3. Create a conda virtual environment and activate it. Instructions can be found here.

  4. Install compilers, netcdf-fortran, openmpi-mpicc, openmpi-mpifort, and openblas (for VMEC2000)

    conda install compilers netcdf-fortran openmpi-mpicc openmpi-mpifort openblas scalapack

    Restart the terminal after installing the above packages. Also install VMEC build dependencies such as mpi4py, scikit-build, numpy

    conda install mpi4py scikit-build numpy

    Also install f90wrap dependency meson-python from conda

    conda install meson-python

    Install f90wrap from pip without build isolation

    pip install --no-build-isolation f90wrap
  5. Optionally, install VMEC2000 from github.com/hiddensymmetries. Follow the instructions here. Copy cmake/machines/cmake_mac_manual_conda_config.json to cmake_config_file.json. Then install VMEC2000.

  6. Install LLVM-OpenMP and other simsopt dependencies from conda before building simsopt

    conda install llvm-openmp numpy jax jaxlib scipy Deprecated nptyping monty ruamel.yaml sympy f90nml randomgen pyevtk

    If any of the above packages are not installable from conda, install with pip using the command pip install --no-build-isolation <package name>.

  7. Install build dependencies from conda

    conda install cmake ninja setuptools_scm
  8. Obtain simsopt from github.com/hiddensymmetries.

    git clone git@github.com:hiddenSymmetries/simsopt.git

    or

    git clone https://github.com/hiddenSymmetries/simsopt.git

    Switch to the simsopt folder and use pip to install simsopt from source. Make sure to install without build isolation.

    cd simsopt
    pip install --no-build-isolation .

Macports

  1. Install macports. The installation instructions can be found here.

  2. Install openmpi. Multiple versions of openmpi are avaialable. Here openmpi version that matches with clang11 is installed.

    sudo port install openmpi-clang11
    sudo port select --set mpi openmpi-clang11-fortran

    Installation of openmpi-clang11 also install python 3.9. Set this version of python3.9 as default python version.

    sudo port select --set python python39
    sudo port select --set python3 python39
  3. Select the proper mpi version:

    sudo port select --set mpi openmpi-mp-fortran

Conda venv

  1. Install conda. The installation instructions for doing so can be found [here]{https://docs.conda.io/projects/conda/en/latest/user-guide/install/macos.html}. I used Miniconda, but presumably Anaconda will also work.

Mac Catalina (10.15) comes with python 3.7, which can be accessed with python3 command. But we are using the python3.9 from macports. Assuming you ran step 2 in Macports section

  1. Create a virtual environment named simsopt_ve:
    conda create -n <path_where_you_want_the_venv>/simsopt_ve
    
  2. Activate the virtual environment.
    conda activate <path_where_you_want_the_venv>/simsopt_ve/bin/activate
    After activating the virtual environment, (simsopt_ve) should appear in front of the command prompt.

Homebrew and OpenBLAS

  1. Install homebrew by running
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2. Add homebrew to path:
    echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/agood/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"

Replacing agood in the above command with your cobra username.

  1. Install openBLAS by running

    brew install openblas
    
  2. Set up the openBLAS path:

    export PKG_CONFIG_PATH="/opt/homebrew/opt/openblas/lib/pkgconfig" OPENBLAS="$(brew --prefix openblas)"
    

Simsopt

  1. Clone the simsopt directory anywhere in your file system, and navigate to that directory

    git clone https://github.com:hiddenSymmetries/simsopt.git
    cd simsopt
  2. In the CMakeLists.txt file, replace all instances of march=native with mpcu=apple-m1.

  3. Install simsopt by running

    OPENBLAS="$(brew --prefix openblas)" pip install -e ".[MPI]"

VMEC installation

  1. Run the following command to set up conda properly, and install the needed packages using conda:
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install mpi4py
conda install -c conda-forge netcdf-fortran
conda install -c conda-forge scalapack 
pip install mpi4py scikit-build numpy f90wrap ninja cmake
conda install -c conda-forge gfortran
  1. Clone the VMEC2000 repository to your system, and navigate to that directory
git clone https://github.com/hiddenSymmetries/VMEC2000
cd VMEC2000
  1. Navigate to the VMEC2000 directory, and replace the contents of the cmake_config_file.json with
{
    "cmake_args": [
        "-DCMAKE_C_COMPILER=clang",
        "-DCMAKE_CXX_COMPILER=clang",
        "-DCMAKE_Fortran_COMPILER=mpif90",
        "-DNETCDF_INC_PATH=/opt/homebrew/opt/netcdf",
        "-DNETCDF_LIB_PATH=/opt/homebrew/opt/netcdf",
        "-DNETCDF_I=/opt/local/include/netcdf.inc"]
}
  1. Install VMEC
python setup.py build_ext
python setup.py install