Sharing a quick guide on how to get ABACUS compiled and running well in Modal. If you want to run DFT calculation with ABACUS in a serverless environment, this is the guide you're looking for.
Why might you want to do something like this? Maybe you don't have access to HPC. Modal offers cheap, on-demand access to a variety of high-end GPUs, like the A100. Or, if you need first-principles atomistic simulation data and want to offer an API on top of the functionality so that others can use it, this is a great approach too.
I've had a lot of success with this approach, particularly the plane wave approach with basis_type pw and ks_solver bpcg. Seems this setup has the best GPU support and utilization as of v3.9.0.
Let's take a look at the config. For the most part, you should be able to copy and paste this Modal image setup into your projects and you'll be good to go. I went with the modal.Image.from_dockerfile approach, but I imagine you could rework it to be compatible with their built-in approach to take better advantage of their build caching system.
Copy this code block into a file called Dockerfile:
Notice the important build flag -DUSE_CUDA=1 to get us our GPU support. Make sure when you make your INPUT files to also set device gpu! See the docs here.
In your Modal app code, build the image like so:
ABACUS will need pseudopotentials and orbital files before it can run too. I think it's best to put those in a Modal Volume and mount it to the image so you can easily update them and not have to rebuild the entire image again.
Commands to load those up might look something like this (assuming you have local folders called pseudopotentials/ and basis/):
Once you get the image built, you will see something about the NVIDA image being depreciated. I'm sure you could update that to something supported but I haven't gotten around to that yet.
And that's it for setup! To run ABACUS in the container, I would usually use Python subprocess to run.
Set up the calc_dir to include all your necessary INPUT, KPT, STRU files as need and then you can let ABACUS do it's thing. I would make the calc_dir on the Modal Volume for persistence and observability so that I could debug runs from the web UI even after the container finished working.
And that's about all there is to it. Hopefully this unlocks some awesome use cases for materials science, chemistry, and other atomistic work! Share what you build here so we can all benefit too! Happy building.
On this page
A simple guide for compiling ABACUS to run with GPU acceleration in Modal. The post explains how to build ABACUS with CUDA support and run DFT calculations in a serverless environment. It covers why Modal’s on‑demand GPUs (like A100) can help, and which ABACUS setup (plane waves with basis_type pw and ks_solver bpcg) tends to work best on GPUs in version 3.9.0.