Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “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? Sign in to your account

Another problem with isless #153

Closed
SouthEndMusic opened this issue Aug 7, 2024 · 1 comment · Fixed by #161
Closed

Another problem with isless #153

SouthEndMusic opened this issue Aug 7, 2024 · 1 comment · Fixed by #161

Comments

@SouthEndMusic
Copy link
Contributor

As a complement to #152, with non-evenly distributed t:

using SparseConnectivityTracer: TracerLocalSparsityDetector, jacobian_sparsity
using DataInterpolations: LinearInterpolation
detector = TracerLocalSparsityDetector()
A = LinearInterpolation([0.0, 2.0, 10.0], [0.0, 2.0, 3.0])

function f!(output, input)
    output .= A.(input)
end

input = rand(5)
output = zero(input)

jacobian_sparsity(f!, output, input, detector)

this gives

ERROR: MethodError: isless(::SparseConnectivityTracer.Dual{Float64, SparseConnectivityTracer.GradientTracer{SparseConnectivityTracer.IndexSetGradientPattern{Int64, BitSet}}}, ::Float64) is ambiguous.

Candidates:
  isless(dx::D, y::Real) where D<:SparseConnectivityTracer.Dual
    @ SparseConnectivityTracer path\to\.julia\packages\SparseConnectivityTracer\tpAG2\src\overloads\dual.jl:25
  isless(x::Real, y::AbstractFloat)
    @ Base operators.jl:178

Possible fix, define
  isless(::D, ::AbstractFloat) where D<:SparseConnectivityTracer.Dual

Stacktrace:
  [1] lt(o::Base.Order.ForwardOrdering, a::SparseConnectivityTracer.Dual{…}, b::Float64)
    @ Base.Order .\ordering.jl:117
  [2] bracketstrictlymontonic
    @ path\to\.julia\packages\FindFirstFunctions\2w5qZ\src\FindFirstFunctions.jl:179 [inlined]
  [3] searchsortedlastcorrelated
    @ path\to\.julia\packages\FindFirstFunctions\2w5qZ\src\FindFirstFunctions.jl:266 [inlined]
  [4] get_idx(A::LinearInterpolation{…}, t::SparseConnectivityTracer.Dual{…}, iguess::Int64; lb::Int64, ub_shift::Int64, idx_shift::Int64, side::Symbol)
    @ DataInterpolations path\to\.julia\packages\DataInterpolations\i1xgb\src\interpolation_utils.jl:133
  [5] get_idx
    @ path\to\.julia\packages\DataInterpolations\i1xgb\src\interpolation_utils.jl:120 [inlined]
  [6] _interpolate(A::LinearInterpolation{…}, t::SparseConnectivityTracer.Dual{…}, iguess::Int64)
    @ DataInterpolations path\to\.julia\packages\DataInterpolations\i1xgb\src\interpolation_methods.jl:19
  [7] _interpolate
    @ path\to\.julia\packages\DataInterpolations\i1xgb\src\interpolation_methods.jl:5 [inlined]
  [8] AbstractInterpolation
    @ path\to\.julia\packages\DataInterpolations\i1xgb\src\DataInterpolations.jl:24 [inlined]
  [9] _broadcast_getindex_evalf
    @ .\broadcast.jl:709 [inlined]
 [10] _broadcast_getindex
    @ .\broadcast.jl:682 [inlined]
 [11] getindex
    @ .\broadcast.jl:636 [inlined]
 [12] macro expansion
    @ .\broadcast.jl:1004 [inlined]
 [13] macro expansion
    @ .\simdloop.jl:77 [inlined]
 [14] copyto!
    @ .\broadcast.jl:1003 [inlined]
 [15] copyto!
    @ .\broadcast.jl:956 [inlined]
 [16] materialize!
    @ .\broadcast.jl:914 [inlined]
 [17] materialize!(dest::Vector{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast .\broadcast.jl:911
 [18] f!(output::Vector{SparseConnectivityTracer.Dual{…}}, input::Vector{SparseConnectivityTracer.Dual{…}})
    @ Main path\to\Ribasim_development\runners\runner.jl:35
 [19] trace_function(::Type{SparseConnectivityTracer.Dual{…}}, f!::typeof(f!), y::Vector{Float64}, x::Vector{Float64})
    @ SparseConnectivityTracer path\to\.julia\packages\SparseConnectivityTracer\tpAG2\src\interface.jl:49
 [20] _local_jacobian_sparsity(f!::Function, y::Vector{…}, x::Vector{…}, ::Type{…})
    @ SparseConnectivityTracer path\to\.julia\packages\SparseConnectivityTracer\tpAG2\src\interface.jl:94
 [21] jacobian_sparsity(f!::Function, y::Vector{…}, x::Vector{…}, ::TracerLocalSparsityDetector{…})
    @ SparseConnectivityTracer path\to\.julia\packages\SparseConnectivityTracer\tpAG2\src\adtypes.jl:122
 [22] top-level scope
    @ path\to\Ribasim_development\runners\runner.jl:41
Some type information was truncated. Use `show(err)` to see complete types.
@adrhill
Copy link
Owner

adrhill commented Aug 8, 2024

Thanks a lot! Looks like the overload of isless(x::Dual, y::Real) added in #149 isn't specific enough for input types and we also need an additional overload on isless(x::Dual, y::AbstractFloat).

Maybe we should run our Dual tests on more diverse input types to catch this type of problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants