Skip to content

Commit

Permalink
basic load/save solution in julia JLD2 format (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreMartinon authored Jun 3, 2024
1 parent fe559d5 commit 8a0b685
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*.jl.mem
*.jl.*.mem

# Julia data files
*.jld2

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ version = "0.6.0"
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
CTBase = "54762871-cc72-4466-b8e8-f6c8b58076cd"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
Expand Down
1 change: 1 addition & 0 deletions src/CTDirect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ export dynamics!
export objective!
export remove_constraint!
export OCPInit
export plot

end
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
7 changes: 7 additions & 0 deletions test/suite/misc.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CTDirect
using JLD2

println("Test: misc")

Expand Down Expand Up @@ -42,3 +43,9 @@ nlp = getNLP(docp)
dsol = solve(docp, print_level=0, tol=1e-12)
sol_raw = OCPSolutionFromDOCP_raw(docp, dsol.solution)

# test save / load solution in JLD2 format
@testset verbose = true showtiming = true ":save_load :JLD2" begin
save_object("sol.jld2", sol0)
sol_reloaded = load_object("sol.jld2")
@test sol0.objective == sol_reloaded.objective
end
7 changes: 7 additions & 0 deletions test/test_misc.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CTDirect
using JLD2

println("Test: misc")

Expand Down Expand Up @@ -41,5 +42,11 @@ dsol2 = solve(docp2, print_level=5, tol=1e-12)
println("\nRebuild OCP solution from raw vector")
sol3 = OCPSolutionFromDOCP_raw(docp2, dsol2.solution)

# save / load solution in JLD2 format (solution includes complex data such as interpolated functions which are less suitable for more generic formats such as JSON)
save_object("sol.jld2", sol)
sol4 = load_object("sol.jld2")
plot(sol4, show=true)
println(sol.objective == sol4.objective)

println("")
#

0 comments on commit 8a0b685

Please sign in to comment.