From 22a27280fe8c313b1bce5a463d26b407e7b65040 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:30:24 +0000 Subject: [PATCH 1/3] Initial plan From 7078e96b2fb962c06337d10d81ce638ee278825d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:32:34 +0000 Subject: [PATCH 2/3] Add docstrings to helper routines Co-authored-by: fassaad <29425753+fassaad@users.noreply.github.com> --- Analysis/convert_bins.py | 1 + Analysis/fix-latt.py | 3 +++ Prog/parse_ham_mod.py | 5 +++++ testsuite/compare_dirs.py | 3 +++ testsuite/test_branch_generate_config.py | 1 + testsuite/test_vs_ed/analysis.py | 1 + 6 files changed, 14 insertions(+) diff --git a/Analysis/convert_bins.py b/Analysis/convert_bins.py index 4032cccd8..7ab627d47 100755 --- a/Analysis/convert_bins.py +++ b/Analysis/convert_bins.py @@ -62,6 +62,7 @@ def copy_parameters(sim_dir, hamiltonian_file): def _get_arg_parser(): + """Build and return the argument parser for the CLI.""" parser = ArgumentParser( description='Convert plain text bins and parameters to HDF5 file. ' 'Moves plain text bin and associated _info files to "old_bins" ' diff --git a/Analysis/fix-latt.py b/Analysis/fix-latt.py index b78084a64..9eccf79d0 100755 --- a/Analysis/fix-latt.py +++ b/Analysis/fix-latt.py @@ -13,6 +13,7 @@ def _get_arg_parser(): + """Create the CLI argument parser for lattice fix utility.""" parser = ArgumentParser( description='Fix a mix-up between `Norb` and `N_coord` in lattice.', ) @@ -23,6 +24,7 @@ def _get_arg_parser(): return parser def _fix_latt(latt_grp): + """Correct swapped Norb/N_coord attributes inside a lattice group.""" orbital_positions = [] i = 0 while True: @@ -46,6 +48,7 @@ def _fix_latt(latt_grp): def _fix_loc(hdf5_loc): + """Recursively traverse an HDF5 hierarchy and fix lattice groups.""" for i in hdf5_loc: if isinstance(i, str): print(i) diff --git a/Prog/parse_ham_mod.py b/Prog/parse_ham_mod.py index c8c8988b6..a7c564a6d 100644 --- a/Prog/parse_ham_mod.py +++ b/Prog/parse_ham_mod.py @@ -103,10 +103,12 @@ def parse_line(line): def _max_len(dictionary): + """Return length of the longest key in a mapping.""" return max(len(i) for i in dictionary) def _dtype_name(parameter): + """Return Fortran dtype name corresponding to a Python value.""" if isinstance(parameter, list): return _dtype_name(parameter[0]) if isinstance(parameter, bool): @@ -334,6 +336,7 @@ def create_read_write_par(filename, parameters, ham_name): def _to_value(dtype, value): + """Convert a string representation to the corresponding Python value.""" if 'real' in dtype: return float(value.replace('d', 'e').replace('D', 'e')) # if 'complex' in dtype: @@ -359,6 +362,7 @@ def _to_value(dtype, value): def _get_mpi_dtype(parameter): + """Return the MPI datatype constant matching the parameter type.""" if isinstance(parameter, list): return _get_mpi_dtype(parameter[0]) if isinstance(parameter, bool): @@ -375,6 +379,7 @@ def _get_mpi_dtype(parameter): def _get_mpi_len(parameter): + """Return the number of MPI elements that need to be broadcast.""" if isinstance(parameter, list): return _get_mpi_len(parameter[0]) * len(parameter) if isinstance(parameter, (bool, float, complex, int)): diff --git a/testsuite/compare_dirs.py b/testsuite/compare_dirs.py index 0a0bc2d05..4d1953bdf 100755 --- a/testsuite/compare_dirs.py +++ b/testsuite/compare_dirs.py @@ -15,6 +15,7 @@ from py_alf.utils import find_sim_dirs def analyze_and_load(root_dir): + """Run analysis for all simulations under root_dir and load results.""" dirs = find_sim_dirs(root_dir) for dir in dirs: analysis(dir) @@ -22,6 +23,7 @@ def analyze_and_load(root_dir): def compare_dirs(dir_R, dir_T, resultsfile): + """Compare observables from two simulation directories and write a report.""" obs_R = analyze_and_load(dir_R) obs_T = analyze_and_load(dir_T) @@ -42,6 +44,7 @@ def compare_dirs(dir_R, dir_T, resultsfile): def _get_arg_parser(): + """Return an argument parser for comparing two simulation directories.""" parser = argparse.ArgumentParser( description='Testing two directories of ALF simulations' 'for identical results.') diff --git a/testsuite/test_branch_generate_config.py b/testsuite/test_branch_generate_config.py index 69f0f2335..2d1e415fb 100755 --- a/testsuite/test_branch_generate_config.py +++ b/testsuite/test_branch_generate_config.py @@ -140,6 +140,7 @@ def prep_runs(test_specs, env_name, env_spec): + """Populate pipeline_config with compile/run jobs for one environment.""" jobname_compile = f'{env_name}_compile' pipeline_config[jobname_compile] = { **{'extends': '.compile_template'}, diff --git a/testsuite/test_vs_ed/analysis.py b/testsuite/test_vs_ed/analysis.py index da21d3b98..4dcfa1798 100755 --- a/testsuite/test_vs_ed/analysis.py +++ b/testsuite/test_vs_ed/analysis.py @@ -20,6 +20,7 @@ res.to_json("results.json") def func(x, y0, a): + """Quadratic function used to fit energy extrapolation.""" return y0 + a*x**2 x = res.dtau y = res.Ener_scal0 From 14abdff06f7be4c1540134cc0775f1f9ef0038cb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 16:34:17 +0000 Subject: [PATCH 3/3] Refine helper naming clarity Co-authored-by: fassaad <29425753+fassaad@users.noreply.github.com> --- Analysis/fix-latt.py | 12 ++++++------ Prog/parse_ham_mod.py | 2 +- testsuite/compare_dirs.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Analysis/fix-latt.py b/Analysis/fix-latt.py index 9eccf79d0..1c19fd510 100755 --- a/Analysis/fix-latt.py +++ b/Analysis/fix-latt.py @@ -49,13 +49,13 @@ def _fix_latt(latt_grp): def _fix_loc(hdf5_loc): """Recursively traverse an HDF5 hierarchy and fix lattice groups.""" - for i in hdf5_loc: - if isinstance(i, str): - print(i) - if i == 'lattice': - _fix_latt(hdf5_loc[i]) + for item in hdf5_loc: + if isinstance(item, str): + print(item) + if item == 'lattice': + _fix_latt(hdf5_loc[item]) else: - _fix_loc(hdf5_loc[i]) + _fix_loc(hdf5_loc[item]) if __name__ == '__main__': diff --git a/Prog/parse_ham_mod.py b/Prog/parse_ham_mod.py index a7c564a6d..708a85a57 100644 --- a/Prog/parse_ham_mod.py +++ b/Prog/parse_ham_mod.py @@ -104,7 +104,7 @@ def parse_line(line): def _max_len(dictionary): """Return length of the longest key in a mapping.""" - return max(len(i) for i in dictionary) + return max(len(key) for key in dictionary) def _dtype_name(parameter): diff --git a/testsuite/compare_dirs.py b/testsuite/compare_dirs.py index 4d1953bdf..6cd436b00 100755 --- a/testsuite/compare_dirs.py +++ b/testsuite/compare_dirs.py @@ -17,8 +17,8 @@ def analyze_and_load(root_dir): """Run analysis for all simulations under root_dir and load results.""" dirs = find_sim_dirs(root_dir) - for dir in dirs: - analysis(dir) + for sim_dir in dirs: + analysis(sim_dir) return load_res(dirs)