Yambo via Docker: Difference between revisions

From The Yambo Project
Jump to navigation Jump to search
(Copy and paste from previous school)
 
No edit summary
Line 3: Line 3:


* Install the docker platform (Linux or Mac). Follow the instruction  in the docker [https://docs.docker.com/engine/install/ website].
* Install the docker platform (Linux or Mac). Follow the instruction  in the docker [https://docs.docker.com/engine/install/ website].
* Pull the Yambo container:


  sudo docker pull nicspalla/yambo-gcc_openmp_petsc:latest
It is possible to run Docker by a normal user without the sudo privileges. In order to do that you have to add your username to the group "docker" (suggested on Linux!).  
 
sudo it is not necessary if your user is part of the group named docker (suggested on Linux!).


For Linux users:
For Linux users:
Line 19: Line 16:
   sudo dseditgroup -o edit -a $USER -t user docker
   sudo dseditgroup -o edit -a $USER -t user docker


Log out and log back in so that your group membership is re-evaluated.
Log out and log back in so that your group membership is re-evaluated.  
 
If you you prefer to use sudo please remember to add the "sudo" command before all the commands below.
 
* Pull the Yambo container:
 
  docker pull maxcentre/yambo:5.1.0_gcc9


* You are done. To run Yambo into the container:
* You are done. To run Yambo into the container:
Line 26: Line 29:
     --mount type=bind,source="$(pwd)",target=/tmpdir \
     --mount type=bind,source="$(pwd)",target=/tmpdir \
     -e OMP_NUM_THREADS=4  \
     -e OMP_NUM_THREADS=4  \
     nicspalla/yambo-gcc_openmp_petsc:latest \
     maxcentre/yambo:5.1.0_gcc9 \
     yambo -F yambo.in -J yambo.out
     yambo -F yambo.in -J yambo.out


Otherwise (suggested!), copy and paste the code below in a file, i.e called drun.sh:
Otherwise (suggested!), copy and paste the code below in a file, i.e called drun.sh:


  #!/bin/bash  
  #!/bin/bash
threads=1
environment="--env-file env.txt"
container="maxcentre/yambo:5.1.0_gcc9"
command_prefix=""
### MAIN ###
while [[ $1 == -* ]]; do
    case $1 in
    -t | --threads ) threads=$2
  shift 2
  ;;
    -c | --container) container=$2
  shift 2
  ;;
-np | --nprocess ) command_prefix="mpirun --use-hwthread-cpus -np $2"
    shift 2
    ;;
--env-file ) environment="--env-file $2"
      shift 2
      ;;
-i | --init ) docker pull ${container}
      docker run -ti --user $(id -u):$(id -g) \
      --mount type=bind,source="$(pwd)",target=/scratch \
      ${container} cat /opt/spack/env.txt > env.txt
      exit 0
              ;;
        * ) echo "Error: \"$1\" unrecognized argument."
    exit 1
    esac
done
  docker run -ti --user $(id -u):$(id -g) \
  docker run -ti --user $(id -u):$(id -g) \
    --mount type=bind,source="$(pwd)",target=/tmpdir \
        --mount type=bind,source="$(pwd)",target=/scratch \
    -e OMP_NUM_THREADS=\
        -e OMP_NUM_THREADS=${threads} ${environment} \
    nicspalla/yambo-gcc_openmp_petsc:latest $@
        ${container} ${command_prefix} $@


then give the file execute privileges:
then give the file execute privileges:
Line 41: Line 75:
  chmod +x drun.sh
  chmod +x drun.sh


Move (or copy) this file in the directory where you want to use Yambo and use it as prefix of your Yambo calculation:
Move (or copy) this file in the directory where you want to use Yambo and use it as prefix of your Yambo calculation.
 
First you have to initialize the environment needed by the container:
 
./drun.sh -i
 
this command will pull the container if not already done and will create a file named env.txt needed by the container to run Yambo.
 
Now you can run yambo like in this example:


  ./drun.sh yambo -F yambo.in -J yambo.out
  ./drun.sh yambo -F yambo.in -J yambo.out

Revision as of 15:48, 30 March 2022

An alternative to get the Yambo code is to install the Yambo container in your machine and this can be done in few steps:

  • Install the docker platform (Linux or Mac). Follow the instruction in the docker website.

It is possible to run Docker by a normal user without the sudo privileges. In order to do that you have to add your username to the group "docker" (suggested on Linux!).

For Linux users:

 sudo groupadd docker
 sudo usermod -aG docker $USER

For Mac users:

 sudo dscl . create /Groups/docker
 sudo dseditgroup -o edit -a $USER -t user docker

Log out and log back in so that your group membership is re-evaluated.

If you you prefer to use sudo please remember to add the "sudo" command before all the commands below.

  • Pull the Yambo container:
 docker pull maxcentre/yambo:5.1.0_gcc9
  • You are done. To run Yambo into the container:
docker run -ti --user $(id -u):$(id -g) \
   --mount type=bind,source="$(pwd)",target=/tmpdir \
   -e OMP_NUM_THREADS=4  \
   maxcentre/yambo:5.1.0_gcc9 \
   yambo -F yambo.in -J yambo.out

Otherwise (suggested!), copy and paste the code below in a file, i.e called drun.sh:

#!/bin/bash
threads=1
environment="--env-file env.txt"
container="maxcentre/yambo:5.1.0_gcc9"
command_prefix=""

### MAIN ###
while $1 == -* ; do
    case $1 in
    -t | --threads ) threads=$2

shift 2  ;;

    -c | --container) container=$2

shift 2  ;; -np | --nprocess ) command_prefix="mpirun --use-hwthread-cpus -np $2" shift 2  ;; --env-file ) environment="--env-file $2" shift 2  ;; -i | --init ) docker pull ${container} docker run -ti --user $(id -u):$(id -g) \ --mount type=bind,source="$(pwd)",target=/scratch \ ${container} cat /opt/spack/env.txt > env.txt exit 0

              ;;
        * ) echo "Error: \"$1\" unrecognized argument."
	    exit 1
    esac
done

docker run -ti --user $(id -u):$(id -g) \
       --mount type=bind,source="$(pwd)",target=/scratch \
       -e OMP_NUM_THREADS=${threads} ${environment} \
       ${container} ${command_prefix} $@

then give the file execute privileges:

chmod +x drun.sh

Move (or copy) this file in the directory where you want to use Yambo and use it as prefix of your Yambo calculation.

First you have to initialize the environment needed by the container:

./drun.sh -i

this command will pull the container if not already done and will create a file named env.txt needed by the container to run Yambo.

Now you can run yambo like in this example:

./drun.sh yambo -F yambo.in -J yambo.out

If the yambo container is working correctly you should obtain:

./drun.sh yambo

yambo: cannot access CORE database (SAVE/*db1 and/or SAVE/*wf)
./drun.sh yambo -h

should provide in output the help for yambo usage.