Skip to content

Commit

Permalink
feat: support serialization of clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jul 30, 2024
1 parent 3a65166 commit 2628741
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/clock.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Clocks

export TimeDomain

using Expronicon.ADT: @adt, @match
using Expronicon.ADT: variant_type, @adt, @match

@adt TimeDomain begin
Continuous
Expand All @@ -15,6 +15,16 @@ end

Base.Broadcast.broadcastable(d::TimeDomain) = Ref(d)

const DiscriminatorType = typeof(variant_type(Continuous))

function Base.write(io::IO, x::DiscriminatorType)
write(io, Base.reinterpret(UInt32, x))
end

function Base.read(io::IO, ::Type{DiscriminatorType})
Base.reinterpret(DiscriminatorType, read(io, UInt32))
end

end

using .Clocks
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ end
@time @safetestset "Problem building tests" begin
include("problem_building_test.jl")
end
@time @safetestset "Serialization tests" begin
include("serialization_tests.jl")
end
end

if !is_APPVEYOR &&
Expand Down
18 changes: 18 additions & 0 deletions test/serialization_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using SciMLBase
using Serialization
using Test

for clock in [
SciMLBase.Clock(0.5),
SciMLBase.Clock(0.5; phase = 0.1),
SciMLBase.SolverStepClock,
SciMLBase.Continuous,
]
serialize("_tmp.jls", clock)
newclock = deserialize("_tmp.jls")
@test newclock == clock
end

if isfile("_tmp.jls")
rm("_tmp.jls")
end

0 comments on commit 2628741

Please sign in to comment.