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

Error: no method matching value(Float64) #53

Closed
ejmeitz opened this issue Nov 10, 2023 · 5 comments
Closed

Error: no method matching value(Float64) #53

ejmeitz opened this issue Nov 10, 2023 · 5 comments

Comments

@ejmeitz
Copy link

ejmeitz commented Nov 10, 2023

Hello,

I'm trying to differentiate pair_potential_nounits:

function pair_potential_nounits(pot::StillingerWeberSilicon, dist_ij)   
    return Φ₂(pot.params.A, pot.params.B, ustrip(pot.params.ϵ), ustrip(pot.params.σ),
                 pot.params.p, pot.params.q, pot.params.a, dist_ij)
end
function Φ₂(A, B, ϵ, σ, p, q, a, rᵢⱼ)
    return A*ϵ*(B*((σ/rᵢⱼ)^p) - ((σ/rᵢⱼ)^q)) * exp/(rᵢⱼ-(a*σ)))
end

with:

vars = make_variables(:r, D)
r_norm = sqrt(sum(x -> x^2, vars))
pot2_symbolic = pair_potential_nounits(pot, r_norm)
H2_symbolic = hessian(pot2_symbolic, vars)
H2_exec = make_function(H2_symbolic, vars)

and the code immediately breaks on the call to pair_potential_nounits with the error trace below. It looks like it has something to do with the exponents p and q (which have values 4 and 0 respectively). How can I get around this issue without hard coding p and q? Seems like it should be possible since I've differentiated a similar function all be it with a constant exponent.

Stacktrace:
[1] ⋮ internal
@ FastDifferentiation
[2] ^(a::FastDifferentiation.Node, b::Float64)
@ FastDifferentiation C:\Users\ejmei.julia\packages\FastDifferentiation\YGbNU\src\Methods.jl:55
[3] Φ₂(A::Float64, B::Float64, ϵ::Float64, σ::Float64, p::Float64, q::Float64, a::Float64, rᵢⱼ::FastDifferentiation.Node)
@ ForceConstants C:\Users\ejmei\repos\ForceConstants\src\interactions\SW.jl:77
[4] pair_potential_nounits(pot::StillingerWeberSilicon{Quantity{Float64, 𝐋, …}, Unitful.FreeUnits{(Å,), 𝐋, …}, …}, dist_ij::FastDifferentiation.Node)
@ ForceConstants C:\Users\ejmei\repos\ForceConstants\src\interactions\SW.jl:52
[5] second_order_AD_test(sys::SuperCellSystem{3, Quantity{Float64, 𝐋, …}}, pot::StillingerWeberSilicon{Quantity{Float64, 𝐋, …}, Unitful.FreeUnits{(Å,), 𝐋, …}, …}, tol::Float64; r_cut::Quantity{Float64, 𝐋, …})
@ ForceConstants C:\Users\ejmei\repos\ForceConstants\src\autodiff_test.jl:49
[6] second_order_AD_test(sys::SuperCellSystem{3, Quantity{Float64, 𝐋, …}}, pot::StillingerWeberSilicon{Quantity{Float64, 𝐋, …}, Unitful.FreeUnits{(Å,), 𝐋, …}, …}, tol::Float64)
@ ForceConstants C:\Users\ejmei\repos\ForceConstants\src\autodiff_test.jl:44
[7] top-level scope
@ REPL[54]:1
Use err to retrieve the full stack trace.

brianguenter added a commit that referenced this issue Nov 10, 2023
@brianguenter
Copy link
Owner

brianguenter commented Nov 10, 2023

Found and fixed the bug. It's fixed in the main branch on my repo but not yet in the Julia code repository.

Can't guarantee that it will fix your problem because the example you sent isn't executable. But pretty sure it will.

If you send me an executable example I'll test it to make sure it works with your code.

@brianguenter
Copy link
Owner

brianguenter commented Nov 10, 2023

I just pushed the fix to the Julia Registry so you should be able to update to the latest version of FastDifferentiation, v 0.3.3, and your bug should be fixed. Let me know if this fixes the problem. If it does I'll close the issue.

@ejmeitz
Copy link
Author

ejmeitz commented Nov 11, 2023

I'll let you know, probably wont be able to test until Monday though. If you want to test, taking the derivative of the phi_2 function w.r.t. that r_norm variable I created and random positive things set for the constants should be equivalent to what my code is doing. The exponents p and q were 4 and 0 which are the two terms that actually matter for the derivative here.

I think this should let you test:

function phi_2(A, B, ϵ, σ, p, q, a, rᵢⱼ)
    return A*ϵ*(B*((σ/rᵢⱼ)^p) - ((σ/rᵢⱼ)^q)) * exp/(rᵢⱼ-(a*σ)))
end

vars = make_variables(:r, D)
r_norm = sqrt(sum(x -> x^2, vars))
pot2_symbolic = phi_2(1, 1, 2, 2, 4, 0, 1.2, r_norm)
H2_symbolic = hessian(pot2_symbolic, vars)
H2_exec = make_function(H2_symbolic, vars)

@brianguenter
Copy link
Owner

I set D=10 (not sure what size variable vector you were using) and ran your code. It executes without errors. I'm going to close this issue. If you run into problems when you test it on Monday reopen the issue.

@ejmeitz
Copy link
Author

ejmeitz commented Nov 21, 2023

I use D=3 this should be more than enough. Sorry for the late reply conference was busier than expected. The error is gone now. Thank you!

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

2 participants