Skip to content

Commit

Permalink
test over a shorter interval, loosen test tolerances
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonProtter committed Sep 30, 2024
1 parent a295c2b commit 2fe7ec8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[sources]
GraphDynamics = {path = "../"}
18 changes: 9 additions & 9 deletions test/particle_osc_example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function ((;fac)::Coulomb)(a, b)
end


function solve_particle_osc(;x1, x2)
function solve_particle_osc(;x1, x2, tspan = (0.0, 10.0), alg=Tsit5())
# put some garbage values in here for states and params, but we'll set them to reasonable values later with the
# u0map and param_map
subsystems_partitioned = ([Subsystem{Particle}(states=(;x= NaN, v=0.0), params=(;m=1.0, q=1.0)),
Expand Down Expand Up @@ -76,31 +76,31 @@ function solve_particle_osc(;x1, x2)
connection_matrices = ConnectionMatrices((spring_conns, coulomb_conns))

sys = ODEGraphSystem(;connection_matrices, states_partitioned, params_partitioned, names_partitioned)
tspan = (0.0, 20.0)


prob = ODEProblem(sys,
# Fix the garbage state values
[:particle1₊x => x1, :particle2₊x => x2, :particle2₊v => 0.0, :osc₊x => 0.0],
tspan,
# fix the garbage param values
[:osc₊m => 3.0])
sol = solve(prob, Tsit5())
sol = solve(prob, alg)
end

@testset "solutions" begin
sol = solve_particle_osc(;x1=1.0, x2=-1.0)
@test sol[:particle1₊x][end] 1.4923823131014389 rtol=1e-7
@test sol[:particle2₊x][end] -0.11189010002787175 rtol=1e-7
@test sol[:osc₊x][end] 1.3175449091469553 rtol=1e-7
@test sol[:particle1₊x][end] 0.580617 rtol=1e-3
@test sol[:particle2₊x][end] -1.391576 rtol=1e-3
@test sol[:osc₊x][end] -1.063306 rtol=1e-3
end

@testset "sensitivies" begin
jac = ForwardDiff.jacobian([1.0, -1.0]) do (x1, x2)
sol = solve_particle_osc(;x1, x2)
[sol[:particle1₊x][end], sol[:particle2₊x][end], sol[:osc₊x][end]]
end
@test jac [0.498565 -0.0161443
-1.92556 3.14649
-0.249007 0.808641] rtol=1e-5
@test jac [-0.50821 -0.740152
-0.199444 -0.906593
-0.586021 0.118173] rtol=1e-3

end

2 comments on commit 2fe7ec8

@MasonProtter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@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/116341

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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.1.3 -m "<description of version>" 2fe7ec803123f65cba7c7290c7bca0158b817630
git push origin v0.1.3

Please sign in to comment.