Skip to content

Commit 369ea5b

Browse files
authored
Refactor to run all calculations in separate directories (#220)
Summary ------- This refactor of the code contains several changes designed to make `koopmans` more robust and amenable to integration with `AiiDA`. Namely... - each calculation is run in a separate directory following a regular pattern - there are no shared `tmp` directories - file reading/writing/moving is done in an abstract way (see the new `FilePointer` class) so that it will be possible to "move" files on a remote server - the introduction of a `Process` class to make python operations on files etc. more standardized (and able to be executed remotely) These changes to treat calculations more like pure functions, and the introduction of a `Process` class also starts us in the direction of following [CWL](https://www.commonwl.org/)'s design pattern more closely. In the long term, we would like to be as close as possible to CWL (perhaps even with composite workflows being able to be written in CWL). Other changes --------------------- - the machine-learning workflows have been simplified - the output of `koopmans` markdown-compliant, making the output files easier to read for humans - `.kwf` files have been replaced by `.pkl` files (removing the responsibility of writing `Workflows` to file from custom code and using the widely-used `dill` package instead)
1 parent 1b656f9 commit 369ea5b

File tree

10,003 files changed

+876431
-4180161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

10,003 files changed

+876431
-4180161
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
uses: actions/checkout@v3
2222
with:
2323
submodules: true
24-
- name: Set up Python 3.8
24+
- name: Set up Python
2525
uses: actions/setup-python@v4
2626
with:
27-
python-version: 3.8
27+
python-version: '3.10'
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip

.github/workflows/tutorials.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ jobs:
2121
uses: actions/checkout@v3
2222
with:
2323
submodules: true
24-
- name: Set up Python 3.8
24+
- name: Set up Python
2525
uses: actions/setup-python@v4
2626
with:
27-
python-version: 3.8
27+
python-version: '3.10'
2828
- name: Install dependencies
2929
run: |
3030
python -m pip install --upgrade pip

.github/workflows/typechecking.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
uses: actions/checkout@v3
2020
with:
2121
submodules: false
22-
- name: Set up Python 3.8
22+
- name: Set up Python
2323
uses: actions/setup-python@v4
2424
with:
25-
python-version: 3.8
25+
python-version: '3.10'
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip

.github/workflows/update_citation.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ jobs:
1717
- name: Get branch name
1818
id: branch-name
1919
uses: tj-actions/branch-names@v8
20-
- name: Set up Python 3.8
20+
- name: Set up Python
2121
uses: actions/setup-python@v4
2222
with:
23-
python-version: 3.8
23+
python-version: '3.10'
2424
- name: Install dependencies
2525
run: |
2626
python -m pip install --upgrade pip
@@ -30,7 +30,9 @@ jobs:
3030
run: |
3131
python bin/update_cff.py
3232
- name: Validate CITATION.cff
33-
uses: dieghernan/cff-validator@main
33+
uses: dieghernan/cff-validator@v3
34+
with:
35+
install-r: true
3436
- name: Commit changes
3537
uses: test-room-7/action-update-file@v1
3638
with:

.gitignore

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@ coverage.xml
1717
.mypy_cache/
1818
TMP-CP/
1919
TMP/
20-
calc_alpha/
21-
calculate_eps/
22-
dft_bands/
23-
final/
24-
init/
25-
pdos/
26-
postproc/
27-
wannier/
28-
screening/
29-
hamiltonian/
20+
??-*/
3021
build/
3122
dist/

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v3.2.0
5+
rev: v4.6.0
66
hooks:
77
- id: trailing-whitespace
88
types: [file, python]
@@ -16,14 +16,14 @@ repos:
1616
- id: isort
1717

1818
- repo: https://github.com/pre-commit/mirrors-mypy
19-
rev: v0.961
19+
rev: v1.10.0
2020
hooks:
2121
- id: mypy
2222
files: src/koopmans/
2323
args: [--ignore-missing-imports]
2424

2525
- repo: https://github.com/pre-commit/mirrors-autopep8
26-
rev: v1.6.0
26+
rev: v2.0.4
2727
hooks:
2828
- id: autopep8
2929
args: [--max-line-length=120, -i]

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ preferred-citation:
7171
repository-code: https://github.com/epfl-theos/koopmans/
7272
title: koopmans
7373
type: software
74-
version: 1.0.1
74+
version: 1.1.0

bin/update_cff.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
2+
23
import yaml
4+
35
if sys.version_info >= (3, 8):
46
from importlib import metadata
57
else:

docs/_static/tutorials/fetch.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from shutil import copy
2+
3+
4+
def extract(filename_in, filename_out, start=0, end=None, heading=None):
5+
with open(filename_in) as fd:
6+
flines = fd.readlines()
7+
8+
# If heading is provided, find the line number of the heading
9+
if heading:
10+
for i, line in enumerate(flines):
11+
if heading in line:
12+
start = i
13+
break
14+
else:
15+
raise ValueError(f'Heading {heading} not found in file {filename_in}')
16+
17+
indent = len(flines[start]) - len(flines[start].lstrip())
18+
19+
for i in range(start + 1, len(flines)):
20+
line = flines[i]
21+
if not line.startswith(' ' * (indent + 1)):
22+
end = i
23+
break
24+
else:
25+
raise ValueError(f'Could not find the end of the {heading} block')
26+
27+
flines = flines[start:end]
28+
29+
# Find the shortest leading whitespace and strip this from all lines (as otherwise the markdown will be rendered as a code block)
30+
min_indent = min(len(line) - len(line.lstrip()) for line in flines if line.strip())
31+
flines = [line if line == "\n" else line[min_indent:]for line in flines]
32+
33+
# Manual conversion of double spaces to /
34+
flines = [line[:-2] + '\ \n' if (line.endswith(' \n')
35+
and not line.strip().startswith('-')) else line for line in flines]
36+
37+
with open(filename_out, 'w') as fd:
38+
fd.writelines(flines)
39+
40+
41+
if __name__ == '__main__':
42+
# Tutorial 1
43+
extract('../../../tutorials/tutorial_1/ozone.md', 'tutorial_1/md_excerpts/ozone_init.md', heading='Initialization')
44+
extract('../../../tutorials/tutorial_1/ozone.md', 'tutorial_1/md_excerpts/ozone_alpha.md', 24, 33)
45+
extract('../../../tutorials/tutorial_1/ozone.md', 'tutorial_1/md_excerpts/ozone_alpha_10.md', 45, 49)
46+
extract('../../../tutorials/tutorial_1/ozone.md', 'tutorial_1/md_excerpts/ozone_tables.md', 50, 62)
47+
extract('../../../tutorials/tutorial_1/ozone.md', 'tutorial_1/md_excerpts/ozone_final.md', -4)
48+
49+
# Tutorial 2
50+
extract('../../../tutorials/tutorial_2/si_wannierize.md', 'tutorial_2/md_excerpts/si_wannierize.md', start=18)
51+
extract('../../../tutorials/tutorial_2/si_ki.md', 'tutorial_2/md_excerpts/si_ki_wannierize.md', heading="Wannierize")
52+
extract('../../../tutorials/tutorial_2/si_ki.md', 'tutorial_2/md_excerpts/si_ki_fold.md', heading="Fold To Supercell")
53+
extract('../../../tutorials/tutorial_2/si_ki.md', 'tutorial_2/md_excerpts/si_ki_screening.md', 51, 61)
54+
extract('../../../tutorials/tutorial_2/si_ki.md',
55+
'tutorial_2/md_excerpts/si_ki_postproc.md', heading="Unfold And Interpolate")
56+
57+
# Tutorial 3
58+
extract('../../../tutorials/tutorial_3/01-ki/zno.md',
59+
'tutorial_3/md_excerpts/zno_wannierize_section.md', heading='Wannierize')
60+
extract('../../../tutorials/tutorial_3/01-ki/zno.md', 'tutorial_3/md_excerpts/zno_w2kc.md', -4, -3)
61+
extract('../../../tutorials/tutorial_3/01-ki/zno.md', 'tutorial_3/md_excerpts/zno_ham.md', -3, -2)
62+
copy('../../../tutorials/tutorial_3/01-ki/01-koopmans-dfpt/Koopmans_DFPT_bandstructure.png', 'tutorial_3/')
63+
64+
# Tutorial 4
65+
extract('../../../tutorials/tutorial_4/h2o_conv.md', 'tutorial_4/md_excerpts/h2o_conv.md', 18, 36)
66+
67+
# Tutorial 5
68+
extract('../../../tutorials/tutorial_5/01-train/h2o_train.md', 'tutorial_5/md_excerpts/train.md', 45, 92)
69+
extract('../../../tutorials/tutorial_5/02-predict/h2o_predict.md',
70+
'tutorial_5/md_excerpts/predict.md', heading='Calculate Screening Via DSCF')
71+
extract('../../../tutorials/tutorial_5/03-test/h2o_test.md', 'tutorial_5/md_excerpts/test.md', 45, 96)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- **Calculate Screening Via DSCF**
2+
- **Iteration 1**
3+
-`01-ki` completed
4+
- **Orbital 1**
5+
-`01-dft_n-1` completed
6+
- **Orbital 2**
7+
-`01-dft_n-1` completed
8+
- **Orbital 3**
9+
-`01-dft_n-1` completed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- **Orbital 10**
2+
-`01-dft_n+1_dummy` completed
3+
-`02-pz_print` completed
4+
-`03-dft_n+1` completed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
-`03-ki_final` completed
3+
4+
**Workflow complete** 🎉
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- **Initialization**
2+
-`01-dft_init_nspin1` completed
3+
-`02-dft_init_nspin2_dummy` completed
4+
-`03-convert_files_from_spin1to2` completed
5+
-`04-dft_init_nspin2` completed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
**α**
2+
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
3+
|---:|---------:|---------:|--------:|---------:|---------:|---------:|---------:|---------:|---------:|---------:|
4+
| 0 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 | 0.6 |
5+
| 1 | 0.655691 | 0.727571 | 0.78386 | 0.663859 | 0.772354 | 0.726848 | 0.729968 | 0.741899 | 0.779264 | 0.717389 |
6+
7+
**ΔE<sub>i</sub> - λ<sub>ii</sub> (eV)**
8+
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
9+
|---:|---------:|----------:|---------:|----------:|---------:|----------:|----------:|----------:|---------:|---------:|
10+
| 0 | -0.47736 | -0.920499 | -1.12409 | -0.452149 | -1.05055 | -0.830893 | -0.785139 | -0.888597 | -1.05016 | 0.711209 |
11+
12+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- **Fold To Supercell**
2+
-`01-convert_block_1_to_supercell` completed
3+
-`02-convert_block_2_to_supercell` completed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
- **Unfold And Interpolate**
2+
- **Wannierize**
3+
-`01-scf` completed
4+
-`02-nscf` completed
5+
- **Wannierize Block 1**
6+
-`01-wannier90_preproc` completed
7+
-`02-pw2wannier90` completed
8+
-`03-wannier90` completed
9+
- **Wannierize Block 2**
10+
-`01-wannier90_preproc` completed
11+
-`02-pw2wannier90` completed
12+
-`03-wannier90` completed
13+
-`05-bands` completed
14+
-`06-projwfc` completed
15+
-`02-unfold_and_interpolate_occ` completed
16+
-`03-unfold_and_interpolate_emp` completed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
- **Calculate Screening Via DSCF**
2+
- **Iteration 1**
3+
-`01-ki` completed
4+
- **Orbital 32**
5+
-`01-dft_n-1` completed
6+
- **Orbital 33**
7+
-`01-dft_n+1_dummy` completed
8+
-`02-pz_print` completed
9+
-`03-dft_n+1` completed
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
- **Wannierize**
2+
-`01-scf` completed
3+
-`02-nscf` completed
4+
- **Wannierize Block 1**
5+
-`01-wannier90_preproc` completed
6+
-`02-pw2wannier90` completed
7+
-`03-wannier90` completed
8+
- **Wannierize Block 2**
9+
-`01-wannier90_preproc` completed
10+
-`02-pw2wannier90` completed
11+
-`03-wannier90` completed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-`01-scf` completed
2+
-`02-nscf` completed
3+
- **Wannierize Block 1**
4+
-`01-wannier90_preproc` completed
5+
-`02-pw2wannier90` completed
6+
-`03-wannier90` completed
7+
- **Wannierize Block 2**
8+
-`01-wannier90_preproc` completed
9+
-`02-pw2wannier90` completed
10+
-`03-wannier90` completed
11+
-`05-bands` completed
12+
-`06-projwfc` completed
13+
14+
**Workflow complete** 🎉
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-`03-kc_ham` completed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-`02-wann2kc` completed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- **Wannierize**
2+
-`01-scf` completed
3+
-`02-nscf` completed
4+
- **Wannierize Block 1**
5+
-`01-wannier90_preproc` completed
6+
-`02-pw2wannier90` completed
7+
-`03-wannier90` completed
8+
- **Wannierize Block 2**
9+
-`01-wannier90_preproc` completed
10+
-`02-pw2wannier90` completed
11+
-`03-wannier90` completed
12+
- **Wannierize Block 3**
13+
-`01-wannier90_preproc` completed
14+
-`02-pw2wannier90` completed
15+
-`03-wannier90` completed
16+
- **Wannierize Block 4**
17+
-`01-wannier90_preproc` completed
18+
-`02-pw2wannier90` completed
19+
-`03-wannier90` completed
20+
- **Wannierize Block 5**
21+
-`01-wannier90_preproc` completed
22+
-`02-pw2wannier90` completed
23+
-`03-wannier90` completed
24+
-`08-merge_occ_wannier_hamiltonian` completed
25+
-`09-merge_occ_wannier_u` completed
26+
-`10-merge_occ_wannier_centers` completed
27+
-`11-bands` completed
28+
-`12-projwfc` completed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- **Singlepoint ecutwfc 20_0 celldm1 11_3**
2+
- **DFTCP**
3+
-`01-dft` completed
4+
- **Singlepoint ecutwfc 20_0 celldm1 12_3**
5+
- **DFTCP**
6+
-`01-dft` completed
7+
- **Singlepoint ecutwfc 20_0 celldm1 13_3**
8+
- **DFTCP**
9+
-`01-dft` completed
10+
- **Singlepoint ecutwfc 30_0 celldm1 11_3**
11+
- **DFTCP**
12+
-`01-dft` completed
13+
- **Singlepoint ecutwfc 30_0 celldm1 12_3**
14+
- **DFTCP**
15+
-`01-dft` completed
16+
- **Singlepoint ecutwfc 30_0 celldm1 13_3**
17+
- **DFTCP**
18+
-`01-dft` completed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- **Calculate Screening Via DSCF**
2+
- **Iteration 1**
3+
-`01-ki` completed
4+
- **Power Spectrum Decomposition**
5+
- **Convert Orbital Files To XML**
6+
-`01-bin2xml_total_density` completed
7+
-`02-bin2xml_occ_spin_0_orb_1_density` completed
8+
-`03-bin2xml_occ_spin_0_orb_2_density` completed
9+
-`04-bin2xml_occ_spin_0_orb_3_density` completed
10+
-`05-bin2xml_occ_spin_0_orb_4_density` completed
11+
-`06-bin2xml_emp_spin_0_orb_5_density` completed
12+
-`07-bin2xml_emp_spin_0_orb_6_density` completed
13+
-`02-extract_coefficients_from_xml` completed
14+
-`03-compute_power_spectrum_orbital_1` completed
15+
-`04-compute_power_spectrum_orbital_2` completed
16+
-`05-compute_power_spectrum_orbital_3` completed
17+
-`06-compute_power_spectrum_orbital_4` completed
18+
-`07-compute_power_spectrum_orbital_5` completed
19+
-`08-compute_power_spectrum_orbital_6` completed

0 commit comments

Comments
 (0)