Skip to content

Introducing alternative installation methods of firedrake powered by nix #4235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
qbisi opened this issue Apr 15, 2025 · 13 comments
Open

Introducing alternative installation methods of firedrake powered by nix #4235

qbisi opened this issue Apr 15, 2025 · 13 comments
Labels

Comments

@qbisi
Copy link
Contributor

qbisi commented Apr 15, 2025

Hi, i am nixpkgs maintainer working on support the whole firedrakeProject in nixpkgs.

For now, i have built a private recipe repo and binary cache for the unstable firedrake project.
See https://github.com/qbisi/nur-fem.

Nix is a powerful package manager that you can custom your own firedrake implemention by easy override/overlay.

e.g. in provided firedrake init template

_module.args = {
  pkgs = import inputs.nixpkgs {
    inherit system;
    overlays = [
      inputs.nur-fem.overlays.default
      (final: prev: {
        petsc = prev.petsc.override {
          # mpi = prev.mpich;
          # blasProvider = prev.mkl;
          # scalarType = "complex";
          # withFullDeps = true;
          # debug = false;
        };
      })
    ];
    config = {
      allowUnfree = true;
    };
  };
};

you can uncomment those petsc ovrridable option and use your disired settings.

If your group have any plan to release a stable firedrake version, i can help packaging it on nixpkgs.

@qbisi qbisi added the question label Apr 15, 2025
@connorjward
Copy link
Contributor

Good timing: #4193

We hope to have our first versioned release by the end of the month.

@connorjward
Copy link
Contributor

If you want people to find your package you may want to signpost it here

@qbisi
Copy link
Contributor Author

qbisi commented Apr 16, 2025

Can you have a try with my nur-fem repo following the README doc.
I have tested the basic functionality on ubuntu-22.04 myself.

After this nix-way installation method is tested and documented, i will open a pr to signpost it to Alternative installation methods.

Looking forward your feedback.

@connorjward
Copy link
Contributor

I have had a quick go in a Docker container and got to the end of the instructions but I have no idea how to use nix so I don't know how to use the resulting environment. nix run from inside ./fem-demo prints out

error: flake 'path:/home/ubuntu/fem-demo' does not provide attribute apps.x86_64-linux.default', 'defaultApp.x86_64-linux', 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux'

The README is very bare bones at the moment so things could definitely be fleshed out. Some examples at the end would be great. Also what are the prerequisites and supported operating systems?

@qbisi
Copy link
Contributor Author

qbisi commented Apr 16, 2025

I have previously added a duplicated " in .bashrc file. see qbisi/nur-fem@e35fe1e.

This mistake cause the direnv to not work.
After delete the duplicated " in .bashrc, direnv will work.
you can manualy run nix develop in directory fem-demo to enter a develop-shell with firedrake intergrated.

nix can be installed on any linux distribution including ubuntu/debian/arch/nixos and also macos.
No special prerequisites is needed since nix will install all required packages under /nix/store .
For now, Firedrake cannot be compiled on macos with nix. There is a broken packages pyopencl (loopy depend on it) in the way.

@connorjward
Copy link
Contributor

  • I had to add /.nix-profile/bin to PATH to find the nix binary.
  • nix develop works for me. I can run python -c "import firedrake". This is really quite cool. I can't run mpiexec or mpirun though.

@qbisi
Copy link
Contributor Author

qbisi commented Apr 16, 2025

I previously removed mpi from the enviroment to test ABI compatibility of mpi4py with mpich/openmpi.

you can run 'nix flake update' to use the latest nur-fem commit.
Or you can modify the flake.nix like this

          devShells.default =
            let
              python-env = pkgs.jupyter.withPackages (
                ps: with ps; [
                  firedrake
                  matplotlib
                  ipykernel
                  ipympl
                  vtk
                  # add extra python module here
                ]
              );
            in
            pkgs.mkShell {
              packages = [
                python-env 
                pkgs.nixGLHook
               
                # add extra pkgs here
                 pkgs.mpi 
                 pkgs.paraview
              ];

              env.OMP_NUM_THREADS = 1;

              shellHook = ''
                rm .venv -rf
                ln -s ${python-env} .venv
                export VIRTUAL_ENV=$HOME
              '';
            };

@connorjward
Copy link
Contributor

nix flake update didn't seem to put mpiexec or mpirun onto my path.

At the moment I don't really have the time to help with further debugging. If you could clean things up and provide an example of how to use everything (in parallel) then we would be very happy, and would definitely be happy to add something to the website mentioning it.

Please note also that we don't really have the resources to take on maintenance of this. I assume that you are planning on doing that yourself? We will of course be happy to answer questions or fix bugs in Firedrake itself.

By the way it might be sensible to rename this issue to something clearer.

@qbisi qbisi changed the title Any plan for stable release? Introducing alternative installation methods of firedrake powered by nix Apr 16, 2025
@qbisi
Copy link
Contributor Author

qbisi commented Apr 16, 2025

I will maintain the project myself since i am acitively using firedrake on my nixos system.
flesh-out documents are needed, working on this.

@qbisi
Copy link
Contributor Author

qbisi commented Apr 16, 2025

nix flake update didn't seem to put mpiexec or mpirun onto my path.

It should be fixed now. I forgot to push the right commit to github.

@connorjward
Copy link
Contributor

Just to let you know, we have now published the first Firedrake release.

@qbisi
Copy link
Contributor Author

qbisi commented May 3, 2025

I am working on porting firedrake and its component to nixpkgs, those pr need time for review.
NixOS/nixpkgs#403406
NixOS/nixpkgs#403405
NixOS/nixpkgs#403098
NixOS/nixpkgs#403090
NixOS/nixpkgs#400357

Btw, i noted that firedrake is supposed to work on darwin platform. however, in nixpkgs, the dependency codepy (codepy -> loopy -> firedrake) should only work on linux platform. https://github.com/inducer/codepy/blob/3a0492ee2f29e325a28ea8aa049714a873d10649/README.rst?plain=1#L15

My question: how firedrake depend on loopy, Is loopy a dummy dependency of firedrake on darwin platform?

@connorjward
Copy link
Contributor

Firedrake definitely needs loopy to work. I read that as saying that not all functionality of codepy is supported on darwin. The bits we want are available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants