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

Use absolute path for config.default.yaml in _helpers.py #1137

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

yerbol-akhmetov
Copy link
Collaborator

Changes proposed in this Pull Request

Good day. Here I propose to use absolute path to config.default.yaml in _helpers.py script. Such change is important while importing PyPSA-Earth rules elsewhere and running then in external directories within another Snakemake. This is helpful for setting workflow.

Checklist

  • I consent to the release of this PR's code under the AGPLv3 license and non-code contributions under CC0-1.0 and CC-BY-4.0.
  • I tested my contribution locally and it seems to work fine.
  • A note for the release notes doc/release_notes.rst is amended in the format of previous release notes, including reference to the requested PR.

@yerbol-akhmetov
Copy link
Collaborator Author

We are still re-testing all rules execution with @GbotemiB. Unfortunately, these small changes were not sufficient for some rules, while it worked in one machine. We will let know when it is 100% ready.
@davide-f @ekatef

@yerbol-akhmetov
Copy link
Collaborator Author

With recent commit, prefix was identified for retrieve_databundle_light rule. Generally, a prefix is added to input and outputs of the imported rules automatically when prefix is defined as:

module pypsa_earth:
    snakefile:
        "submodules/pypsa-earth/Snakefile"
    config:
        config
    prefix:
        "submodules/pypsa-earth"

Those inputs and outputs (with prefix) are accessed properly when input and outputs of rules are defined explicitly as in almost all rules, except retrieve_databundle_light rule. Therefore, prefix is added inside of the retrieve_databundle_light.py script. It helps to match the inputs of following rule to outputs of preceding rule if Snakefile import is done. If snakemake is run in pypsa-earth directory (as regularly), then prefix is an empty string `` and rules are run regularly.

@@ -143,7 +143,7 @@ def download_and_unzip_zenodo(config, rootpath, hot_run=True, disable_progress=F
"""
resource = config["category"]
file_path = os.path.join(rootpath, "tempfile.zip")
destination = os.path.relpath(config["destination"])
destination = os.path.join(PREFIX, config["destination"])
Copy link
Member

Choose a reason for hiding this comment

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

Why do you propose PREFIX here instead of BASE_DIR as in the other cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, @davide-f. That is the valid point. I have used BASE_DIR as the first try. And it worked fine as standalone for rule execution. But to make sure rules see each other and trigger, outputs and inputs needs to match. So submodules/pypsa-earth/data/eez/eez_v11.gpkg is not equal to absolute path /home/yerbol/efuels/.../submodules/pypsa-earth/data/eez/eez_v11.gpkg when it comes to input outputs of snakemake.

With BASE_DIR instead build_shapes were not triggering retrieve_databundle_light. But retrieve_databundle_light worked just fine separately when calling it. CI test actually helped me to figure that out (https://github.com/pypsa-meets-earth/pypsa-earth/actions/runs/11314101704/job/31463655978)

BASE_DIR is good for handling files inside of the script, that are not tight to input/outputs of snakemake. If it is input/output, only PREFIX makes the full workflow intact and preserve rule connections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants