-
Notifications
You must be signed in to change notification settings - Fork 101
Customised docker image for running calculation out-of-box #981
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
unkcpz
wants to merge
14
commits into
main
Choose a base branch
from
docker-image
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f618e7c
Docker image for out-of-box qe calculation running
unkcpz f4ec7e6
Add github action to build and push
unkcpz 852853c
f-m
unkcpz 8b41937
Implement unit test for the built image
unkcpz ea658a5
timeout for session count when test start
unkcpz e164144
test
unkcpz db854fd
More proper service wait fixture
unkcpz 58e074a
Use run-before-daemon to simplify implementation
unkcpz 0806377
finalize the docker tag and push
unkcpz 706ae68
pre-commit
unkcpz 1046eca
Update .docker/Dockerfile
unkcpz a2c486e
Update .docker/tests/conftest.py
unkcpz a378330
Update .docker/Dockerfile to test aiida-core#6176
unkcpz e5677ed
Update .docker/Dockerfile
unkcpz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #FROM ghcr.io/aiidateam/aiida-core-with-services:edge | ||
| FROM ghcr.io/aiidateam/aiida-core-with-services:pr-6170 | ||
|
|
||
| USER root | ||
|
|
||
| ARG QE_VERSION | ||
| ENV QE_VERSION ${QE_VERSION} | ||
|
|
||
| # Install aiida-quantumespresso from source code | ||
| COPY --from=src . /tmp/aiida-quantumespresso | ||
| RUN pip install /tmp/aiida-quantumespresso --no-cache-dir && \ | ||
| rm -rf /tmp/aiida-quantumespresso | ||
|
|
||
| # Install quantum espresso from conda (the latest version) | ||
| RUN mamba install -y -c conda-forge qe=${QE_VERSION} && \ | ||
| mamba clean --all -f -y && \ | ||
| fix-permissions "${CONDA_DIR}" && \ | ||
| fix-permissions "/home/${SYSTEM_USER}" | ||
|
|
||
| COPY scripts/60-pseudo-code-setup.sh /etc/init/run-before-daemon-start/ | ||
|
|
||
| # Static example files | ||
| RUN mkdir -p /opt/examples | ||
| COPY _static/ /opt/examples | ||
|
|
||
| USER ${SYSTEM_UID} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # generated using pymatgen | ||
| data_Si | ||
| _symmetry_space_group_name_H-M 'P 1' | ||
| _cell_length_a 3.86697465 | ||
| _cell_length_b 3.86697465 | ||
| _cell_length_c 3.86697465 | ||
| _cell_angle_alpha 60.00000000 | ||
| _cell_angle_beta 60.00000000 | ||
| _cell_angle_gamma 60.00000000 | ||
| _symmetry_Int_Tables_number 1 | ||
| _chemical_formula_structural Si | ||
| _chemical_formula_sum Si2 | ||
| _cell_volume 40.88829285 | ||
| _cell_formula_units_Z 2 | ||
| loop_ | ||
| _symmetry_equiv_pos_site_id | ||
| _symmetry_equiv_pos_as_xyz | ||
| 1 'x, y, z' | ||
| loop_ | ||
| _atom_site_type_symbol | ||
| _atom_site_label | ||
| _atom_site_symmetry_multiplicity | ||
| _atom_site_fract_x | ||
| _atom_site_fract_y | ||
| _atom_site_fract_z | ||
| _atom_site_occupancy | ||
| Si Si0 1 0.75000000 0.75000000 0.75000000 1 | ||
| Si Si1 1 0.50000000 0.50000000 0.50000000 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # docker-bake.hcl | ||
| variable "ORGANIZATION" { | ||
| default = "aiidateam" | ||
| } | ||
|
|
||
| variable "REGISTRY" { | ||
| default = "docker.io/" | ||
| } | ||
|
|
||
| variable "PLATFORMS" { | ||
| default = ["linux/amd64"] | ||
| } | ||
|
|
||
| variable "QE_VERSION" { | ||
| default = "7.2" | ||
| } | ||
|
|
||
| function "tags" { | ||
| params = [image] | ||
| result = [ | ||
| "${REGISTRY}${ORGANIZATION}/${image}:newly-baked" | ||
| ] | ||
| } | ||
|
|
||
| group "default" { | ||
| targets = ["aiida-quantumespresso"] | ||
| } | ||
|
|
||
| target "aiida-quantumespresso" { | ||
| tags = tags("aiida-quantumespresso") | ||
| contexts = { | ||
| src = ".." | ||
| } | ||
| platforms = "${PLATFORMS}" | ||
| args = { | ||
| "QE_VERSION" = "${QE_VERSION}" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| version: '3.4' | ||
|
|
||
| services: | ||
|
|
||
| aiida: | ||
| image: ${REGISTRY:-}${BASE_IMAGE:-aiidateam/aiida-quantumespresso}:${TAG:-latest} | ||
| environment: | ||
| TZ: Europe/Zurich | ||
| SETUP_DEFAULT_AIIDA_PROFILE: 'true' | ||
| #volumes: | ||
| # - aiida-home-folder:/home/aiida | ||
|
|
||
| volumes: | ||
| aiida-home-folder: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| docker | ||
| pre-commit | ||
| pytest | ||
| requests | ||
| tabulate | ||
| pytest-docker | ||
| docker-compose | ||
| pyyaml<=5.3.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/bin/bash | ||
|
|
||
| # If lock file exists, then we have already run this script | ||
| if [ -f ${HOME}/.lock_pseudo_code_setup ]; then | ||
| exit 0 | ||
| else | ||
| touch ${HOME}/.lock_pseudo_code_setup | ||
| fi | ||
|
|
||
| # Install pseudopotential libraries | ||
| aiida-pseudo install sssp --functional PBE -p efficiency | ||
| aiida-pseudo install sssp --functional PBE -p precision | ||
| aiida-pseudo install sssp --functional PBEsol -p efficiency | ||
| aiida-pseudo install sssp --functional PBEsol -p precision | ||
|
|
||
| # Loop over executables to set up | ||
| for code_name in pw ph; do | ||
| # Set up caching | ||
| verdi config set -a caching.enabled_for aiida.calculations:quantumespresso.${code_name} | ||
| # Set up code | ||
| verdi code create core.code.installed \ | ||
| --non-interactive \ | ||
| --label ${code_name}-${QE_VERSION} \ | ||
| --description "${code_name}.x code on localhost" \ | ||
| --default-calc-job-plugin quantumespresso.${code_name} \ | ||
| --computer localhost --prepend-text 'eval "$(conda shell.posix hook)"\nconda activate base\nexport OMP_NUM_THREADS=1' \ | ||
| --filepath-executable ${code_name}.x | ||
| done | ||
|
|
||
| # Import example structures | ||
| verdi data core.structure import ase /opt/examples/Si.cif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # pylint: disable=missing-docstring, redefined-outer-name | ||
| import json | ||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session') | ||
| def docker_compose_file(pytestconfig): # pylint: disable=unused-argument | ||
| return f'docker-compose.aiida-quantumespresso.yml' | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session') | ||
| def docker_compose(docker_services): | ||
| # pylint: disable=protected-access | ||
| return docker_services._docker_compose | ||
|
|
||
|
|
||
| def is_container_ready(dodkec_compose): | ||
| output = dodkec_compose.execute('exec -T aiida verdi status').decode().strip() | ||
|
unkcpz marked this conversation as resolved.
Outdated
|
||
| return 'Connected to RabbitMQ' in output and 'Daemon is running' in output | ||
|
|
||
|
|
||
| @pytest.fixture(scope='session', autouse=True) | ||
| def _docker_service_wait(docker_services): | ||
| """Container startup wait.""" | ||
| docker_compose = docker_services._docker_compose | ||
|
|
||
| docker_services.wait_until_responsive(timeout=120.0, pause=0.1, check=lambda: is_container_ready(docker_compose)) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def container_user(): | ||
| return 'aiida' | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def aiida_exec(docker_compose): | ||
|
|
||
| def execute(command, user=None, **kwargs): | ||
| if user: | ||
| command = f'exec -T --user={user} aiida {command}' | ||
| else: | ||
| command = f'exec -T aiida {command}' | ||
| return docker_compose.execute(command, **kwargs) | ||
|
|
||
| return execute | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def qe_version(aiida_exec): | ||
| info = json.loads(aiida_exec('mamba list -n base --json --full-name qe').decode())[0] | ||
| return info['version'] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sssp_version(aiida_exec): | ||
| output = aiida_exec('aiida-pseudo list').decode().strip() | ||
| return re.search(r'SSSP/(\d+\.\d+)/PBE/efficiency', output).group(1) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # pylint: disable=missing-docstring | ||
|
|
||
|
|
||
| def test_verdi_status(aiida_exec, container_user): | ||
| output = aiida_exec('verdi status', user=container_user).decode().strip() | ||
| assert 'Connected to RabbitMQ' in output | ||
| assert 'Daemon is running' in output | ||
|
|
||
| # check that we have suppressed the warnings | ||
| assert 'Warning' not in output | ||
|
|
||
|
|
||
| def test_computer_setup_success(aiida_exec, container_user): | ||
| output = aiida_exec('verdi computer test localhost', user=container_user).decode().strip() | ||
|
|
||
| assert 'Success' in output | ||
| assert 'Failed' not in output | ||
|
|
||
|
|
||
| def test_run_real_pw_computation(aiida_exec, container_user, qe_version, sssp_version): | ||
| import re | ||
|
|
||
| output = aiida_exec('verdi data core.structure import ase /opt/examples/Si.cif', | ||
| user=container_user).decode().strip() | ||
|
|
||
| # Find pk | ||
| pk = re.search(r'PK = (\d+)', output).group(1) | ||
|
|
||
| cmd = f'aiida-quantumespresso calculation launch pw -X pw-{qe_version}@localhost -F SSSP/{sssp_version}/PBE/efficiency -S {pk} -k 1 1 1' | ||
| output = aiida_exec(cmd, user=container_user).decode().strip() | ||
|
|
||
| assert 'terminated with state: finished [0]' in output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| --- | ||
| name: Build, test and push Docker Images | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths-ignore: | ||
| - "docs/**" | ||
| - "tests/**" | ||
| push: | ||
| branches: | ||
| - main | ||
| tags: | ||
| - "v*" | ||
| paths-ignore: | ||
| - "docs/**" | ||
| - "tests/**" | ||
| workflow_dispatch: | ||
|
|
||
| # https://docs.github.com/en/actions/using-jobs/using-concurrency | ||
| concurrency: | ||
| # only cancel in-progress jobs or runs for the current workflow - matches against branch & tags | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| amd64-build: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: bash | ||
| working-directory: .docker | ||
|
|
||
| steps: | ||
| - name: Checkout Repo ⚡️ | ||
| uses: actions/checkout@v3 | ||
| - name: Set Up Python 🐍 | ||
| uses: actions/setup-python@v4 | ||
| with: | ||
| python-version: 3.x | ||
|
|
||
| - name: Install Dev Dependencies 📦 | ||
| run: | | ||
| pip install --upgrade pip | ||
| pip install --upgrade -r requirements.txt | ||
|
|
||
| - name: Build image | ||
| run: docker buildx bake -f docker-bake.hcl --set *.platform=linux/amd64 --load | ||
| env: | ||
| # Full logs for CI build | ||
| BUILDKIT_PROGRESS: plain | ||
|
|
||
| - name: Run tests ✅ | ||
| run: TAG=newly-baked python -m pytest -s tests | ||
|
|
||
| - name: Docker meta 📝 | ||
| id: meta | ||
| uses: docker/metadata-action@v4 | ||
| with: | ||
| images: | | ||
| name=ghcr.io/aiidateam/aiida-quantumespresso | ||
| tags: | | ||
| type=edge,enable={{is_default_branch}} | ||
| type=sha,enable=${{ github.ref_type != 'tag' }} | ||
| type=ref,event=pr | ||
| type=match,pattern=v(\d+\.\d+.\d+),group=1 | ||
| type=raw,value={{tag}},enable=${{ startsWith(github.ref, 'refs/tags/v') }} | ||
|
|
||
| - name: Login to Container Registry 🔑 | ||
| uses: docker/login-action@v2 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Set tags for image and push 🏷️📤💾 | ||
| run: | | ||
| declare -a arr=(${{ steps.meta.outputs.tags }}) | ||
| for tag in "${arr[@]}"; do | ||
| docker tag aiidateam/aiida-quantumespresso:newly-baked ${tag} | ||
| docker push ${tag} | ||
| done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.