From a3c35ac382ebb768ebe494d90190aaea54abcf37 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Thu, 21 Mar 2024 10:02:00 +0000 Subject: [PATCH] regression test for the parameters generated by the app The previous test used the final builder generated by the workchain, which is like an end-to-end test. However, the builder depends on the version of the aiida-quantumespresso, which we want to avoid for the moment. In this PR, we only test the ui_parameters generated by the app. This ui_parameter is the most important parameter, and it contains all the information on the jobs. We can use it to recreate the whole qeapp instance. The test here guarantees that the ui_parameters are the same as the reference data. --- tests/test_submit_qe_workchain.py | 45 +++- .../test_create_builder_default.yml | 203 +++--------------- 2 files changed, 70 insertions(+), 178 deletions(-) diff --git a/tests/test_submit_qe_workchain.py b/tests/test_submit_qe_workchain.py index 5bde299c2..51d3a4a1a 100644 --- a/tests/test_submit_qe_workchain.py +++ b/tests/test_submit_qe_workchain.py @@ -14,13 +14,12 @@ def test_create_builder_default( app = submit_app_generator(properties=["bands", "pdos"]) submit_step = app.submit_step - builder = submit_step._create_builder() - - # check and validate the builder - got = builder_to_readable_dict(builder) - - # regression test - data_regression.check(got) + submit_step._create_builder() + # since uuid is specific to each run, we remove it from the output + ui_parameters = remove_uuid_fields(submit_step.ui_parameters) + # regression test for the parameters generated by the app + # this parameters are passed to the workchain + data_regression.check(ui_parameters) @pytest.mark.usefixtures("sssp") @@ -121,3 +120,35 @@ def builder_to_readable_dict(builder): readable_dict[k] = v return readable_dict + + +def remove_uuid_fields(data): + """ + Recursively remove fields that contain UUID values from a dictionary. + + :param data: The dictionary to process. + :return: The dictionary with UUID fields removed. + """ + import re + + # Define a UUID pattern + uuid_pattern = re.compile( + r"[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}", re.I + ) + + if isinstance(data, dict): + new_dict = {} + for key, value in data.items(): + # If the value matches the UUID pattern, skip adding it to the new dictionary + if isinstance(value, str) and uuid_pattern.match(value): + continue + # Otherwise, process the value recursively and add it to the new dictionary + else: + new_dict[key] = remove_uuid_fields(value) + return new_dict + elif isinstance(data, list): + # Process each item in the list recursively + return [remove_uuid_fields(item) for item in data] + else: + # Return the value unchanged if it's not a dictionary or list + return data diff --git a/tests/test_submit_qe_workchain/test_create_builder_default.yml b/tests/test_submit_qe_workchain/test_create_builder_default.yml index 868198e3b..2f9f23575 100644 --- a/tests/test_submit_qe_workchain/test_create_builder_default.yml +++ b/tests/test_submit_qe_workchain/test_create_builder_default.yml @@ -1,173 +1,34 @@ +advanced: + clean_workdir: false + initial_magnetic_moments: null + kpoints_distance: 0.12 + pseudo_family: SSSP/1.3/PBEsol/efficiency + pw: + parameters: + SYSTEM: + degauss: 0.015 + ecutrho: 240.0 + ecutwfc: 30.0 + smearing: methfessel-paxton + tot_charge: 0.0 + vdw_corr: none + pseudos: {} bands: - bands: - pw: - parallelization: - npool: 1 - parameters: - CONTROL: - calculation: bands - etot_conv_thr: 2.0e-05 - forc_conv_thr: 0.0001 - restart_mode: from_scratch - tprnfor: true - tstress: true - ELECTRONS: - conv_thr: 4.0e-10 - diago_full_acc: true - diagonalization: paro - electron_maxstep: 80 - mixing_beta: 0.4 - startingpot: file - SYSTEM: - degauss: 0.01 - ecutrho: 240.0 - ecutwfc: 30.0 - nosym: false - occupations: smearing - smearing: cold - tot_charge: 0.0 - vdw_corr: none - pseudos: - Si: Si.upf - bands_kpoints_distance: 0.025 - nbands_factor: 3.0 - scf: - kpoints_distance: 0.12 - kpoints_force_parity: false - pw: - parallelization: - npool: 1 - parameters: - CONTROL: - calculation: scf - etot_conv_thr: 2.0e-05 - forc_conv_thr: 0.0001 - tprnfor: true - tstress: true - ELECTRONS: - conv_thr: 4.0e-10 - electron_maxstep: 80 - mixing_beta: 0.4 - SYSTEM: - degauss: 0.015 - ecutrho: 240.0 - ecutwfc: 30.0 - nosym: false - occupations: smearing - smearing: methfessel-paxton - tot_charge: 0.0 - vdw_corr: none - pseudos: - Si: Si.upf -clean_workdir: false + kpath_2d: hexagonal +codes: + xspectra: null pdos: - dos: - parameters: - DOS: - DeltaE: 0.02 - nscf: - kpoints_distance: 0.1 - kpoints_force_parity: false - pw: - parallelization: - npool: 1 - parameters: - CONTROL: - calculation: nscf - etot_conv_thr: 2.0e-05 - forc_conv_thr: 0.0001 - restart_mode: from_scratch - tprnfor: true - tstress: true - ELECTRONS: - conv_thr: 4.0e-10 - electron_maxstep: 80 - mixing_beta: 0.4 - SYSTEM: - ecutrho: 240.0 - ecutwfc: 30.0 - nosym: true - occupations: tetrahedra - tot_charge: 0.0 - vdw_corr: none - pseudos: - Si: Si.upf - projwfc: - parameters: - PROJWFC: - DeltaE: 0.02 - settings: - cmdline: - - -nk - - '1' - scf: - kpoints_distance: 0.12 - kpoints_force_parity: false - pw: - parallelization: - npool: 1 - parameters: - CONTROL: - calculation: scf - etot_conv_thr: 2.0e-05 - forc_conv_thr: 0.0001 - restart_mode: from_scratch - tprnfor: true - tstress: true - ELECTRONS: - conv_thr: 4.0e-10 - electron_maxstep: 80 - mixing_beta: 0.4 - SYSTEM: - degauss: 0.015 - ecutrho: 240.0 - ecutwfc: 30.0 - nosym: false - occupations: smearing - smearing: methfessel-paxton - tot_charge: 0.0 - vdw_corr: none - pseudos: - Si: Si.upf -properties: -- bands -- pdos -- relax -relax: - base: - kpoints_distance: 0.12 - kpoints_force_parity: false - pw: - parallelization: - npool: 1 - parameters: - CELL: - cell_dofree: all - press_conv_thr: 0.5 - CONTROL: - calculation: vc-relax - etot_conv_thr: 2.0e-05 - forc_conv_thr: 0.0001 - tprnfor: true - tstress: true - ELECTRONS: - conv_thr: 4.0e-10 - electron_maxstep: 80 - mixing_beta: 0.4 - SYSTEM: - degauss: 0.015 - ecutrho: 240.0 - ecutwfc: 30.0 - nosym: false - occupations: smearing - smearing: methfessel-paxton - tot_charge: 0.0 - vdw_corr: none - pseudos: - Si: Si.upf - base_final_scf: - pw: - pseudos: {} - max_meta_convergence_iterations: 5 - meta_convergence: true - volume_convergence: 0.02 + nscf_kpoints_distance: 0.1 +resources: + npools: 1 + num_machines: 1 + num_mpiprocs_per_machine: 2 +workchain: + electronic_type: metal + properties: + - bands + - pdos + - relax + protocol: moderate + relax_type: positions_cell + spin_type: none