DFTK.jl icon indicating copy to clipboard operation
DFTK.jl copied to clipboard

Initial ideas for Aiida integration

Open mfherbst opened this issue 2 years ago • 8 comments

@azadoks Some initial fruit for discussion.

mfherbst avatar Jun 28 '22 16:06 mfherbst

Not sure if DftkParameters should even exist or if it is wise to put all of this into a submodule.

But let's lock first the names for the parameters first and the basic structure for passing them and then we see how we fix that in concrete code.

mfherbst avatar Jun 28 '22 16:06 mfherbst

Maybe also makes sense to make use of as much of https://github.com/JuliaMolSim/DFTK.jl/blob/master/src/external/interatomicpotentials.jl or to exploit similarities in the implementation.

mfherbst avatar Jun 28 '22 16:06 mfherbst

It looks like you're doing a bit of sanity checking in code (e.g. that the smearing type is known). This makes sense if the AiiDA plugin writes a .jl file for input (i.e. it could write a file which creates a struct instance and then calls a sort of main function), but it might eventually lead to some fairly complicated logic to make sure that everything is consistent.

A different avenue would be to define a TOML/JSON schema which deals with making sure inputs are in a defined range, the correct shape, from a restricted list of keywords, etc. Then a TOML/JSON schema library will check all of this automatically and raise an appropriate error wherever inconsistencies/incorrectness is found. This would mean that the DFTK AiiDA interface could assume everything is correct and would just have to concern itself with setting up the system and running the requested calculation.

azadoks avatar Jun 29 '22 08:06 azadoks

This makes sense if the AiiDA plugin writes a .jl file for input (i.e. it could write a file which creates a struct instance and then calls a sort of main function)

I know nothing about AiiDA and Michael will have a better idea about this than me, but have you considered using PyJulia or https://github.com/cjdoris/PythonCall.jl?

antoine-levitt avatar Jun 29 '22 08:06 antoine-levitt

Nice idea, but unfortunately that's not sufficient because where you manage Aiida workflows and where they run could be different machines (e.g. laptop versus cluster).

mfherbst avatar Jun 29 '22 09:06 mfherbst

OK; in that case there is packagecompiler and https://github.com/dmolina/DaemonMode.jl

antoine-levitt avatar Jun 29 '22 09:06 antoine-levitt

indeed, but deamonmode is also tricky for other reasons (when should the daemon be shut down?) For the first version we will be stupid and recompile DFTK from scratch in each calculation. Should not be too bad. The idea of Aiida is anyway to have larger chunks of work (geometry optimisation, band structure calculation etc.) as one complete building block.

mfherbst avatar Jun 29 '22 09:06 mfherbst

The general idea of AiiDA is to completely separate AiiDA itself and the calculation being run. As such, AiiDA is run on some host computer; for the sake of simplicity let's say that's where the database, RabbitMQ message server, and daemon are run (this need not be the case).

To run, e.g., Abinit, I would install the abinit binary on a work computer (could be the host computer, could be a cluster, etc.). I then set up a Computer node in AiiDA which has info on how to connect and launch processes on the work computer. Next, I set up a Code node in AiiDA which is linked to the Computer on which it is installed, which contains code-specific details about the shell environment, location of the binary, etc.

Then, on the host computer I write a script which defines the inputs of the Abinit calculation, create an AbinitCalculation node with those inputs and run it, either synchronously with run or asynchronously (i.e. give it to a daemon process) with submit. AiiDA will then write an input file aiida.abi, a submission/launch script _aiidasubmit.sh, and any other miscellaneous files (e.g. pseudopotentials). All those files will be copied to the work computer via SSH or locally into a working directory /somedir/aiida/xx/xx/xxxxxxxxx. Then, AiiDA will send the submission command (sbatch or similar) to the work computer.

The daemon or python process will then occasionally (SSH default: 30s, local default: 1s) poll the work computer to check if the job is done. Once it's finished, AiiDA will copy some list of files (e.g. aiida.abo) back to the host computer and parse them. The parsed output is then stored in the database/graph by the AiiDA ORM.

There are many tricks that can be played at various parts of this process, but they'll require some thinking and engineering. I know that Louis Ponet has some tooling around running Julia codes with AiiDA, so maybe it would be good to bring him on for advice eventually.

For the moment, the easiest thing to do (from my point of view) would be to copy dftk.in.toml or similar to the work machine and set up julia as a Code. The DftkCalculation can then write an appropriate run command something like $julia_bin --project=$dftk_environment $dftk_script -in dftk.in.toml -out dftk.out.hdf5.

azadoks avatar Jun 29 '22 10:06 azadoks

Closing this as this will be superseeded by an upcoming project going in a slightly different direction.

mfherbst avatar Jun 13 '23 11:06 mfherbst