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

"Adding parameters" example gives error #417

Open
natevmp opened this issue Oct 7, 2024 · 2 comments
Open

"Adding parameters" example gives error #417

natevmp opened this issue Oct 7, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@natevmp
Copy link

natevmp commented Oct 7, 2024

Describe the bug 🐞

Running the "Adding parameters" example script of the docs on Julia v1.10.4, with current versions of ModelingToolkit v9.42.0 and MethodOfLines v0.11.5 gives an error on the discretization step.

Minimal Reproducible Example 👇

using ModelingToolkit, MethodOfLines, OrdinaryDiffEq, DomainSets

@parameters t x
@parameters Dn, Dp
@variables u(..) v(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2

eqs  = [Dt(u(t,x)) ~ Dn * Dxx(u(t,x)) + u(t,x)*v(t,x),
        Dt(v(t,x)) ~ Dp * Dxx(v(t,x)) - u(t,x)*v(t,x)]
bcs = [u(0,x) ~ sin(pi*x/2),
       v(0,x) ~ sin(pi*x/2),
       u(t,0) ~ 0.0, Dx(u(t,1)) ~ 0.0,
       v(t,0) ~ 0.0, Dx(v(t,1)) ~ 0.0]

domains = [t  Interval(0.0,1.0),
           x  Interval(0.0,1.0)]

@named pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)],[Dn=>0.5, Dp=>2])

discretization = MOLFiniteDifference([x=>0.1],t)

prob = discretize(pdesys,discretization) # This gives an ODEProblem since it's time-dependent
# the error occurs on the above line

sol = solve(prob,Tsit5())

discrete_x = sol[x]
discrete_t = sol[t]

solu = sol[u(t, x)]
solv = sol[v(t, x)]

Error & Stacktrace ⚠️

ERROR: MethodError: no method matching hasmetadata(::Pair{Num, Float64}, ::Type{Symbolics.VariableDefaultValue})

Closest candidates are:
  hasmetadata(::Num, ::Any)
   @ Symbolics ~/.julia/packages/Symbolics/rtkf9/src/Symbolics.jl:188
  hasmetadata(::Complex{Num}, ::Any)
   @ Symbolics ~/.julia/packages/Symbolics/rtkf9/src/Symbolics.jl:188
  hasmetadata(::SymbolicUtils.Symbolic, ::Any)
   @ SymbolicUtils ~/.julia/packages/SymbolicUtils/ij6YM/src/types.jl:631

Stacktrace:
 [1] hasdefault(v::Pair{Num, Float64})
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/5OzIt/src/utils.jl:237
 [2] collect_defaults!
   @ ~/.julia/packages/ModelingToolkit/5OzIt/src/utils.jl:255 [inlined]
 [3] process_variables!(var_to_name::Dict{Any, Any}, defs::Dict{Any, Any}, vars::Vector{Pair{Num, Float64}})
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/5OzIt/src/utils.jl:248
 [4] ODESystem(deqs::Vector{…}, iv::Num, dvs::Vector{…}, ps::Vector{…}; controls::Vector{…}, observed::Vector{…}, systems::Vector{…}, tspan::Nothing, name::Symbol, default_u0::Dict{…}, default_p::Dict{…}, defaults::Dict{…}, guesses::Dict{…}, initializesystem::Nothing, initialization_eqs::Vector{…}, schedule::Nothing, connector_type::Nothing, preface::Nothing, continuous_events::Nothing, discrete_events::Nothing, parameter_dependencies::Vector{…}, checks::Bool, metadata::MethodOfLines.MOLMetadata{…}, gui_metadata::Nothing, is_dde::Nothing)
   @ ModelingToolkit ~/.julia/packages/ModelingToolkit/5OzIt/src/systems/diffeqs/odesystem.jl:250
 [5] generate_system(disc_state::PDEBase.EquationState, s::MethodOfLines.DiscreteSpace{…}, u0::Vector{…}, tspan::Tuple{…}, metadata::MethodOfLines.MOLMetadata{…}, disc::MOLFiniteDifference{…})
   @ PDEBase ~/.julia/packages/PDEBase/EWM3U/src/discretization_state.jl:40
 [6] symbolic_discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…})
   @ PDEBase ~/.julia/packages/PDEBase/EWM3U/src/symbolic_discretize.jl:89
 [7] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…}; analytic::Nothing, kwargs::@Kwargs{})
   @ PDEBase ~/.julia/packages/PDEBase/EWM3U/src/discretization_state.jl:57
 [8] discretize(pdesys::PDESystem, discretization::MOLFiniteDifference{…})
   @ PDEBase ~/.julia/packages/PDEBase/EWM3U/src/discretization_state.jl:54
 [9] top-level scope
   @ ~/Library/CloudStorage/OneDrive-QueenMary,UniversityofLondon/GitHub/MicroscopicGradientDynamics/test/parameterExample.jl:24
Some type information was truncated. Use `show(err)` to see complete types.

Environment:

  • Output of using Pkg; Pkg.status()
Status `~/Library/CloudStorage/OneDrive-QueenMary,UniversityofLondon/GitHub/MicroscopicGradientDynamics/Project.toml`
  [13f3f980] CairoMakie v0.12.13
  [5b8099bc] DomainSets v0.7.14
  [94925ecb] MethodOfLines v0.11.5
  [961ee093] ModelingToolkit v9.42.0
  [1dea7af3] OrdinaryDiffEq v6.89.0
  • Output of versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M3
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 4 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
@natevmp natevmp added the bug Something isn't working label Oct 7, 2024
@sathvikbhagavan
Copy link
Member

Hello,

Can you refer to the latest dev docs here - https://docs.sciml.ai/MethodOfLines/dev/tutorials/params/
The issue is

@named pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)],[Dn=>0.5, Dp=>2])

is not correct. Instead it should be:

@named pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)],[Dn, Dp]; defaults = Dict(Dn => 0.5, Dp => 2))

which is fixed in master.

Due to the issues in tagbot, stable docs has not been released for new releases.

@natevmp
Copy link
Author

natevmp commented Oct 14, 2024

Great. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants