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

(JOSS) Bug when running Example in the documentation #111

Closed
fb456 opened this issue Feb 2, 2024 · 10 comments · Fixed by #115
Closed

(JOSS) Bug when running Example in the documentation #111

fb456 opened this issue Feb 2, 2024 · 10 comments · Fixed by #115

Comments

@fb456
Copy link

fb456 commented Feb 2, 2024

When trying to run this part of the Example in the docs:

models = Dict(
    Gent => ComponentVector(μ=240e-3, Jₘ=80.0),
    EdwardVilgis => ComponentVector(Ns=0.10, Nc=0.20, α=0.001, η=0.001),
    NeoHookean => ComponentVector(μ=200e-3),
    NonaffineMicroSphere => ComponentVector(μ=0.292, N=22.5, p=1.471, U=0.744, q=0.1086),
    Beda => ComponentVector(C1=0.1237, C2=0.0424, C3=7.84e-5, K1=0.0168, α=0.9, β=0.68, ζ=3.015)
)

sol = Dict{Any, SciMLSolution}()
for (ψ, p₀) in models
    HEProblem = HyperelasticProblem(ψ(), treloar_data, p₀,  ad_type = AutoForwardDiff())
    sol[ψ] = solve(HEProblem, NelderMead())
end

I get the following error that arises from the Gent model:

ERROR: type NamedTuple has no field J_m
Stacktrace:
  [1] getproperty
    @ .\Base.jl:37 [inlined]
  [2] getindex(#unused#::ComponentArrays.Axis{(μ = 1, Jₘ = 2)}, s::Symbol)
    @ ComponentArrays C:\Users\...\.julia\packages\ComponentArrays\NoToB\src\axis.jl:158
  [3] _broadcast_getindex_evalf
    @ .\broadcast.jl:683 [inlined]
  [4] _broadcast_getindex
    @ .\broadcast.jl:656 [inlined]
  [5] (::Base.Broadcast.var"#31#32"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(getindex), Tuple{Tuple{ComponentArrays.Axis{(μ = 1, Jₘ = 2)}}, Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(ComponentArrays.getval), Tuple{Tuple{DataType}}}}}})(k::Int64)
    @ Base.Broadcast .\broadcast.jl:1088
  [6] ntuple
    @ .\ntuple.jl:48 [inlined]
  [7] copy
    @ .\broadcast.jl:1088 [inlined]
  [8] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(getindex), Tuple{Tuple{ComponentArrays.Axis{(μ = 1, Jₘ = 2)}}, Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(ComponentArrays.getval), Tuple{Tuple{DataType}}}}})
    @ Base.Broadcast .\broadcast.jl:873
  [9] #s39#55
    @ C:\Users\...\.julia\packages\ComponentArrays\NoToB\src\array_interface.jl:120 [inlined]
 [10] var"#s39#55"(::Any, index_fun::Any, x::Any, idx::Any)
    @ ComponentArrays .\none:0
 [11] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core .\boot.jl:602
 [12] getindex
    @ C:\Users\...\.julia\packages\ComponentArrays\NoToB\src\array_interface.jl:103 [inlined]
 [13] getindex(x::ComponentVector{Float64, Vector{Float64}, Tuple{ComponentArrays.Axis{(μ = 1, Jₘ = 2)}}}, idx::Symbol)
    @ ComponentArrays C:\Users\...\.julia\packages\ComponentArrays\NoToB\src\array_interface.jl:102
 [14] HyperelasticProblem(ψ::Gent{PrincipalValueForm}, test::HyperelasticUniaxialTest{Float64, Float64}, u0::ComponentVector{Float64, Vector{Float64}, Tuple{ComponentArrays.Axis{(μ = 1, J_m = 2)}}}; ad_type::AutoForwardDiff{nothing, Nothing}, loss::LossFunctions.L2DistLoss, lb::NamedTuple{(:μ, :Jₘ), Tuple{Float64, 
Float64}}, ub::Nothing, int::Nothing, lcons::Nothing, ucons::Nothing, sense::Nothing, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ HyperelasticsOptimizationExt C:\Users\...\.julia\packages\Hyperelastics\9siTz\ext\HyperelasticsOptimizationExt.jl:52
 [15] top-level scope
    @ c:\Users\...\he_review\src\he_review.jl:42

Changing "Jₘ" to "J_m" above hasn't helped for this. In either case, I think the issue arises from trying to access a named tuple like this in the HyperelasticsOptimizationExt.jl file:

(μ = 0.0, Jₘ = 55.46379855669157)[J_m]

The rest of the example runs fine when I remove the Gent model from the code.

@cfarm6 cfarm6 linked a pull request Feb 2, 2024 that will close this issue
@cfarm6 cfarm6 reopened this Feb 2, 2024
@cfarm6
Copy link
Member

cfarm6 commented Feb 2, 2024

@fb456 Thank you. I believe this has been fixed now. Please feel free to test any of the code in the documentation. There was an issue with the documentation not updating that has now been resolved.

@SotaYoshida
Copy link

I encountered the same error regarding J_m. Could you explain a bit more on how to fix this?
(I assume you are trying to update and deploy the documentation now though...)

@cfarm6
Copy link
Member

cfarm6 commented Feb 7, 2024

@SotaYoshida @fb456 It was an issue with code in the optimization wrapper and calculated the upper and lower bounds for some parameters. The package had originally had Jm instead of J_m. I just released a new version which should have fixed the issue. I had been testing on the dev branch instead of the release. If you update the package, you should received the fix.

@SotaYoshida
Copy link

@cfarm6 The problem is still not resolved.
If I understand correctly, NamedTuples in your code use both Jₘ and J_m and thereby conflict.
Finally, by unifying all the J_m in your package to Jₘ (and vice versa), I was able to run the sample code.

By the way, I suggest that the sample code be included in the test code and passed to CI.

@cfarm6
Copy link
Member

cfarm6 commented Feb 9, 2024

@SotaYoshida can you provide the output of import Pkg; Pkg.status()? The Hyperelastics version with the patch is v0.1.2.

The example code is being moved into the CI shortly.

@SotaYoshida
Copy link

SotaYoshida commented Feb 10, 2024

@cfarm6

can you provide the output of import Pkg; Pkg.status()?

Yes.

(Hyperelastics) pkg> status
Project Hyperelastics v0.1.2
Status `~/Downloads/Hyperelastics.jl-main/Project.toml`
  [47edcb42] ADTypes v0.2.6
  [b0b7db55] ComponentArrays v0.15.8
  [3a778109] ContinuumMechanicsBase v0.1.1
  [82cc6244] DataInterpolations v4.6.0
  [ffbed154] DocStringExtensions v0.9.3
  [de52edbc] Integrals v4.1.0
  [b82787f2] InverseLangevinApproximations v0.2.0
  [2ee39098] LabelledArrays v1.15.1
  [30fc2ffe] LossFunctions v0.11.1
⌃ [36348300] OptimizationOptimJL v0.1.14
  [65ce6f38] PackageExtensionCompat v1.0.2
  [1fd47b50] QuadGK v2.9.4
⌅ [731186ca] RecursiveArrayTools v3.3.3
  [189a3867] Reexport v1.2.2
⌃ [0bca4576] SciMLBase v2.15.2
  [276daf66] SpecialFunctions v2.3.1
  [09ab397b] StructArrays v0.6.17
  [37e2e46d] LinearAlgebra
  [10745b16] Statistics v1.9.0

In src/isotropic_incompressible_models.jl, both Jₘ and J_m is used.
https://github.com/TRACER-LULab/Hyperelastics.jl/blob/225d19321358214fc27b8e7162f3d72eabcf54cc/src/isotropic_incompressible_models.jl
As mentioned above, I believe unifying them into one or the other resolved the error.

@cfarm6
Copy link
Member

cfarm6 commented Feb 12, 2024

@SotaYoshida I have checked that they are unified in the latest release. The docs are generating and running the code without error. Can you try creating a clean environment with the latest version to see if the error persists?

@fb456
Copy link
Author

fb456 commented Feb 13, 2024

I confirm that I was able to run the example code without any errors using the latest release, in a clean environment.

@cfarm6
Copy link
Member

cfarm6 commented Feb 13, 2024

@fb456 Thank you.

@SotaYoshida Can you try the latest release in a clean environment? I think the issue should be resolved now.

@SotaYoshida
Copy link

@cfarm6 Yes. I succeeded to run the example code in the doc with a clean environment.
Sorry for bothering you. Now you can close the issue.

@cfarm6 cfarm6 closed this as completed Feb 14, 2024
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.

3 participants