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

Add .jinja suffix; reorganise template rules #409

Merged
merged 6 commits into from
Jul 9, 2024

Conversation

brynpickering
Copy link
Member

@brynpickering brynpickering commented Jul 2, 2024

Fixes #404
Also fixes ruleorder issue highlighted in #394. I achieved this by merging {tech_group}/{tech} into {tech_and_group} which allows us to add wildcard constraints that are combinations of tech group and tech (currently, only supply/biofuel).

Checklist

Any checks which are not relevant to the PR can be pre-checked by the PR creator. All others should be checked by the reviewer. You can add extra checklist items here if required by the PR.

  • CHANGELOG updated
  • Minimal workflow tests pass
  • Tests added to cover contribution
  • Documentation updated
  • Configuration schema updated

@brynpickering brynpickering requested a review from timtroendle July 2, 2024 10:24
Copy link
Member

@timtroendle timtroendle left a comment

Choose a reason for hiding this comment

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

The jinja part of this PR makes a lot of sense.

The part related to the "tech_locations_template" rules is nice in the sense that it removes all these rule dependencies. It comes at the price that "tech_group" and "tech" are merged into a single wildcard. That's less clear I find, but I didn't find a better solution either.

I definitely think the rules and wildcards should have different naming. I always takes my a while to understand what they are doing.

  • "tech_and_group" -> "group_and_tech", because that's the order.
  • I suggest to rename all "template" rules to "module" rules, because rules are typically named by their outputs (a model module in these cases) instead of their inputs (a template).
  • "locations_template" -> "locations", or "locations_module"
  • "techs_and_locations_template" -> "tech_module" (potentially plus "with(out)_location_data", see my comment)
  • "bio_techs_and_locations_template" -> "biofuel_tech_module"

Snakefile Outdated
rule techs_and_locations_template:
message: "Create {wildcards.resolution} definition file for the {wildcards.tech_group} tech `{wildcards.tech}`."
message: "Create {wildcards.resolution} definition file for {wildcards.tech_and_group}."
Copy link
Member

Choose a reason for hiding this comment

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

Consider naming this "group_and_tech", highlighting that groups comes first.

Copy link
Member

Choose a reason for hiding this comment

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

Also, a workflow-wide wildcard_constraint that requires this wildcard to contain / could be useful, right?

@@ -58,7 +58,7 @@
* **UPDATED** structure of YAML templates and parametrisation:
* Parametrisation moved to eurocalliopelib.
* Rules to parametrise split into smaller technology-specific rules, to ensure inputs are directly relevant to the files being parametrised.
* YAML templates restructured to match structure of final model (see `Updated (models) above`);
* YAML templates restructured to match structure of final model (see `Updated (models) above`) and given `.jinja` suffix to allow for IDE syntax highlighting (#404);
Copy link
Member

Choose a reason for hiding this comment

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

Do you use a plug-in for that? My VSCode seems to understand it's jinja (the icon is jinja), but I don't get any syntax highlighting or problems.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, found the answer myself, haha.

Snakefile Outdated
# For all cases where we don't have any location-specific data that we want to supply to the template
input:
template = techs_template_dir + "{tech_and_group}.yaml.jinja",
locations = rules.locations_template.output.csv
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR: Should this rule be called locations instead of locations_template? I was misled into thinking this was a template, but it isn't.

Copy link
Member Author

Choose a reason for hiding this comment

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

locations_from_template? I still like the link to templates in the rule name

Copy link
Member Author

Choose a reason for hiding this comment

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

or locations_calliope_input?

Copy link
Member

Choose a reason for hiding this comment

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

Personally, I like locations_module best. We already call these files modules and this would be most consistent. I am fine with renaming these files to something else, but I'd be consistent -- including in the docs.

Snakefile Outdated
script: "scripts/template_techs.py"

use rule techs_and_locations_template as dummy_tech_locations_template with:
Copy link
Member

Choose a reason for hiding this comment

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

consistent naming would be "dummy_techs_and_locations_template".

Copy link
Member

Choose a reason for hiding this comment

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

Anyways, maybe different names would be more helpful in communicating the difference. I don't really understand why this is called a "dummy". Is it maybe: "tech_and_locations_template_with(out)_location_specific_data"? That seems the be the differentiating factor to me.

Or even more radical and better in my opinion: "model_component_with(out)_location_specific_data". We don't have a clear rule, but typically rules are named by (1) what they do or (2) what they produce, not by their inputs (here: template).

Or: "module_with(out)_location_specific_data". That's how we call these files in the documentation. My favourite right now.

@brynpickering brynpickering requested a review from timtroendle July 5, 2024 14:30
Copy link
Member

@timtroendle timtroendle left a comment

Choose a reason for hiding this comment

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

I like this. There are a few more things we could change, so that we have a consistent name for this type of files.

Snakefile Outdated Show resolved Hide resolved
Snakefile Outdated Show resolved Hide resolved
Snakefile Show resolved Hide resolved
rules/shapes.smk Outdated Show resolved Hide resolved
Snakefile Outdated Show resolved Hide resolved
@brynpickering brynpickering requested a review from timtroendle July 8, 2024 17:28
@brynpickering brynpickering merged commit 6bbb2ed into develop Jul 9, 2024
4 checks passed
@brynpickering brynpickering deleted the cleanup-templates branch July 9, 2024 15:11
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.

Add .jinja to all template files
2 participants