QuantEcon / QuantEcon/BasisMatrices.jl
Segfault with 0-degree polynomials and autodiff
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 33
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
I'm not sure if this is a problem with BasisMatrices or somewhere deeper in Julia, so apologies if this is not the right place. Anyway, on my computer (Julia 0.6.0) and also on JuliaBox (0.6.2), the following consistently segfaults:
using BasisMatrices
using ForwardDiff
fspace = Basis(ChebParams(1, 0.0, 1.0), ChebParams(5, 0.0, 1.0), ChebParams(1, 0.0, 1.0))
b = ones(length(fspace))
f = x -> funeval(b, fspace, x)
Df_x = ForwardDiff.gradient(f, 0.5*ones(3))
Using 0-th degree polynomials is kind of a hack, but the original idea was to use 0-degree / 1-coefficient polynomials as basis functions in some dimensions to impose the approximated function to be constant in those dimensions. This works when evaluated at standard float inputs for x, but apparently not when x is array of ForwardDiff duals (although interestingly it did work in two dimensions, only at three I came across the issue).
I'm attaching segfault output, according to which the crash happened somewhere in base linear algebra routines. However it's not consistent - for some other inputs the crash happened somewhere inside garbage collector instead, so who knows...
signal (11): Segmentation fault
while loading [...omitted...]/tmp_segflt.jl, in expression starting on line 8
macro expansion at ./linalg/generic.jl:9 [inlined]
macro expansion at ./simdloop.jl:73 [inlined]
generic_scale! at ./linalg/generic.jl:8
evalbasex! at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:183
evalbasex at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:202
evalbase at [...omitted...]/.julia/v0.6/BasisMatrices/src/cheb.jl:119
Type at [...omitted...]/.julia/v0.6/BasisMatrices/src/basis_structure.jl:231
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:197
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:152 [inlined]
funeval at [...omitted...]/.julia/v0.6/BasisMatrices/src/interp.jl:152
unknown function (ip: 0x7fc3a0d607d7)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
#1 at [...omitted...]/tmp_segflt.jl:7
unknown function (ip: 0x7fc3a0d5a212)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
vector_mode_gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:96 [inlined]
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:17
unknown function (ip: 0x7fc3a0d593ed)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:15
unknown function (ip: 0x7fc3a0d591ed)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
gradient at [...omitted...]/.julia/v0.6/ForwardDiff/src/gradient.jl:15
unknown function (ip: 0x7fc3a0d572b6)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:75
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:242
eval_body at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:543
jl_interpret_toplevel_thunk at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:692
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:592
jl_parse_eval_all at /home/centos/buildbot/slave/package_tarball64/build/src/ast.c:873
jl_load at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:616
include_from_node1 at ./loading.jl:569
unknown function (ip: 0x7fc3b54ddb1b)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
include at ./sysimg.jl:14
unknown function (ip: 0x7fc3b538286b)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
do_call at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:75
eval at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:242
jl_interpret_toplevel_expr at /home/centos/buildbot/slave/package_tarball64/build/src/interpreter.c:34
jl_toplevel_eval_flex at /home/centos/buildbot/slave/package_tarball64/build/src/toplevel.c:577
jl_toplevel_eval_in at /home/centos/buildbot/slave/package_tarball64/build/src/builtins.c:496
eval at ./boot.jl:235
unknown function (ip: 0x7fc3b54a739f)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7fc3b55151cf)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7fc3a0d4f2af)
jl_call_fptr_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:339 [inlined]
jl_call_method_internal at /home/centos/buildbot/slave/package_tarball64/build/src/julia_internal.h:358 [inlined]
jl_apply_generic at /home/centos/buildbot/slave/package_tarball64/build/src/gf.c:1933
jl_apply at /home/centos/buildbot/slave/package_tarball64/build/src/julia.h:1424 [inlined]
start_task at /home/centos/buildbot/slave/package_tarball64/build/src/task.c:267
unknown function (ip: 0xffffffffffffffff)
Allocations: 6918720 (Pool: 6916942; Big: 1778); GC: 12
Segmentation fault
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided Julia 0.6 example, then inspect BasisMatrices/src/cheb.jl around evalbasex! and evalbasex, followed by basis_structure.jl and interp.jl as shown in the stack trace. Compare ordinary Float64 evaluation with ForwardDiff dual inputs and varying dimensions; done means the three-dimensional gradient no longer segfaults and the regression is covered by a test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100