Skip to content

Commit

Permalink
Added Pluto workshop examples to github example action and docs (#129)
Browse files Browse the repository at this point in the history
* added pluto action and moved example

* removed dbg junk

* added autocommit to examples branch

* added to Documentation building, dbg upload for docs

* moved examples around

* merged Actions

* fixed Doc action

* doc action uses triggering branch now

* removed debug statements

* trigger action

---------

Co-authored-by: exnersim <simon.exner@student.uni-augsburg.de>
  • Loading branch information
0815Creeper and exnersim authored Apr 19, 2024
1 parent 77471fb commit 4a35090
Show file tree
Hide file tree
Showing 21 changed files with 60 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: "Check out repository"
uses: actions/checkout@v3
with:
ref: main
ref: ''

- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
Expand All @@ -37,13 +37,13 @@ jobs:
env:
WORK_TREE: './docs/src/examples'
SRC_BRANCH: 'origin/examples'
SRC_FOLDER_PATH: 'examples/src'
SRC_FOLDER_PATH: 'examples'
# copy the examples from the examples branch (.md, .svg) and copy the readme in the docs folder
run: |
git fetch
git --work-tree=$WORK_TREE/.. checkout $SRC_BRANCH -- $SRC_FOLDER_PATH/*.md $SRC_FOLDER_PATH/*.svg $SRC_FOLDER_PATH/*.gif
mv $WORK_TREE/src/* $WORK_TREE
rm -r $WORK_TREE/src
git --work-tree=$WORK_TREE/.. checkout $SRC_BRANCH -- $SRC_FOLDER_PATH/jupyter-src/*.md $SRC_FOLDER_PATH/jupyter-src/*.svg $SRC_FOLDER_PATH/jupyter-src/*.gif $SRC_FOLDER_PATH/pluto-src/*.html
mv $WORK_TREE/jupyter-src/* $WORK_TREE
rm -r $WORK_TREE/jupyter-src
cp ./README.md ./docs/src/index.md
- name: "Install dependencies"
Expand Down
62 changes: 45 additions & 17 deletions .github/workflows/Example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ on:
- main
paths:
- 'src/**'
- 'examples/src/**'
- 'examples/jupyter-src/**'
- 'examples/pluto-src/**'
- '.github/workflows/Example.yml'
- 'Project.toml'

jobs:
sync-files:
jypiter:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -42,7 +43,7 @@ jobs:

- name: "Execute and synchronize all files"
env:
FILE: examples/src/${{ matrix.file-name }}.ipynb
FILE: examples/jupyter-src/${{ matrix.file-name }}.ipynb
run: |
jupyter nbconvert --ExecutePreprocessor.kernel_name="julia-1.8" --to notebook --inplace --execute ${{ env.FILE }}
jupyter nbconvert --to script ${{ env.FILE }}
Expand All @@ -51,40 +52,67 @@ jobs:
- name: "Fix GIFs"
run: |
echo "starting gif fixing"
mv examples/src/gif_*.gif examples/src/${{ matrix.file-name }}_files
mv examples/jupyter-src/gif_*.gif examples/jupyter-src/${{ matrix.file-name }}_files
$env:Path += ";C:\Program Files\Git\usr\bin"
awk '{if($0~/<img src="data:image\/gif;base64,[[:alpha:],[:digit:],\/,+,=]*" \/>/) {sub(/<img src="data:image\/gif;base64,[[:alpha:],[:digit:],\/,+,=]*" \/>/,"![gif](${{ matrix.file-name }}_files\/gif_"++i".gif)")}}1' examples/src/${{ matrix.file-name }}.md > examples/src/tmp_${{ matrix.file-name }}.md
mv -Force examples/src/tmp_${{ matrix.file-name }}.md examples/src/${{ matrix.file-name }}.md
awk '{if($0~/<img src="data:image\/gif;base64,[[:alpha:],[:digit:],\/,+,=]*" \/>/) {sub(/<img src="data:image\/gif;base64,[[:alpha:],[:digit:],\/,+,=]*" \/>/,"![gif](${{ matrix.file-name }}_files\/gif_"++i".gif)")}}1' examples/jupyter-src/${{ matrix.file-name }}.md > examples/jupyter-src/tmp_${{ matrix.file-name }}.md
mv -Force examples/jupyter-src/tmp_${{ matrix.file-name }}.md examples/jupyter-src/${{ matrix.file-name }}.md
echo "gifs should be fixed"
- name: Archive examples artifacts
- name: Archive examples artifacts (success)
if: success() && matrix.os == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: examples
path: examples/src/${{ matrix.file-name }}*
name: jupyter-examples
path: examples/jupyter-src/${{ matrix.file-name }}*

pluto:
runs-on: ubuntu-latest
steps:
- name: "Check out repository"
uses: actions/checkout@v3

- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: '1.10'

- run: julia -e 'using Pkg; Pkg.add("PlutoSliderServer"); Pkg.add("FMIFlux")'
- run: julia -e 'using PlutoSliderServer; PlutoSliderServer.export_directory("examples/pluto-src")'

- name: Archive examples artifacts (success)
if: success()
uses: actions/upload-artifact@v3
with:
name: pluto-examples
path: examples/pluto-src/*

auto-commit:
needs: sync-files
needs: [jypiter, pluto]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3

- name: Download examples
- name: Download jupyter examples
uses: actions/download-artifact@v3
with:
name: examples
path: examples/src/
name: jupyter-examples
path: examples/jupyter-src/

- name: Download pluto examples
uses: actions/download-artifact@v3
with:
name: pluto-examples
path: examples/pluto-src/

- name: auto-commit
env:
CI_COMMIT_MESSAGE: Jupyter nbconvert synch - modified, paired .ipynb files
CI_COMMIT_MESSAGE: Jupyter modified .ipynb & exported md files; Pluto static html exported files
CI_COMMIT_AUTHOR: github-actions[bot]
EXAMPLES_PATH: examples/src
# Fetch all and clear the stash list. Include all files from the examples/src folder to the stash and switch the branch.
# Reset the branch and remove all current files in the examples/src folder.
EXAMPLES_PATH: examples
# Fetch all and clear the stash list. Include all files from the examples/jupyter-src folder to the stash and switch the branch.
# Reset the branch and remove all current files in the examples/jupyter-src folder.
# Checkout the last stash to restore the new notebooks and apply the stash index to restore all other new files in the folder.
run: |
git fetch --all
Expand Down
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ makedocs(sitename="FMIFlux.jl",
"JuliaCon 2023" => "examples/juliacon_2023.md"
"MDPI 2022" => "examples/mdpi_2022.md"
"Modelica Conference 2021" => "examples/modelica_conference_2021.md"
"Pluto Workshops" => "examples/workshops.md"
]
"FAQ" => "faq.md"
"Library Functions" => "library.md"
Expand Down
6 changes: 5 additions & 1 deletion docs/src/examples/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ The examples show how to combine FMUs with machine learning ("NeuralFMU") and il
- [__Modelica Conference 2021: NeuralFMUs__](https://thummeto.github.io/FMIFlux.jl/dev/examples/modelica_conference_2021/): Showing basics on how to train a NeuralFMU (Contribution for the *Modelica Conference 2021*).

## Archived
- [__MDPI 2022: Physics-enhanced NeuralODEs in real-world applications__](https://thummeto.github.io/FMIFlux.jl/dev/examples/mdpi_2022/): An example for a NeuralODE in a real world modeling scenario (Contribution in *MDPI Electronics 2022*).
- [__MDPI 2022: Physics-enhanced NeuralODEs in real-world applications__](https://thummeto.github.io/FMIFlux.jl/dev/examples/mdpi_2022/): An example for a NeuralODE in a real world modeling scenario (Contribution in *MDPI Electronics 2022*).

## Workshops
[Pluto](https://plutojl.org/) based notebooks, that can easyly be executed on your own Pluto-Setup.
- [__HybridModelingUsingFMI__](../pluto-src/HybridModelingUsingFMI/HybridModelingUsingFMI.html): Workshop at MODPROD 2024 (Linköping University, Sweden)
4 changes: 4 additions & 0 deletions docs/src/examples/workshops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Pluto](https://plutojl.org/) based notebooks, that can easyly be executed on your own Pluto-Setup.
```@raw html
<iframe src="../pluto-src/index.html" style="height:500px;width:100%;"></iframe>
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4a35090

Please sign in to comment.