Giter VIP home page Giter VIP logo

Comments (8)

ChrisRackauckas avatar ChrisRackauckas commented on July 2, 2024

On v1.8 with the latest Integrals this outputs:

julia > dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
(-0.9092974268256817, -0.27941549819892586, -0.4091435516769757)

from integrals.jl.

nelslind avatar nelslind commented on July 2, 2024

I'm having the same issue in Julia 1.8.5. What version of Julia and versions of Zygote and Integrals was this working under?

from integrals.jl.

ChrisRackauckas avatar ChrisRackauckas commented on July 2, 2024

The example is incorrect. Corrected:

using Integrals, Zygote
f(x, p) = sum(sin.(p * x))
lb = 1.0
ub = 3.0
p = 2.0
function testf(lb, ub, p)
    prob = IntegralProblem(f, lb, ub, p)
    sin(solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1])
end
dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)

The difference is f(x, p) = sum(sin.(p * x)) instead of f(x, p) = sum(sin.(p[1] * x)). The OP's original example fails because p[1] fails because p is a scalar, not a vector. I don't know why Zygote throws that weird error, but that's an issue for Zygote.

If you have an example that' supposed to work, please open a new issue.

from integrals.jl.

Moelf avatar Moelf commented on July 2, 2024

? that's the problem though

julia> p = [2.0]
1-element Vector{Float64}:
 2.0

julia> function testf(lb, ub, p)
           prob = IntegralProblem(f, lb, ub, p)
           sin(solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1])
       end
testf (generic function with 1 method)

julia> dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
ERROR: BoundsError: attempt to access 0-element Vector{Any} at index []
Stacktrace:
  [1] throw_boundserror(A::Vector{Any}, I::Tuple{})
    @ Base ./abstractarray.jl:744
  [2] checkbounds
    @ ./abstractarray.jl:709 [inlined]
  [3] _getindex
    @ ./abstractarray.jl:1326 [inlined]
  [4] getindex
    @ ./abstractarray.jl:1294 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/Zygote/SuKWp/src/lib/lib.jl:314 [inlined]
  [6] (::Zygote.Jnew{Base.MethodList, Vector{Any}, false})(Δ::Nothing)
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/lib/lib.jl:308

also Zygote can handle this:

julia> p = [2.0]
1-element Vector{Float64}:
 2.0

julia> Zygote.gradient(f, 30, p)
(-1.9048259608303126, [-28.57238941245469])

julia> p = 2.0
2.0

julia> Zygote.gradient(f, 30, p)
(-1.9048259608303126, -28.57238941245469)

from integrals.jl.

nelslind avatar nelslind commented on July 2, 2024

Hi All, Thanks for the help with this.

Here is a simple example:

`
foo(x, p) = p + x

lb = 1.0
ub = 3.0
p = 2.0

function testf(lb, ub, p)
prob = IntegralProblem(foo, lb, ub, p)
solve(prob, QuadGKJL(), reltol = 1e-3, abstol = 1e-3)[1]
end

dlb1, dub1, dp1 = Zygote.gradient(testf, lb, ub, p)
`

I get "ERROR: BoundsError: attempt to access 0-element Vector{Any} at index []"

from integrals.jl.

nelslind avatar nelslind commented on July 2, 2024

Also, the example at

https://docs.juliahub.com/Integrals/QIwht/3.1.1/tutorials/differentiating_integrals/

creates the same error for Zygote, but works fine for ForwardDiff and and FiniteDiff (I had to replace CubaCuhre with HCubatureJL). This is true using either Integrals 3.1.1 (which is the version listed at that page) and 3.7.

from integrals.jl.

ChrisRackauckas avatar ChrisRackauckas commented on July 2, 2024

@ArnoStrouwen does that already have an issue?

from integrals.jl.

ArnoStrouwen avatar ArnoStrouwen commented on July 2, 2024

I think it is this issue #99?

from integrals.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.