Skip to content

Commit

Permalink
Bump version for simlogger nt patch (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinraeKim authored Dec 18, 2021
1 parent 8ea6d5e commit 4a32a8a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 94 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FSimBase"
uuid = "731e945d-f3ed-49a1-bee2-3998705ef155"
authors = ["JinraeKim <kjl950403@gmail.com> and contributors"]
version = "0.2.0"
version = "0.2.1"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand All @@ -14,11 +14,11 @@ Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"

[compat]
DataFrames = "1.2"
DiffEqBase = "6.73"
DiffEqCallbacks = "2.17"
DiffEqBase = "6.77"
DiffEqCallbacks = "2.18"
NamedTupleTools = "0.13"
Reexport = "1.2"
SimulationLogger = "0.2"
SimulationLogger = "0.3"
Transducers = "0.4"
julia = "1"

Expand Down
94 changes: 5 additions & 89 deletions src/APIs/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,6 @@ function _initialise(__Problem, state0, __dyn, p, t0, tf)
prob
end

"""
Extended to deal with empty Dict.
"""
function _namedtuple(x::Dict)
if x == Dict()
return NamedTuple() # empty NamedTuple
else
return namedtuple(x)
end
end

function recursive_namedtuple(x::Any)
x
end

function recursive_namedtuple(d::Dict)
_namedtuple(
Dict(k => recursive_namedtuple(v) for (k, v) in d)
)
end


"""
Simulator struct.
# NOTICE
Expand Down Expand Up @@ -116,9 +94,9 @@ end
function _push!(df::DataFrame, integrator::DEIntegrator, log_func)
x = integrator.u
t = integrator.t
__log_dict__ = log_func(x, t, integrator)
__log_nt__ = recursive_namedtuple(__log_dict__)
push!(df, (; time=t, sol=__log_nt__))
__logger__ = log_func(x, t, integrator)
# __log_nt__ = recursive_namedtuple(__logger__)
push!(df, (; time=t, sol=__logger__))
end

function Base.push!(simulator::Simulator, df::DataFrame, flag=true)
Expand Down Expand Up @@ -156,7 +134,7 @@ function DiffEqBase.solve(simulator::Simulator;
elseif saveat != nothing && savestep != nothing
error("Assign values of either `saveat` or `savestep`")
end
saved_values = SavedValues(Float64, Dict)
saved_values = SavedValues(Float64, NamedTuple)
if log_func != nothing
cb_save = SavingCallback(log_func, saved_values;
saveat=saveat, tdir=Int(sign(tf-t0)))
Expand All @@ -167,74 +145,12 @@ function DiffEqBase.solve(simulator::Simulator;
kwargs...)
df = DataFrame(
time = saved_values.t,
sol = saved_values.saveval |> Map(recursive_namedtuple) |> collect,
sol = saved_values.saveval,
)
df
end


# function sim(state0, dyn, p=nothing;
# solver=nothing, # DifferentialEquations.jl will find a default solver
# t0=0.0, tf=1.0,
# callback::DECallback=CallbackSet(),
# log_off=false,
# saveat=nothing,
# savestep=nothing,
# kwargs...,
# )
# if saveat == nothing && savestep == nothing
# saveat = [] # default
# elseif saveat != nothing && savestep == nothing
# # nothing
# elseif saveat == nothing && savestep != nothing
# saveat = t0:savestep:tf
# elseif saveat != nothing && savestep != nothing
# error("Assign values of either `saveat` or `savestep`")
# end
# tspan = (t0, tf)
# iip = true
# __dyn = (dx, x, p, t) -> dyn(dx, x, p, t)
# prob = ODEProblem{iip}(__dyn, state0, tspan, p) # true: isinplace
# saved_values = SavedValues(Float64, Dict)
# cb_save = nothing
# if log_off == false
# # logging function
# if isinplace(prob)
# __log_indicator__ = __LOG_INDICATOR__() # just an indicator for logging
# if hasmethod(dyn, Tuple{Any, Any, Any, Any, __LOG_INDICATOR__})
# log_func = function (x, t, integrator::DEIntegrator; kwargs...)
# x = copy(x) # `x` merely denotes a "view"
# dyn(zero.(x), x, integrator.p, t, __log_indicator__; kwargs...)
# end
# cb_save = SavingCallback(log_func, saved_values;
# saveat=saveat, tdir=Int(sign(tspan[2]-tspan[1])))
# end
# else
# error("Not tested")
# end
# callback = CallbackSet(callback, cb_save) # save values "after all other callbacks"
# end
# sol = solve(prob, solver;
# callback=callback,
# kwargs...)
# prob, sol
# if log_off == true
# return prob, sol
# else
# # recursive NamedTuple conversion from Dict; https://discourse.julialang.org/t/how-to-make-a-named-tuple-from-a-dictionary/10899/34?u=ihany
# recursive_namedtuple(x::Any) = x
# recursive_namedtuple(d::Dict) = _namedtuple(
# Dict(k => recursive_namedtuple(v) for (k, v) in d)
# )
# df = DataFrame(
# time = saved_values.t,
# sol = saved_values.saveval |> Map(recursive_namedtuple) |> collect,
# )
# return prob, df
# end
# end


"""
# Notes
- The basic concept is borrowed from [an MRAC example](https://jonniedie.github.io/ComponentArrays.jl/stable/examples/adaptive_control/).
Expand Down
2 changes: 1 addition & 1 deletion test/minimal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function main()
end
simulator = Simulator(
state0, dynamics!, p;
Problem=ODEProblem,
Problem=:ODE,
solver=Tsit5(),
tf=tf,
)
Expand Down

4 comments on commit 4a32a8a

@JinraeKim
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/50783

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 4a32a8a76776804345ce70d948694073d2886c42
git push origin v0.2.1

@JinraeKim
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request updated: JuliaRegistries/General/50783

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 4a32a8a76776804345ce70d948694073d2886c42
git push origin v0.2.1

Please sign in to comment.