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

Unable to interpolate parameters when using @parameters within DSL #692

Closed
TorkelE opened this issue Sep 26, 2023 · 3 comments
Closed

Unable to interpolate parameters when using @parameters within DSL #692

TorkelE opened this issue Sep 26, 2023 · 3 comments

Comments

@TorkelE
Copy link
Member

TorkelE commented Sep 26, 2023

I think this is supposed to be a correct syntax?

p_stored = :p
rn = @reaction_network begin
    @parameters $(p_stored)
    (p, d), 0 <--> X
end

it returns a

ERROR: LoadError: AssertionError: @parameters expects a tuple of expressions or an expression of a tuple (`@parameters x y z(t) v[1:3] w[1:2,1:4]` or `@parameters x y z(t) v[1:3] w[1:2,1:4] k=1.0`)
Stacktrace:
  [1] _parse_vars(macroname::Symbol, type::Type, x::Vector{Any}, transform::Function)
    @ Symbolics ~/.julia/packages/Symbolics/3ueSK/src/variable.jl:136
  [2] _parse_vars
    @ ~/.julia/packages/Symbolics/3ueSK/src/variable.jl:82 [inlined]
  [3] extract_syms(opts::Dict{Symbol, Expr}, vartype::Symbol)
    @ Catalyst ~/.julia/dev/Catalyst/src/reaction_network.jl:469
...

(I have checked on the master branch)

The problem is in this function:

function extract_syms(opts, vartype::Symbol)
    if haskey(opts, vartype)
        ex = opts[vartype]
        vars = Symbolics._parse_vars(vartype, Real, ex.args[3:end])
        syms = Vector{Union{Symbol, Expr}}(vars.args[end].args)
    else
        syms = Union{Symbol, Expr}[]
    end
    return syms
end

where ex.args[3:end] becomes $(Expr(:escape, :p_stored)))].

There is also weird stuff going on a deeper level. E.g. shouldn't

p_stored = :p
@parameters $(p_stored)
p

work? Here, the first two lines is fin,e but the last gives ERROR: UndefVarError: p not defined.

@isaacsas
Copy link
Member

Ahh, right there is no reason to interpolate into @parameters in the DSL since you are expected to just create the parameter externally in that case and then interpolate the symbolic itself into the reaction that uses it.

In your example the symbolic is the first entry in the vector @parameters returns, but it isn't loaded into scope:

julia> a = :b
:b

julia> pv = @parameters $a
1-element Vector{Num}:
 b

julia> pv[1]
b

That is fine and how it has always worked. So if you can match that behavior with the macro outside the DSL we are good. Inside the DSL we don't need interpolation since we can just require the parameter to have been created outside and the symbolic interpolated in.

@isaacsas
Copy link
Member

I’m going to close this since there isn’t any issue that I can see.

@TorkelE
Copy link
Member Author

TorkelE commented Sep 26, 2023

agree

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