From 0252fc5b32e6fb8d91eeb9a27087be3893fc7fe7 Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 25 Jan 2024 16:13:36 -0500 Subject: [PATCH 1/2] Prevent overwriting the "results" variable when parallelization is off. This commit fixes the issue reported by @lizziel in #285. The "results" variable was being overwritten instead of appended to when plots are generated sequentially (i.e. with "n_cores: 1" in the YAML input). gcpy/benchmark/modules/run_1yr_*_fullchem.py gcpy/benchmark_funcs.py gcpy/plot/compare_*.py - For the case when parallelization is off: 1. Declare "results" as an empty list 2. Append the output of the routine being called into "results" This will prevent a dictionary key error as described in #285. Signed-off-by: Bob Yantosca --- CHANGELOG.md | 3 +++ .../modules/run_1yr_fullchem_benchmark.py | 18 ++++++++++++------ gcpy/benchmark/modules/run_1yr_tt_benchmark.py | 9 ++++++--- gcpy/benchmark_funcs.py | 16 ++++++++++++---- gcpy/plot/compare_single_level.py | 3 ++- gcpy/plot/compare_zonal_mean.py | 3 ++- 6 files changed, 37 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c68b041..53d545e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Example script `create_test_plot.py`, which can be used to check that GCPy has been installed properly - GitHub action `build-gcpy-environment` which tests installation of the mamba environment specified in in `docs/source/environment.yml` +### Fixed +- Prevent overwriting of the `results` variable when parallel plotting is deactivated (`n_cores: 1`) + ## [1.4.1] - 2023-12-08 ### Fixed - Now use the proper default value for the `--weightsdir` argument to `gcpy/file_regrid.py` diff --git a/gcpy/benchmark/modules/run_1yr_fullchem_benchmark.py b/gcpy/benchmark/modules/run_1yr_fullchem_benchmark.py index 7321c50a..3582bfba 100644 --- a/gcpy/benchmark/modules/run_1yr_fullchem_benchmark.py +++ b/gcpy/benchmark/modules/run_1yr_fullchem_benchmark.py @@ -694,8 +694,9 @@ def gcc_vs_gcc_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gcc_vs_gcc_mass_table(mon) + results.append(gcc_vs_gcc_mass_table(mon)) # ================================================================== # GCC vs GCC operations budgets tables @@ -741,8 +742,9 @@ def gcc_vs_gcc_ops_budg(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gcc_vs_gcc_ops_budg(mon) + results.append(gcc_vs_gcc_ops_budg(mon)) # ================================================================== # GCC vs GCC aerosols budgets/burdens tables @@ -1255,8 +1257,9 @@ def gchp_vs_gcc_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gcc_mass_table(mon) + results.append(gchp_vs_gcc_mass_table(mon)) # ================================================================== # GCHP vs GCC operations budgets tables @@ -1311,8 +1314,9 @@ def gchp_vs_gcc_ops_budg(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gcc_ops_budg(mon) + results.append(gchp_vs_gcc_ops_budg(mon)) # ================================================================== # GCHP vs GCC aerosol budgets and burdens tables @@ -1863,8 +1867,9 @@ def gchp_vs_gchp_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gchp_mass_table(mon) + results.append(gchp_vs_gchp_mass_table(mon)) # ================================================================== # GCHP vs GCHP operations budgets tables @@ -1921,8 +1926,9 @@ def gchp_vs_gchp_ops_budg(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gchp_ops_budg(mon) + results.append(gchp_vs_gchp_ops_budg(mon)) # ================================================================== # GCHP vs GCHP aerosol budgets and burdens tables diff --git a/gcpy/benchmark/modules/run_1yr_tt_benchmark.py b/gcpy/benchmark/modules/run_1yr_tt_benchmark.py index 878dad76..7d10d149 100644 --- a/gcpy/benchmark/modules/run_1yr_tt_benchmark.py +++ b/gcpy/benchmark/modules/run_1yr_tt_benchmark.py @@ -540,8 +540,9 @@ def gcc_vs_gcc_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gcc_vs_gcc_mass_table(mon) + results.append(gcc_vs_gcc_mass_table(mon)) # ================================================================== # GCC vs GCC operations budgets tables @@ -837,8 +838,9 @@ def gchp_vs_gcc_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gcc_mass_table(mon) + results.append(gchp_vs_gcc_mass_table(mon)) # ================================================================== # GCHP vs GCC operations budgets tables @@ -1149,8 +1151,9 @@ def gchp_vs_gchp_mass_table(mon): for mon in range(bmk_n_months) ) else: + results = [] for mon in range(bmk_n_months): - results = gchp_vs_gchp_mass_table(mon) + results.append(gchp_vs_gchp_mass_table(mon)) # ================================================================== # GCHP vs GCHP operations budgets tables diff --git a/gcpy/benchmark_funcs.py b/gcpy/benchmark_funcs.py index e6fe88c6..36ea5360 100644 --- a/gcpy/benchmark_funcs.py +++ b/gcpy/benchmark_funcs.py @@ -1503,10 +1503,13 @@ def createplots(filecat): for _, filecat in enumerate(catdict) ) else: + results = [] for _, filecat in enumerate(catdict): - results = createplots(filecat) + results.append(createplots(filecat)) # -------------------------------------------- - + print(results) + quit() + dict_sfc = {list(result.keys())[0]: result[list( result.keys())[0]]['sfc'] for result in results} dict_500 = {list(result.keys())[0]: result[list( @@ -1514,6 +1517,9 @@ def createplots(filecat): dict_zm = {list(result.keys())[0]: result[list( result.keys())[0]]['zm'] for result in results} + print("stop here") + quit() + # ============================================================== # Write the list of species having significant differences, # which we need to fill out the benchmark approval forms. @@ -1868,8 +1874,9 @@ def createfile_hco_cat(c): for c in emis_cats ) else: + results = [] for c in emis_cats: - results = createfile_hco_cat(c) + results.append(createfile_hco_cat(c)) # --------------------------------------- dict_emis = {list(result.keys())[0]: result[list(result.keys())[0]] @@ -1981,8 +1988,9 @@ def createfile_bench_cat(filecat): for _, filecat in enumerate(catdict) ) else: + results = [] for _, filecat in enumerate(catdict): - results = createfile_bench_cat(filecat) + results.append(createfile_bench_cat(filecat)) #------------------------------------------------ allcatspc = [spc for result in results for spc in result] diff --git a/gcpy/plot/compare_single_level.py b/gcpy/plot/compare_single_level.py index 5a9db5ef..faf82650 100644 --- a/gcpy/plot/compare_single_level.py +++ b/gcpy/plot/compare_single_level.py @@ -1152,8 +1152,9 @@ def get_extent_for_colors(dset, minlon, maxlon, minlat, maxlat): for i in range(n_var) ) else: + results = [] for i in range(n_var): - results = createfig(i, temp_dir) + results.append(createfig(i, temp_dir)) # --------------------------------------- # update sig diffs after parallel calls diff --git a/gcpy/plot/compare_zonal_mean.py b/gcpy/plot/compare_zonal_mean.py index 3999bb3e..f7b41577 100644 --- a/gcpy/plot/compare_zonal_mean.py +++ b/gcpy/plot/compare_zonal_mean.py @@ -1046,8 +1046,9 @@ def createfig(ivar, temp_dir=''): for i in range(n_var) ) else: + results = [] for i in range(n_var): - results = createfig(i, temp_dir) + results.append(createfig(i, temp_dir)) # --------------------------------------- # update sig diffs after parallel calls From 7a2c321a87f261f80e5b4fa0fada956734a8a483 Mon Sep 17 00:00:00 2001 From: Bob Yantosca Date: Thu, 25 Jan 2024 16:18:06 -0500 Subject: [PATCH 2/2] Remove leftover debug output gcpy/benchmark_funcs.py - Removed a leftover print statement and quit() statement from debugging Signed-off-by: Bob Yantosca --- gcpy/benchmark_funcs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/gcpy/benchmark_funcs.py b/gcpy/benchmark_funcs.py index 36ea5360..18f7ffd3 100644 --- a/gcpy/benchmark_funcs.py +++ b/gcpy/benchmark_funcs.py @@ -1507,8 +1507,6 @@ def createplots(filecat): for _, filecat in enumerate(catdict): results.append(createplots(filecat)) # -------------------------------------------- - print(results) - quit() dict_sfc = {list(result.keys())[0]: result[list( result.keys())[0]]['sfc'] for result in results}