-
-
Notifications
You must be signed in to change notification settings - Fork 217
Small numeric error introduced in sparse jacobians #3554
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
Comments
Some potentially useful outputs: julia> J .- prob.f.jac(prob.u0, prob.p, 1.0)
13×13 SparseArrays.SparseMatrixCSC{Float64, Int64} with 1 stored entry:
-1.11022e-16 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ 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⋅ ⋅
1.5e-323 5.0e-323 ⋅ 9.4e-323 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1.5e-323 ⋅ 8.0e-323 ⋅ 1.0e-322 ⋅ ⋅ 1.43e-322 ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1.1e-322 1.3e-322 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1.1e-322 1.33e-322 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1.04e-322 1.24e-322 1.4e-322 1.5e-322 ⋅ ⋅ ⋅ ⋅ ⋅
1.5e-323 5.4e-323 8.0e-323 ⋅ ⋅ ⋅ ⋅ ⋅ 1.43e-322 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1.1e-322 ⋅ ⋅ 1.5e-322 ⋅ 1.7e-322 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.63e-322 ⋅ 1.4e-322 ⋅ ⋅
3.0e-323 5.4e-323 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1.0e-323 ⋅
⋅ ⋅ 7.4e-323 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 6.44477e-310 0.0
julia> ModelingToolkit.jacobian_sparsity(prob.f.sys)
13×13 SparseArrays.SparseMatrixCSC{Bool, Int64} with 38 stored entries:
1 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
1 ⋅ 1 ⋅ 1 ⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1 1 1 1 ⋅ ⋅ ⋅ ⋅ ⋅
1 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ 1 ⋅ ⋅ 1 ⋅ 1 ⋅ ⋅ ⋅
⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅ 1 ⋅ ⋅
1 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 ⋅
⋅ ⋅ 1 ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 1 1
|
Show |
Note that [4,4] is the hard zero, but it's entry 1 that's different so this is not due to #3535 related issues. This shows that is properly setting [4,4] as hard zero in the generated |
As pointed out by Chris, setting |
Some further debug info probd = ODEProblem(rn, u0, 0.0, ps; jac = true, sparse = false, cse=true)
j1cse = probd.f.jac(Jd, prob.u0, prob.p, 1.0)
j2cse = probd.f.jac(prob.u0, prob.p, 1.0)
probd = ODEProblem(rn, u0, 0.0, ps; jac = true, sparse = false, cse=false)
j1ncse = probd.f.jac(Jd, prob.u0, prob.p, 1.0)
j2ncse = probd.f.jac(prob.u0, prob.p, 1.0)
j1cse == j1ncse # true
j2cse == j2ncse # false prob = ODEProblem(rn, u0, 0.0, ps; jac = true, sparse = false, cse=true)
j1cse = probd.f.jac(J, prob.u0, prob.p, 1.0)
j2cse = probd.f.jac(prob.u0, prob.p, 1.0)
prob = ODEProblem(rn, u0, 0.0, ps; jac = true, sparse = false, cse=false)
j1ncse = probd.f.jac(J, prob.u0, prob.p, 1.0)
j2ncse = probd.f.jac(prob.u0, prob.p, 1.0)
j1cse == j1ncse # true
j2cse == j2ncse # true |
@AayushSabharwal in-place and out of place Jacobians aren't CSEing the same, and in-place looks like it doesn't change its numerics with CSE true/false, can you check the function expression and see if it's actually CSEing? |
I have a feeling that we might be putting out the same equation in both cases, but then LLVM's CSE pass might do something differently with sparse Jacobian allocations around and that might be a thing here, but we should check our expressions are exactly the same first |
I'm guessing this is due to ModelingToolkit.jl/src/systems/diffeqs/abstractodesystem.jl Lines 142 to 148 in 8e69dc9
Expr before CSE gets its hands on it, so CSE doesn't actually do anything.
|
Something that popped up. The actual error is really small, so probably not practically serious. Still might be worth investigating what is going one.
The text was updated successfully, but these errors were encountered: