Skip to content

Commit

Permalink
v0.10.3 (#91)
Browse files Browse the repository at this point in the history
* initial apply! for schedulers

* fixed "missing NelderMead"
  • Loading branch information
ThummeTo committed Jul 5, 2023
1 parent d887406 commit 53c23a4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "FMIFlux"
uuid = "fabad875-0d53-4e47-9446-963b74cae21f"
version = "0.10.2"
version = "0.10.3"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
10 changes: 7 additions & 3 deletions src/layers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ import FMIImport: fmi2Real, fmi2ValueReferenceFormat
"""
ToDo.
"""
struct FMUParameterRegistrator
struct FMUParameterRegistrator{T}
fmu::FMU2
p_refs::AbstractArray{<:fmi2ValueReference}
p::AbstractArray{<:Real}
p::AbstractArray{T}

function FMUParameterRegistrator(fmu::FMU2, p_refs::fmi2ValueReferenceFormat, p::AbstractArray{<:Real})
function FMUParameterRegistrator{T}(fmu::FMU2, p_refs::fmi2ValueReferenceFormat, p::AbstractArray{T}) where {T}
@assert length(p_refs) == length(p) "`p_refs` and `p` need to be the same length!"
p_refs = prepareValueReference(fmu, p_refs)
fmu.optim_p_refs = p_refs
fmu.optim_p = p
return new(fmu, p_refs, p)
end

function FMUParameterRegistrator(fmu::FMU2, p_refs::fmi2ValueReferenceFormat, p::AbstractArray{T}) where {T}
return FMUParameterRegistrator{T}(fmu, p_refs, p)
end
end
export FMUParameterRegistrator

Expand Down
4 changes: 2 additions & 2 deletions src/neural.jl
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ function affectFMU!(nfmu::ME_NeuralFMU, c::FMU2Component, integrator, idx)

# ToDo: Problem-related parameterization of optimize-call
#result = optimize(x_seek -> f_optim(x_seek, nfmu, right_x_fmu), left_x, LBFGS(); autodiff = :forward)
#result = Optim.optimize(x_seek -> f_optim(x_seek, nfmu, right_x_fmu, idx, sign(indicators[idx])), left_x, NelderMead())
#result = Optim.optimize(x_seek -> f_optim(x_seek, nfmu, right_x_fmu, idx, sign(indicators[idx])), left_x, Optim.NelderMead())

# if there is an ANN above the FMU, propaget FMU state through top ANN:
if nfmu.modifiedState == true
result = Optim.optimize(x_seek -> f_optim(x_seek, nfmu, c, right_x_fmu), left_x, NelderMead())
result = Optim.optimize(x_seek -> f_optim(x_seek, nfmu, c, right_x_fmu), left_x, Optim.NelderMead())
right_x = Optim.minimizer(result)
else # if there is no ANN above, then:
right_x = right_x_fmu
Expand Down
6 changes: 3 additions & 3 deletions src/scheduler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function initialize!(scheduler::BatchScheduler; runkwargs...)
scheduler.runkwargs = runkwargs
end

#scheduler.elementIndex = apply!(scheduler)
scheduler.elementIndex = apply!(scheduler)

if scheduler.plotStep > 0
plot(scheduler, lastIndex)
Expand All @@ -201,11 +201,11 @@ function update!(scheduler::BatchScheduler)

scheduler.step += 1

if scheduler.step % scheduler.applyStep == 0
if scheduler.applyStep > 0 && scheduler.step % scheduler.applyStep == 0
scheduler.elementIndex = apply!(scheduler)
end

if scheduler.step % scheduler.plotStep == 0
if scheduler.plotStep > 0 && scheduler.step % scheduler.plotStep == 0
plot(scheduler, lastIndex)
end
end
Expand Down

0 comments on commit 53c23a4

Please sign in to comment.