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

Integration with Measurements #1320

Open
GrigorySarnitsky opened this issue Oct 12, 2022 · 1 comment
Open

Integration with Measurements #1320

GrigorySarnitsky opened this issue Oct 12, 2022 · 1 comment

Comments

@GrigorySarnitsky
Copy link

GrigorySarnitsky commented Oct 12, 2022

This is a cross post from Measurements github (JuliaPhysics/Measurements.jl#129). I don't know what's going on, I post it here in case it uncovers some deficiencies of Zygote. In particular, what is the role of that missing method (see below)?

UPD The most concise example that gives the ``MethodError`:

using Zygote
using Measurements

(x -> 2 * x)'(2 ± 0.1)

I was trying out Zygote and was testing how it plays with Measurements. I have encountered a problem when I try to take a second derivative:

(√)''(2 ± 0.1)

This throws an exception:

MethodError: no method matching Float64(::Measurement{Float64})

At the same time (√)''(2) works just fine. I can fix this by defining

Float64(x::Measurement{Float64}) = Measurements.value(x)

I know little about Zygote and Measurements and I cannot tell what is going on and if this needs fixing and on which side.

ForwardDiff works correctly:

using ForwardDiff
using Measurements

ForwardDiff.derivative(x -> ForwardDiff.derivative(√, x), 2 ± 0.1)
@GrigorySarnitsky
Copy link
Author

The problem occurs with any raising to power operation, e.g.

(x -> x^2)''(2 ± 0.1)

also fails, but (x -> x*x)''(2 ± 0.1) works.

Also with first order derivatives sin'(2 ± 0.1) works, but not (x -> sin(5x))'(2 ± 0.1).

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

No branches or pull requests

1 participant