Skip to content
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

Make sure that supercell_matrices of single-atom-displaced and rattled supercells are the same per default #258

Merged
merged 33 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3022c3b
increase M3GNET RMSE tolereance because of fluctuations
QuantumChemist Nov 14, 2024
a01c5a6
prettify GAP parameters representation and remove GAP related things …
QuantumChemist Nov 14, 2024
f3d35a0
rearrange file entires to make it look better, added user-defined for…
QuantumChemist Nov 15, 2024
1b7e6c0
fix unit test
QuantumChemist Nov 15, 2024
3754c8c
fix unit test
QuantumChemist Nov 15, 2024
d76dc84
small format fix
QuantumChemist Nov 15, 2024
4dc423e
fix unit test
QuantumChemist Nov 15, 2024
c02bfc3
removed a comment
QuantumChemist Nov 15, 2024
1b95862
decrease default max_length for rattled supercells
QuantumChemist Nov 15, 2024
8d0c3a8
Merge branch 'autoatml:main' into main
QuantumChemist Nov 18, 2024
0337f46
reducing max_length default a bit
QuantumChemist Nov 18, 2024
e51db69
Merge branch 'main' of github.com:QuantumChemist/autoplex
QuantumChemist Nov 18, 2024
eacd697
added missing doctsring
QuantumChemist Nov 19, 2024
c89312c
set max_length to 20
QuantumChemist Nov 19, 2024
a508a53
set max_length to 20
QuantumChemist Nov 19, 2024
b8ae70c
add fallback to single-atom-dsipl- supercells
QuantumChemist Nov 19, 2024
10ac1e5
minor changes in file format
QuantumChemist Nov 19, 2024
bc5ca78
supercell_matrix is only determined once by reduce_supercell_size_job
QuantumChemist Nov 19, 2024
cb4c995
filter out supercell_matrix key to prevent problems with mismacthing …
QuantumChemist Nov 19, 2024
9f02c13
filter out supercell_matrix mpid key as mpids are not used here
QuantumChemist Nov 19, 2024
d60d9fc
adjust job number and remove print
QuantumChemist Nov 19, 2024
75f2668
adjust defaults
QuantumChemist Nov 19, 2024
6da2b0f
fix unit tests
QuantumChemist Nov 20, 2024
14a9eb5
fix unit tests
QuantumChemist Nov 20, 2024
776384d
putting the phonon GAP defaults to SI settings
QuantumChemist Nov 20, 2024
6b3ceb2
fix unit test
QuantumChemist Nov 20, 2024
125eec1
fix unit test
QuantumChemist Nov 20, 2024
a0f3d83
fix unit test
QuantumChemist Nov 20, 2024
f35ef28
added user info about supercell settings
QuantumChemist Nov 20, 2024
bbae8f5
Merge branch 'autoatml:main' into main
QuantumChemist Nov 20, 2024
bc7dec9
addressing Yb's comments
QuantumChemist Nov 20, 2024
5b35adf
adjust unit test
QuantumChemist Nov 20, 2024
a84458d
fix unit test
QuantumChemist Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ def make(
dft_references=dft_references,
supercell_settings=self.supercell_settings,
displacement=displacement,
# TODO add a hyper parameter here for the benchmark
atomwise_regularization_parameter=atomwise_reg_parameter,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the docstrings of CompleteDFTvsMLBenchmarkWorkflow, should we unify the formatting since some start with lowercase letters while others start with uppercase letters?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should indeed agree on a convention here. This is something that I can fix in the documentation pull-request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

soap_dict=soap_dict,
**self.benchmark_kwargs,
Expand Down
22 changes: 16 additions & 6 deletions src/autoplex/benchmark/phonons/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ def write_benchmark_metrics(
encoding="utf-8",
) as file:
file.write(
"%-11s%-11s%-12s%-18s%-12s%-55s%-16s%-16s%-14s"
"%-11s%-11s%-12s%-18s%-12s%-16s%-16s%-16s%-18s"
% (
"Potential",
"Structure",
"MPID",
"Displacement (Å)",
"RMSE (THz)",
"Hyperparameters (atom-wise f, n_sparse, SOAP delta)",
"Database type",
"imagmodes(pot)",
"imagmodes(dft)",
"Database type",
"(Hyper-)Parameters",
)
)

Expand All @@ -59,15 +59,25 @@ def write_benchmark_metrics(
encoding="utf-8",
) as file:
# Build the SOAP dictionary or suffix value
soap_params = {
soap_params = { # (atom-wise f, n_sparse, SOAP delta)
f"f={metric['atomwise_regularization_parameter']}": metric["soap_dict"]
}

if metric["ml_model"] == "GAP":
key = next(iter(soap_params.keys()))
value = next(iter(soap_params.values()))
pretty_hyper_params = f"atom-wise {key}: n_sparse = {value['n_sparse']}, SOAP delta = {value['delta']}"
else:
pretty_hyper_params = "user defined"

if not metric["suffix"]:
metric["suffix"] = "full"

file.write(
f"\n{metric['ml_model']:<11}{structure_composition:<11}{metric['mp_id']:<12}"
f"{metric['displacement']:<18.2f}{metric['benchmark_phonon_rmse']:<12.5f}"
f"{soap_params!s:<55}{metric['suffix']!s:<16}{metric['ml_imaginary_modes']!s:<16}"
f"{metric['dft_imaginary_modes']!s:<5}"
f"{metric['ml_imaginary_modes']!s:<16}{metric['dft_imaginary_modes']!s:<16}"
f"{metric['suffix']!s:<16}{pretty_hyper_params!s:<50}"
)

return Response(output=metrics)
6 changes: 3 additions & 3 deletions tests/auto/test_auto_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def test_complete_dft_vs_ml_benchmark_workflow_gap(

# check if soap_default_dict is correctly constructed from
# n_sparse and delta values in mlip_phonon_default json file
expected_soap_dict = "{'f=0.1': {'n_sparse': 6000, 'delta': 0.5}}"
expected_soap_dict = "atom-wise f=0.1: n_sparse = 6000, SOAP delta = 0.5"
results_files = glob.glob('job*/results_LiCl.txt')

for file_path in results_files:
Expand Down Expand Up @@ -584,7 +584,7 @@ def test_complete_dft_vs_ml_benchmark_workflow_m3gnet(
assert complete_workflow_m3gnet.jobs[4].name == "complete_benchmark_mp-22905"
assert responses[complete_workflow_m3gnet.jobs[-1].output.uuid][1].output[0][0][
"benchmark_phonon_rmse"] == pytest.approx(
5.2622804443539355, abs=1.0 # bad fit data
5.2622804443539355, abs=3.0 # bad fit data, fluctuates between 4 and 7
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this slight fluctuation result from the fitting, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we would need more fit data, but then the unit tests would also take longer.


Expand Down Expand Up @@ -996,7 +996,7 @@ def test_complete_dft_vs_ml_benchmark_workflow_with_sigma_regularization(
assert reg_specific_file_exists

# check if soap_default_dict is correctly constructed from n_sparse and delta values in user fit parameter input
expected_soap_dict = "{'f=0.1': {'delta': 3.0, 'n_sparse': 8000}}"
expected_soap_dict = "atom-wise f=0.1: n_sparse = 8000, SOAP delta = 3.0"

results_files = glob.glob('job*/test_results_LiCl.txt')
for file_path in results_files:
Expand Down
19 changes: 10 additions & 9 deletions tests/benchmark/test_benchmark_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def test_compute_bandstructure_benchmark_metrics_dummy(test_dir, clean_dir):
def test_compute_bandstructure_benchmark_metrics(test_dir, clean_dir):
import os
from pathlib import Path
from jobflow import run_locally

# test wih two different band-structures
dft_bs_file_path = test_dir / "benchmark" / "DFT_phonon_band_structure.yaml"
Expand Down Expand Up @@ -104,12 +103,14 @@ def test_write_benchmark_metrics(test_dir, clean_dir):
]

soap_dict = [ # unit tests for checking correct default soap_dict in tests/auto/test_auto_flows.py
None,
None,
None,
None,
{'n_sparse': 3000, 'delta': 1.0},
{'n_sparse': 4000, 'delta': 1.0},
{'n_sparse': 5000, 'delta': 1.0},
{'n_sparse': 6000, 'delta': 1.0},
{'n_sparse': 6000, 'delta': 1.0},
{'n_sparse': 3000, 'delta': 1.0},
{'n_sparse': 5000, 'delta': 1.0},
{'n_sparse': 6000, 'delta': 1.0},
]

suffixes = ["", '_wo_sigma', '_phonon', '_rand_struc']
Expand All @@ -118,8 +119,8 @@ def test_write_benchmark_metrics(test_dir, clean_dir):

suffix_index = 0

for i, metric_group in enumerate(metric_vals):
for metric in metric_group:
for metric_group in metric_vals:
for metric, soap in zip(metric_group, soap_dict):
fused_dict = {
'benchmark_phonon_rmse': metric['benchmark_phonon_rmse'],
'dft_imaginary_modes': metric['dft_imaginary_modes'],
Expand All @@ -129,7 +130,7 @@ def test_write_benchmark_metrics(test_dir, clean_dir):
'structure': structure,
'displacement': 0.01,
'atomwise_regularization_parameter': 0.1,
'soap_dict': soap_dict[i],
'soap_dict': soap,
'suffix': suffixes[suffix_index]
}
metrics.append(fused_dict)
Expand All @@ -140,7 +141,7 @@ def test_write_benchmark_metrics(test_dir, clean_dir):
metrics=[metrics],
)

_ = run_locally(write_metrics_job, create_folders=False, ensure_success=True)
run_locally(write_metrics_job, create_folders=False, ensure_success=True)

# get list of generated txt file
path_to_ref_txt_file = test_dir / "benchmark" / "results_LiCl_ref.txt"
Expand Down
18 changes: 9 additions & 9 deletions tests/test_data/benchmark/results_LiCl_ref.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Potential Structure MPID Displacement (Å) RMSE (THz) Hyperparameters (atom-wise f, n_sparse, SOAP delta) Database type imagmodes(pot) imagmodes(dft)
GAP LiCl mp-22905 0.01 0.87425 {'f=0.1': None} False False
GAP LiCl mp-22905 0.01 0.63839 {'f=0.1': None} False False
GAP LiCl mp-22905 0.01 0.55506 {'f=0.1': None} _wo_sigma False False
GAP LiCl mp-22905 0.01 0.43216 {'f=0.1': None} _phonon False False
GAP LiCl mp-22905 0.01 0.54584 {'f=0.1': None} _rand_struc False False
GAP LiCl mp-22905 0.01 0.43216 {'f=0.1': {'n_sparse': 3000, 'delta': 1.0}} _rand_struc False False
GAP LiCl mp-22905 0.01 0.36478 {'f=0.1': {'n_sparse': 5000, 'delta': 1.0}} _rand_struc False False
GAP LiCl mp-22905 0.01 0.38100 {'f=0.1': {'n_sparse': 5000, 'delta': 1.0}} _rand_struc False False
Potential Structure MPID Displacement (Å) RMSE (THz) imagmodes(pot) imagmodes(dft) Database type (Hyper-)Parameters
GAP LiCl mp-22905 0.01 0.87425 False False full atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.63839 False False full atom-wise f=0.1: n_sparse = 4000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.55506 False False _wo_sigma atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.43216 False False _phonon atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.54584 False False _rand_struc atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.43216 False False _rand_struc atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.36478 False False _rand_struc atom-wise f=0.1: n_sparse = 3000, SOAP delta = 1.0
GAP LiCl mp-22905 0.01 0.38100 False False _rand_struc atom-wise f=0.1: n_sparse = 4000, SOAP delta = 1.0
Loading