Skip to content

Commit c9b178f

Browse files
refactor: make @constants create non-tunable parameters
1 parent 034b8ee commit c9b178f

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

src/constants.jl

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import SymbolicUtils: symtype, term, hasmetadata, issym
2-
struct MTKConstantCtx end
3-
4-
isconstant(x::Num) = isconstant(unwrap(x))
51
"""
62
Test whether `x` is a constant-type Sym.
73
"""
84
function isconstant(x)
95
x = unwrap(x)
10-
x isa Symbolic && getmetadata(x, MTKConstantCtx, false)
6+
x isa Symbolic && !getmetadata(x, VariableTunable, true)
117
end
128

139
"""
@@ -16,12 +12,11 @@ end
1612
Maps the parameter to a constant. The parameter must have a default.
1713
"""
1814
function toconstant(s)
19-
hasmetadata(s, Symbolics.VariableDefaultValue) ||
20-
throw(ArgumentError("Constant `$(s)` must be assigned a default value."))
21-
setmetadata(s, MTKConstantCtx, true)
15+
s = toparam(s)
16+
setmetadata(s, VariableTunable, false)
2217
end
2318

24-
toconstant(s::Num) = wrap(toconstant(value(s)))
19+
toconstant(s::Union{Num, Symbolics.Arr}) = wrap(toconstant(value(s)))
2520

2621
"""
2722
$(SIGNATURES)
@@ -36,15 +31,3 @@ macro constants(xs...)
3631
xs,
3732
toconstant) |> esc
3833
end
39-
40-
"""
41-
Substitute all `@constants` in the given expression
42-
"""
43-
function subs_constants(eqs)
44-
consts = collect_constants(eqs)
45-
if !isempty(consts)
46-
csubs = Dict(c => getdefault(c) for c in consts)
47-
eqs = substitute(eqs, csubs)
48-
end
49-
return eqs
50-
end

0 commit comments

Comments
 (0)