-
Notifications
You must be signed in to change notification settings - Fork 360
define extra_funcitonality inside solve_network to capture snakemake object #1787
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
FabianHofmann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since moving this will likely lead to a lot of merge conflicts in downstream forks, what you can do alternatively is to pass the snakemake object to n._snakemake and change
custom_extra_functionality(n, snapshots, snakemake) # pylint: disable=E0601to
custom_extra_functionality(n, snapshots, n._snakemake)|
Or you make an explicit argument to def extra_functionality(
n: pypsa.Network, snapshots: pd.DatetimeIndex, planning_horizons: str | None = None, snakemake: Snakemake
) -> None:and then pass it to n.optimize(..., extra_functionality=partial(extra_functionality, snakemake=snakemake)) |
|
I like the While we are at it: If snakemake is passed to solve_network should we get rid of all the other keywords as well? |
fneum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! Let's start with that.
At the moment the solve_network function can not be imported from other scripts, because the snakemake object required by extra_functionality is a global variable.
This PR defines the extra_functionality within solve_network, and adds the snakemake object as an additional argument to solve_network, s.t. the snakemake object can be captured from the scope of solve_network instead of the global scope.
This allows imports of the
solve_networkfunction from other scripts.For an application see: PyPSA/pypsa-de#103
Before completing the PR i'd like to hear some opinions @fneum @lkstrp
Closes # (if applicable).
Changes proposed in this Pull Request
Checklist
envs/environment.yaml.config/config.default.yaml.doc/configtables/*.csv.doc/data_sources.rst.doc/release_notes.rstis added.