Copied config file may diverge from results
Closed this issue · 7 comments
Checklist
- I am using the current
master
branch or the latest release. Please indicate. - I am running on an up-to-date
pypsa-eur
environment. Update viaconda env update -f envs/environment.yaml
.
Describe the Bug
I solved a model, changed the config, resolved the model. Then I look at results/.../config.yaml
and find that it's the file from the first run, not from the second. Thus, the stored results have diverged from the stored config. The reason is that snakemake does not execute this rule again:
rule copy_config:
params:
RDIR=RDIR,
output:
RESULTS + "config.yaml",
threads: 1
resources:
mem_mb=1000,
conda:
"../envs/environment.yaml"
script:
"../scripts/copy_config.py"
Together with @p-glaum we tried a bunch of ways to enforce re-executing this rule whenever the config.yaml changes, e.g., by adding config=config
to the params
section to check for changes in the snakemake.config. However, that did not work. Another idea would be to use one of the prenetworks or postnetworks as dummy input, but nothing was quite satisfactory. Scenario management and the dependence of the different solve_*
rules on the copied config.yaml complicate the matter further. Any ideas?
A workaround could be:
rule copy_config:
params:
RDIR=RDIR
config=lambda wildcards: scenario_config(wildcards.run) if "run" in wildcards else config,
But a drawback is that all the subsequent rules are then also triggered. Maybe we can create a run specific config instead
I can also confirm that this somehow bit me not too long ago, but it seems like with the current master branch the config.yaml and copy_config is not necessary anymore. See in particular https://github.com/koen-vg/pypsa-eur/tree/remove-copy-config where I removed them; the tests run fine. Any reason to still keep that rule around? Should I open a PR?
I'd vote for removing the copy_config
rule. The only thing we want to retain is a results network-specific configuration file for documentation of the options used (especially with new scenario management). But this should be exported at the end of the solve_network
rule.
I'd vote for removing the
copy_config
rule. The only thing we want to retain is a results network-specific configuration file for documentation of the options used (especially with new scenario management). But this should be exported at the end of thesolve_network
rule.
fine by me!
You mean the fact that the config is attached to n.meta
right? That should mean that one really doesn't need a separate yaml file export for the config.
Yes, a bit on the fence about the output form. I am contemplating whether it could be useful to export what is written in n.meta
additionally as a YAML file, mostly for convenience to read without opening a potentially large .nc
file and also for reusing the YAML file directly in a new snakemake run for reproducibility.
Yes, a bit on the fence about the output form. I am contemplating whether it could be useful to export what is written in
n.meta
additionally as a YAML file, mostly for convenience to read without opening a potentially large.nc
file and also for reusing the YAML file directly in a new snakemake run for reproducibility.
I agree, it would be nice to write out the YAML file for a quick inspection or for reruns.