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 the transport tutorial #146

Draft
wants to merge 17 commits into
base: enh/run-clone
Choose a base branch
from

Conversation

danielhuppmann
Copy link
Member

@danielhuppmann danielhuppmann commented Jan 9, 2025

This PR copies over the transport tutorial (with linopy) from #101 in a more streamlined manner. Most importantly, the term "tutorial" is now used for the entire thing consisting of three notebooks:

  1. set up the database
  2. implement the base version of the transport problem
  3. do a scenario/variation

@danielhuppmann danielhuppmann self-assigned this Jan 9, 2025
Copy link

codecov bot commented Jan 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.1%. Comparing base (d69ff7c) to head (4cc277d).

Additional details and impacted files
@@              Coverage Diff              @@
##           enh/run-clone    #146   +/-   ##
=============================================
  Coverage           87.1%   87.1%           
=============================================
  Files                231     231           
  Lines               8216    8216           
=============================================
  Hits                7160    7160           
  Misses              1056    1056           

@glatterf42 glatterf42 self-assigned this Jan 10, 2025
@glatterf42 glatterf42 added the enhancement New feature or request label Jan 10, 2025
Copy link
Member

@glatterf42 glatterf42 left a comment

Choose a reason for hiding this comment

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

Thanks for starting this work and outlining the structure you envision :)

I have cleaned up the notebook files, made formatting consistent, added some content where I thought it was needed, updated the syntax to fit our current API, and made the code comply with the mypy config.
This last step includes adding linopy to the dependencies. Unfortunately, linopy still doesn't support numpy 2.0, see PyPSA/linopy#386 and PyPSA/linopy#332, so this brings with it an effective numpy pin to < 2.0. I would like to avoid that, so I would not merge this PR right away.
Even more so since Volker previously indicated that linopy might not be the tool of choice for us since it doesn't support non-linear programming. I've opened PyPSA/linopy#384 to ask their maintainers about plans for that, but haven't received a reply yet.

On top of all this, I'm not sure why the codecov report says that all coverable lines are covered. It seems to me that this PR so far copies over the utility code for running the tutorials, but not the tests for the same, which should be a TODO:

  • Add tests for the tutorials and their utility code

@glatterf42
Copy link
Member

Not sure why mypy is still failing here. I bumped the version locally, which removed the linopy/numpy pin. So this latest commit might also break the usability of linopy, but poetry allowed this.

@glatterf42
Copy link
Member

Thanks for your updates here, @danielhuppmann! I have reworked some of them, mainly in terms of formatting: we seem to have different preferences how to highlight things. I differentiate between names of tools and software, which I write like this, and vocabulary of our tool in particular, including function names and code object names, which I write like this. I think this helps newcomers to spot the difference and they will need to learn the vocabulary, anyway. I also apply the same highlighting always to indicate that Run still means Run and not "run". The only exception to this rule is when I think we're talking about "real world" units, for examples, as opposed to the Unit objects we have in ixmp4.

"metadata": {},
"source": [
"You can check that the solution from [Notebook 1](1_transport-tutorial.ipynb) was indeed saved by inspecting an `ixmp4.Variable`. \n",
"The `data` of any optimization object is stored internally as a dictionary."
Copy link
Member

Choose a reason for hiding this comment

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

Just noting here that this might change soon if the "Normalize Parameter DB storage" PR gets finished and accepted.

Comment on lines +468 to +477
"## Cleaning up after doing this tutorial\n",
"\n",
"You can use the **ixmp4** Command Line Interface (CLI) to remove the database related to this tutorial.\n",
"\n",
"Run the following in the command-line:\n",
"```\n",
"ixmp4 platforms remove transport-tutorial\n",
"```\n",
"\n",
"The prompt will ask whether you also want to delete the SQLite database file from your computer, answer `y` for a complete deletion."
Copy link
Member

Choose a reason for hiding this comment

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

Maybe by having this cell here, we can remove the almost identical ones in Notebook 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, my thinking for having it twice is to show users that do something stupid during setup how to quickly restart - and then show how clean up at the end of the tutorial.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, we can also have it twice :)

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

Successfully merging this pull request may close these issues.

2 participants