-
Notifications
You must be signed in to change notification settings - Fork 9
feat(tutorials): ship tutorial data + downloadable example systems #706
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| name: Tutorial data | ||
|
|
||
| # Builds the pre-built example FlowSystems and uploads them (plus registry.txt) as | ||
| # assets to the GitHub release that `flixopt.tutorials.load_example` downloads from. | ||
| # Run manually whenever the example systems change. The release tag must match | ||
| # `flixopt.tutorials._examples.DATA_RELEASE` (default: tutorial-data-v1). | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| release_tag: | ||
| description: "Release tag to (re)upload the data assets to (must match DATA_RELEASE)." | ||
| required: true | ||
| default: "tutorial-data-v1" | ||
|
|
||
| env: | ||
| PYTHON_VERSION: "3.11" | ||
|
|
||
| jobs: | ||
| build-and-upload: | ||
| name: Build and upload example systems | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - uses: astral-sh/setup-uv@v7 | ||
| with: | ||
| version: "0.10.9" | ||
| enable-cache: true | ||
|
|
||
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: ${{ env.PYTHON_VERSION }} | ||
|
|
||
| # docs extra provides demandlib/pvlib/holidays used by the example generators. | ||
| - name: Install build dependencies | ||
| run: uv pip install --system -e ".[docs,full]" | ||
|
|
||
| - name: Verify DATA_RELEASE matches the requested tag | ||
| run: | | ||
| EXPECTED=$(python -c "from flixopt.tutorials._examples import DATA_RELEASE; print(DATA_RELEASE)") | ||
| if [[ "$EXPECTED" != "$TAG" ]]; then | ||
| echo "::error::DATA_RELEASE is '$EXPECTED' but the workflow was asked to upload to '$TAG'." | ||
| echo "Update flixopt/tutorials/_examples.py or pass the matching tag." | ||
| exit 1 | ||
| fi | ||
| env: | ||
| TAG: ${{ inputs.release_tag }} | ||
|
|
||
| - name: Build example systems | ||
| run: python scripts/build_tutorial_datasets.py --out-dir dist/tutorial_datasets | ||
|
|
||
| - name: Create the data release if it does not exist | ||
| run: | | ||
| if ! gh release view "$TAG" >/dev/null 2>&1; then | ||
| gh release create "$TAG" \ | ||
| --title "Tutorial data ($TAG)" \ | ||
| --notes "Pre-built example FlowSystems downloaded by flixopt.tutorials.load_example." \ | ||
| --prerelease | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ inputs.release_tag }} | ||
|
|
||
| - name: Upload data assets | ||
| run: gh release upload "$TAG" dist/tutorial_datasets/* --clobber | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ inputs.release_tag }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,9 +59,7 @@ | |
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from data.generate_example_systems import create_district_heating_system\n", | ||
| "\n", | ||
| "flow_system = create_district_heating_system()\n", | ||
| "flow_system = fx.tutorials.load_example('district_heating')\n", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
BASE_URL="https://github.com/flixOpt/flixopt/releases/download/tutorial-data-v1"
files=(
"registry.txt"
"district_heating.nc"
"operational.nc"
"simple.nc"
"complex.nc"
"seasonal_storage.nc"
"multiperiod.nc"
)
for f in "${files[@]}"; do
code=$(curl -s -o /dev/null -w "%{http_code}" -L "${BASE_URL}/${f}")
echo "${f} -> HTTP ${code}"
doneRepository: flixOpt/flixopt Length of output: 247 Tutorial release assets are missing; publish Line 63 uses 🤖 Prompt for AI Agents |
||
| "flow_system.connect_and_transform() # Align all data as xarray\n", | ||
| "\n", | ||
| "timesteps = flow_system.timesteps\n", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """Datasets and example systems for the flixopt tutorials and notebooks. | ||
|
|
||
| Two tiers, so every notebook is standalone after ``pip install flixopt`` - no need | ||
| to clone the repository or copy files out of GitHub: | ||
|
|
||
| * **Synthetic data** (notebooks 01-07) - generated on the fly from numpy/pandas, | ||
| no files and no network. Access by name with :func:`get_data`; see :func:`list_data`. | ||
|
|
||
| * **Pre-built example systems** (notebooks 08-09) - downloaded (and cached) from the | ||
| project's GitHub releases with :func:`load_example`; see :func:`list_examples`. | ||
| Needs ``pooch`` (``pip install flixopt[tutorials]``). | ||
| """ | ||
|
|
||
| from ._examples import ExampleName, list_examples, load_example | ||
| from ._tutorial_data import DataName, get_data, list_data | ||
|
|
||
| __all__ = [ | ||
| 'DataName', | ||
| 'get_data', | ||
| 'list_data', | ||
| 'ExampleName', | ||
| 'load_example', | ||
| 'list_examples', | ||
| ] |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: flixOpt/flixopt
Length of output: 482
🏁 Script executed:
Repository: flixOpt/flixopt
Length of output: 2057
Pin action revisions to commit SHAs and disable checkout credential persistence in this write-scoped job.
This workflow has
permissions: contents: writeat the job level. The three action references use mutable@v*version tags rather than pinned commit SHAs:actions/checkout@v6(line 26)astral-sh/setup-uv@v7(line 30)actions/setup-python@v6(line 35)Additionally, the checkout action does not set
persist-credentials: false. For a write-scoped job, pin each action to a full commit SHA and disable credential persistence to reduce supply-chain and token exposure risk.🧰 Tools
🪛 zizmor (1.25.2)
[warning] 26-28: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
[error] 26-26: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
[error] 30-30: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
[error] 35-35: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)
(unpinned-uses)
🤖 Prompt for AI Agents
Source: Linters/SAST tools