Skip to content

Sparse ODE segfaults when RHS contains differentiated variable #3871

@hersle

Description

@hersle

Take this simple example:

using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t_nounits as t, D_nounits as D

@variables x(t) y(t)
@mtkcompile sys = System([
    D(x) ~ x * D(y)
    D(y) ~ x - y
], t)
prob = ODEProblem(sys, [x => 1.0, y => 0.0], (0.0, 1.0); jac = true, sparse = true)

sol = solve(prob, FBDF());
sol = solve(prob, FBDF());
sol = solve(prob, FBDF());
# ...

It segfaults after a few solves (the precise number required appears random):

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.  
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffab2845290 -- gc_mark_outrefs at C:/workdir/src\gc.c:2776 [inlined]
gc_mark_loop_serial_ at C:/workdir/src\gc.c:2938
in expression starting at none:0
gc_mark_outrefs at C:/workdir/src\gc.c:2776 [inlined]
gc_mark_loop_serial_ at C:/workdir/src\gc.c:2938
gc_mark_loop_serial at C:/workdir/src\gc.c:2961
gc_mark_loop at C:/workdir/src\gc.c:3143 [inlined]
_jl_gc_collect at C:/workdir/src\gc.c:3532
ijl_gc_collect at C:/workdir/src\gc.c:3893
maybe_collect at C:/workdir/src\gc.c:926 [inlined]
jl_gc_pool_alloc_inner at C:/workdir/src\gc.c:1319
jl_gc_pool_alloc_noinline at C:/workdir/src\gc.c:1386 [inlined] 
jl_gc_alloc_ at C:/workdir/src\julia_internal.h:523 [inlined]   
jl_gc_alloc at C:/workdir/src\gc.c:3946
_new_genericmemory_ at C:/workdir/src\genericmemory.c:56 [inlined]
jl_alloc_genericmemory at C:/workdir/src\genericmemory.c:99     
ijl_array_grow_end at C:/workdir/src\array.c:229
ijl_module_names at C:/workdir/src\module.c:1002
#unsorted_names#9 at .\reflection.jl:96 [inlined]
unsorted_names at .\reflection.jl:96 [inlined]
make_typealias at .\show.jl:624
show_typealias at .\show.jl:805
_show_type at .\show.jl:970
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_datatype at .\show.jl:1152
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
jfptr_show_50734.1 at C:\Users\herma\.julia\juliaup\julia-1.11.6+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
show_typeparams at .\show.jl:722
show_datatype at .\show.jl:1181
show_datatype at .\show.jl:1089 [inlined]
_show_type at .\show.jl:973
show at .\show.jl:965
print at .\strings\io.jl:35
print_to_string at .\strings\io.jl:148
string at .\strings\io.jl:189 [inlined]
treerender at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\trees.jl:103 [inlined]
treerender at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\trees.jl:98  
unknown function (ip: 000002cf5587309b)
treerender at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\trees.jl:61  
getvariables at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\trees.jl:297
unknown function (ip: 000002cf7e770ced)
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
jl_f__call_latest at C:/workdir/src\builtins.c:875
#invokelatest#2 at .\essentials.jl:1055 [inlined]
invokelatest at .\essentials.jl:1052 [inlined]
repl_getvariables_request at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\trees.jl:270
unknown function (ip: 000002cf7e73b344)
dispatch_msg at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\JSONRPC\src\typed.jl:68     
unknown function (ip: 000002cf7e73b1c4)
dispatch_msg at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\VSCodeServer.jl:109
macro expansion at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\VSCodeServer.jl:168 [inlined]
macro expansion at .\task.jl:498 [inlined]
#233 at c:\Users\herma\.vscode\extensions\julialang.language-julia-1.149.2\scripts\packages\VSCodeServer\src\VSCodeServer.jl:154
unknown function (ip: 000002cf7e73245b)
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
start_task at C:/workdir/src\task.c:1202
Allocations: 77026592 (Pool: 77024145; Big: 2447); GC: 38       

Can you reproduce? What is going on here?

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions