Legacy FEniCS 2019 on Apple Silicon

Has anyone had success running the legacy FEniCS 2019.1.0 on Apple Silicon? This discussion seems to be about FEniCSx, but I still use the legacy FEniCS for a project that has not been (and would be quite hard to) update to FEniCSx.

If anyone knows that FEniCS 2019 cannot run on Apple Silicon or has other advice, that would be welcome.

1 Like

There shouldn’t be a problem. A coworker has built the old dolfin docker images on his M1 Mac so it’s definitely possible. Perhaps you could try the same.

https://bitbucket.org/fenics-project/docker/src/master/

Very glad to hear that it’s been done successfully. I don’t have an Apple Silicon machine on which to test yet, but as my current ones age out, I am going to make the transition. If I couldn’t run legacy dolfin, that would perhaps change my purchase plans.
Thanks!

I just bought a Mac Studio with M1 Max. I searched for fenics using conda but did not find any fenics from conda-forge. It is good to know that fenics 2019 works on M1 and can get a docker image from the web link. However, is it possible for an author of the web link to produce a version of fenics for conda-forge? Doing so will be highly appreciated by many fenics users like me.

1 Like

Maybe not ideal, but you can create a x64 env in conda and run fenics 2019 with Rosetta:

CONDA_SUBDIR=osx-64 conda create -n myenv_x64 python=3.9
conda activate myenv_x64
conda config --env --set subdir osx-64

conda create -n fenics2019 -c conda-forge mshr=2019.1.0=py38h2af9582_2
1 Like

Thanks, Paulms. I installed fenics on my Mac Studio. It works!

Did you use the Paulms’ way?

Yes. I did exactly. But, Paulms’ way may cause new problems. For example, I got an error of an incompatible architecture (have ‘arm64’, need 'x86_64’) when using f2py since gfortran was run on Apple Silicon (Paulms, can you have a way to fix this issue? This issue is common since f2py is often used). Hence, it is still important for someone to generate a binary of fenics 2019 for Apple Silicon.

I’m afraid that I don’t use f2py myself. The method above will certainly fail if the package tries to interface with external executables (not installed by conda itself) due to mixed architectures.

conda create -n fenics2019
conda activate fenics2019
conda config --env --set subdir osx-64

Running the following commands will create a conda environment named fenics2019 that’s set to be an x64 environment permanently, so anything installed should be installed for x64.

1 Like

Confirming, Paulms solutions is functional for me. I was suffering from “catastrophic performance degradation” using the usual fenics2019 docker container. I couldn’t quite piece together how to build my own for that, but thankfully your conda solution works great. I really appreciate it.

I would love to just migrate to fenicsx, since it seems to have better apple silicon support, but I’m bound to hippylib which depends on the 2019 version. I need to put in some time to try and implement the features I need from it in dolfinx.

use this command install fenics and mshr , how to install matplotlib?

As matplotlib is on conda you can call conda install -c conda-forge matplotlib, see: Matplotlib :: Anaconda.org

Hi Paulms, thank you for the solution. I am trying to install Fenics 2019 on my Mac Pro with M1 chip and it keeps showing the package is not available from current channels as shown in the screenshot. Any idea about this issue?

I installed that specific version since, at that time, the latest build gave me problems with the ‘mshr’ package. Maybe that build has been replaced with more recent ones in the conda repository. You can omit the version (==2019.1…), and try the latest builds. Perhaps it works now, or you can check the available versions at this link: Files :: Anaconda.org

Thank you, Paulms. Let me try it.

Additional details, in case you find them useful.
What I have done in November 2023 to make it run on M1:

conda update -n base -c defaults conda
CONDA_SUBDIR=osx-64 conda create -n myenv_x64 python=3.9
conda activate myenv_x64
conda config --env --set subdir osx-64
conda create -n fenics2019 -c conda-forge fenics
conda activate fenics2019 
pip install meshio   
pip install h5py
pip install matplotlib
2 Likes

Hi!
Thank you for sharing your complete solution. I am trying to install fenics on my MacAir M2 and I have a few questions.

  1. You run “conda create -n …” twice. Why? Can I just run

    conda update -n base -c defaults conda
    CONDA_SUBDIR=osx-64 conda create -n myenv_x64 python=3.9
    conda activate myenv_x64
    conda config --env --set subdir osx-64
    

    and then like

    conda install -c conda-forge fenics-dolfinx mpich pyvista
    

    or

    pip install ...
    
  2. Install fenics from conda-forge seems to take too long for me. Can I install it from other sources?

Hi!

Thanks for your answer! I am trying to install fenics on my MacAir M2 and have a few questions.

  1. Is it correct to run
conda install -c conda-forge fenics-dolfinx mpich pyvista

after the commands in your solutions?

  1. Will the x64 environment be activated automatically every time I run
conda activate ...

later?

OP here, and I thought I should chime in with a different solution that has been working for me, to get legacy fenics on apple silicon.

On my Mac, I use an Ubuntu docker container, which works fine, but there is an extra flag you need to set to make sure you build for arm64 rather than (the much slower) amd64 with Rosetta. You do not want to use an old pre-built Docker image, because that will be for amd64 and run slowly, but it’s not hard to build a new one.

Regardless of what Dockerfile you use, the key is to build using something like

docker build -f Dockerfile --platform linux/arm64 -t container_name .

The Dockerfile that I use for installing Simudo is here. It does a bunch of things that you wouldn’t need, so you could easily delete lines 7, 10, 13, 14, 15 and many of the packages on lines 21-29, as you like. Legacy dolfin is on line 25. It also included a cautious non-pip installation of Simudo on lines 36-44 that you don’t need, which verifies hashes of the files. You could likely also build off of one of the Dockerfiles here, as @nate suggested above.

1 Like