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

merge-v0.13.0 #9

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions .github/workflows/Example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ jobs:
julia-version: ['1.8']
julia-arch: [x64]
experimental: [false]

steps:
- name: "Check out repository"
uses: actions/checkout@v3

- name: "Set up Julia"
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}

- name: "Install dependencies"
run: julia --project=examples/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'

- name: "Install packages"
run: pip install jupyter nbconvert

Expand All @@ -48,7 +48,7 @@ jobs:
jupyter nbconvert --ExecutePreprocessor.kernel_name="julia-1.8" --to notebook --inplace --execute ${{ env.FILE }}
jupyter nbconvert --to script ${{ env.FILE }}
jupyter nbconvert --to markdown ${{ env.FILE }}

- name: "Fix GIFs"
run: |
echo "starting gif fixing"
Expand All @@ -57,7 +57,7 @@ jobs:
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 (success)
if: success() && matrix.os == 'windows-latest'
uses: actions/upload-artifact@v3
Expand All @@ -70,30 +70,52 @@ jobs:
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:
filecheck:
needs: [jypiter, pluto]
runs-on: ubuntu-latest
steps:
- name: Download jupyter examples
uses: actions/download-artifact@v3
with:
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: Check if the example files generated are valid (if jupyter-examples failed, svgs are missing; jupyter command does not fail even if examples fail)
uses: andstor/file-existence-action@v3
with:
files: "examples/jupyter-src/*/*.svg"
fail: true

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

- name: Download jupyter examples
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -130,7 +152,7 @@ jobs:
git add ${{ env.EXAMPLES_PATH }}
git commit -m "${{ env.CI_COMMIT_MESSAGE }}"
git push origin examples

call-docu:
needs: auto-commit
if: github.event_name != 'pull_request'
Expand Down
29 changes: 16 additions & 13 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
name = "FMIFlux"
uuid = "fabad875-0d53-4e47-9446-963b74cae21f"
version = "0.12.2"
version = "0.13.0"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DifferentiableEigen = "73a20539-4e65-4dcb-a56d-dc20f210a01b"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
FMIImport = "9fcbc62e-52a0-44e9-a616-1359a0008194"
FMISensitivity = "3e748fe5-cd7f-4615-8419-3159287187d2"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
ThreadPools = "b189fb0b-2eb5-4ed4-bc0c-d34c51242431"

[weakdeps]
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"

[extensions]
JLD2Ext = ["JLD2"]

[compat]
Colors = "0.12.8"
Colors = "0.12"
DifferentiableEigen = "0.2.0"
DifferentialEquations = "7.7.0 - 7.12"
FMIImport = "0.16.4"
FMISensitivity = "0.1.4"
Flux = "0.13.0 - 0.14"
Optim = "1.7.0"
ProgressMeter = "1.7.0 - 1.9"
Requires = "1.3.0"
ThreadPools = "2.1.1"
FMIImport = "1.0.0"
FMISensitivity = "0.2.0"
Flux = "0.9 - 0.14"
Optim = "1.6"
OrdinaryDiffEq = "6.0"
Statistics = "1"
ThreadPools = "2.1"
julia = "1.6"
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ To keep dependencies nice and clean, the original package [*FMI.jl*](https://git
- [*FMI.jl*](https://github.com/ThummeTo/FMI.jl): High level loading, manipulating, saving or building entire FMUs from scratch
- [*FMIImport.jl*](https://github.com/ThummeTo/FMIImport.jl): Importing FMUs into Julia
- [*FMIExport.jl*](https://github.com/ThummeTo/FMIExport.jl): Exporting stand-alone FMUs from Julia Code
- [*FMIBase.jl*](https://github.com/ThummeTo/FMIBase.jl): Common concepts for import and export of FMUs
- [*FMICore.jl*](https://github.com/ThummeTo/FMICore.jl): C-code wrapper for the FMI-standard
- [*FMISensitivity.jl*](https://github.com/ThummeTo/FMISensitivity.jl): Static and dynamic sensitivities over FMUs
- [*FMIBuild.jl*](https://github.com/ThummeTo/FMIBuild.jl): Compiler/Compilation dependencies for FMIExport.jl
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs (differentiation over FMUs)
- [*FMIFlux.jl*](https://github.com/ThummeTo/FMIFlux.jl): Machine Learning with FMUs
- [*FMIZoo.jl*](https://github.com/ThummeTo/FMIZoo.jl): A collection of testing and example FMUs

## How to cite?
Expand Down
12 changes: 9 additions & 3 deletions src/extensions/JLD2.jl → ext/JLD2Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

function fmiSaveParameters(nfmu::NeuralFMU, path::String; keyword="parameters")
module JLD2Ext

using FMIFlux, JLD2

function FMIFlux.saveParameters(nfmu::NeuralFMU, path::String; keyword="parameters")

params = Flux.params(nfmu)

JLD2.save(path, Dict(keyword=>params[1]))
end

function fmiLoadParameters(nfmu::NeuralFMU, path::String; flux_model=nothing, keyword="parameters")
function FMIFlux.loadParameters(nfmu::NeuralFMU, path::String; flux_model=nothing, keyword="parameters")

paramsLoad = JLD2.load(path, keyword)

Expand Down Expand Up @@ -40,4 +44,6 @@ function fmiLoadParameters(nfmu::NeuralFMU, path::String; flux_model=nothing, ke
end

return nothing
end
end

end # JLD2Ext
61 changes: 10 additions & 51 deletions src/FMIFlux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,20 @@ if VERSION < v"1.7.0"
@warn "Training under Julia 1.6 is very slow, please consider using Julia 1.7 or newer." maxlog=1
end

import FMIImport.FMICore: hasCurrentComponent, getCurrentComponent, unsense
import FMIImport.FMICore.ChainRulesCore: ignore_derivatives
import FMIImport.FMIBase: hasCurrentInstance, getCurrentInstance, unsense
import FMISensitivity.ChainRulesCore: ignore_derivatives

import DifferentialEquations
import FMIImport

using Requires
import Flux

using FMIImport
using FMIImport: fmi2ValueReference, FMU, FMU2, FMU2Component
using FMIImport: fmi2Struct
using FMIImport: fmi2SetupExperiment, fmi2EnterInitializationMode, fmi2ExitInitializationMode, fmi2Reset, fmi2Terminate
using FMIImport: fmi2NewDiscreteStates, fmi2SetContinuousStates, fmi2GetContinuousStates, fmi2GetNominalsOfContinuousStates
using FMIImport: fmi2SetTime, fmi2CompletedIntegratorStep, fmi2GetEventIndicators, fmi2GetDerivatives, fmi2GetReal
using FMIImport: fmi2SampleJacobian, fmi2GetDirectionalDerivative, fmi2GetJacobian, fmi2GetJacobian!
using FMIImport: fmi2True, fmi2False

import FMIImport.FMICore: fmi2ValueReferenceFormat, fmi2Real

include("optimiser.jl")
include("hotfixes.jl")
include("convert.jl")
include("flux_overload.jl")
include("neural.jl")
#include("chain_rules.jl")
include("misc.jl")
include("layers.jl")
include("deprecated.jl")
Expand All @@ -51,46 +39,17 @@ include("losses.jl")
include("scheduler.jl")
include("compatibility_check.jl")

# from Plots.jl
# No export here, Plots.plot is extended if available.

# from FMI.jl
function fmiPlot(nfmu::NeuralFMU; kwargs...)
@assert false "fmiPlot(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
end
function fmiPlot!(fig, nfmu::NeuralFMU; kwargs...)
@assert false "fmiPlot!(...) needs `Plots` package. Please install `Plots` and do `using Plots` or `import Plots`."
end
# No export here, FMI.fmiPlot is extended.

# from JLD2.jl
function fmiSaveParameters(nfmu::NeuralFMU, path::String; keyword="parameters")
@assert false "fmiSaveParameters(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
end
function fmiLoadParameters(nfmu::NeuralFMU, path::String; flux_model=nothing, keyword="parameters")
@assert false "fmiLoadParameters(...) needs `JLD2` package. Please install `JLD2` and do `using JLD2` or `import JLD2`."
end
export fmiSaveParameters, fmiLoadParameters

# optional extensions
using FMIImport.FMIBase.Requires
using FMIImport.FMIBase.PackageExtensionCompat
function __init__()
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin
import .Plots
include("extensions/Plots.jl")
end

@require FMI="14a09403-18e3-468f-ad8a-74f8dda2d9ac" begin
@require Plots="91a5bcdd-55d7-5caf-9e0b-520d859cae80" begin
import .FMI
include("extensions/FMI.jl")
end
end

@require JLD2="033835bb-8acc-5ee8-8aae-3f567f8a3819" begin
import .JLD2
include("extensions/JLD2.jl")
end
@require_extensions
end

# JLD2.jl
function saveParameters end
function loadParameters end

# FMI_neural.jl
export ME_NeuralFMU, CS_NeuralFMU, NeuralFMU

Expand Down
10 changes: 5 additions & 5 deletions src/batch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

import FMIImport.FMICore: FMUSnapshot
import FMIImport.FMIBase: FMUSnapshot
import FMIImport: fmi2Real, fmi2FMUstate, fmi2EventInfo, fmi2ComponentState
using DifferentialEquations.DiffEqCallbacks: FunctionCallingCallback
using FMIImport.FMIBase.DiffEqCallbacks: FunctionCallingCallback

abstract type FMU2BatchElement end

Expand Down Expand Up @@ -66,7 +66,7 @@ mutable struct FMU2SolutionBatchElement{D} <: FMU2BatchElement

indicesModel

solution::FMU2Solution
solution::FMUSolution

scalarLoss::Bool
# canGetSetState::Bool
Expand Down Expand Up @@ -309,10 +309,10 @@ function loss!(batchElement::FMU2SolutionBatchElement, lossFct; logLoss::Bool=fa

loss = 0.0 # will be incremented

if hasmethod(lossFct, Tuple{FMU2Solution})
if hasmethod(lossFct, Tuple{FMUSolution})
loss = lossFct(batchElement.solution)

elseif hasmethod(lossFct, Tuple{FMU2Solution, Union{}})
elseif hasmethod(lossFct, Tuple{FMUSolution, Union{}})
loss = lossFct(batchElement.solution, batchElement.targets)

else # hasmethod(lossFct, Tuple{Union{}, Union{}})
Expand Down
8 changes: 5 additions & 3 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT license. See LICENSE file in the project root for details.
#

using FMIImport.FMIBase: FMI2Struct

"""
DEPRECATED:

Expand Down Expand Up @@ -46,7 +48,7 @@ DEPRECATED:

Wrapper. Call ```fmi2EvaluateME``` for more information.
"""
function fmiEvaluateME(str::fmi2Struct,
function fmiEvaluateME(str::FMI2Struct,
x::Array{<:Real},
t::Real = (typeof(str) == FMU2 ? str.components[end].t : str.t),
setValueReferences::Union{Array{fmi2ValueReference}, Nothing} = nothing,
Expand All @@ -64,7 +66,7 @@ DEPRECATED:

Wrapper. Call ```fmi2DoStepCS``` for more information.
"""
function fmiDoStepCS(str::fmi2Struct,
function fmiDoStepCS(str::FMI2Struct,
dt::Real,
setValueReferences::Array{fmi2ValueReference} = zeros(fmi2ValueReference, 0),
setValues::Array{<:Real} = zeros(Real, 0),
Expand All @@ -78,7 +80,7 @@ DEPRECATED:

Wrapper. Call ```fmi2InputDoStepCSOutput``` for more information.
"""
function fmiInputDoStepCSOutput(str::fmi2Struct,
function fmiInputDoStepCSOutput(str::FMI2Struct,
dt::Real,
u::Array{<:Real})
fmi2InputDoStepCSOutput(str, dt, u)
Expand Down
17 changes: 0 additions & 17 deletions src/extensions/FMI.jl

This file was deleted.

6 changes: 0 additions & 6 deletions src/extensions/Plots.jl

This file was deleted.

Loading
Loading