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

Problem with external constant for the macro @constraint #154

Open
newptcai opened this issue Dec 14, 2019 · 7 comments
Open

Problem with external constant for the macro @constraint #154

newptcai opened this issue Dec 14, 2019 · 7 comments

Comments

@newptcai
Copy link

I just tried the example in the document. This is what I get.

julia> a = 3;
julia> C = @constraint x^2 + y^2 <= $a
ERROR: LoadError: TypeError: in Interval, in T, expected T<:Real, got Type{Expr}
Stacktrace:
 [1] ..(::Float64, ::Expr) at /home/xinca341/.julia/packages/IntervalArithmetic/W4cqS/src/intervals/intervals.jl:136
 [2] parse_comparison(::Expr) at /home/xinca341/.julia/packages/IntervalConstraintProgramming/ta93g/src/separator.jl:88
 [3] @constraint(::LineNumberNode, ::Module, ::Expr, ::Any) at /home/xinca341/.julia/packages/IntervalConstraintProgramming/ta93g/src/separator.jl:185 (repeats 2 times)
in expression starting at REPL[57]:1
@dpsanders
Copy link
Member

Oops, that seems to have broken at some point "recently".
cc @Yashcodes

@dpsanders
Copy link
Member

Try without the variable:

C = @constraint x^2 + y^2 <= 3

@dpsanders
Copy link
Member

Here's an alternative:

julia> using ModelingToolkit

julia> @variables x y
(x, y)

julia> a = 3
3

julia> C = Separator(x^2 + y^2 < a)
Separator:
  - variables: x, y
  - expression: x ^ 2 + y ^ 2 == [-∞, 3]

@newptcai
Copy link
Author

The alternative works, but is this a bug?

julia> C = Separator(x^2+y^2<=a)
ERROR: MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:600
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:600
  iterate(::ExponentialBackOff) at error.jl:218
  ...
Stacktrace:
 [1] indexed_iterate(::Nothing, ::Int64) at ./tuple.jl:66
 [2] Separator(::Array{Any,1}, ::Operation) at /home/xinca341/.julia/packages/IntervalConstraintProgramming/ta93g/src/separator.jl:199
 [3] Separator(::Operation) at /home/xinca341/.julia/packages/IntervalConstraintProgramming/ta93g/src/separator.jl:203
 [4] top-level scope at REPL[77]:1

@dpsanders
Copy link
Member

That is a detail of ModelingToolkit.jl:
SciML/ModelingToolkit.jl#101

For now use < instead of <=.

@lucaferranti
Copy link
Member

With the @constraint macro, the interpolation works if the variable is on the left-hand side. The following seems to work on 1.4 and 1.5

julia> a = 3
3

julia> C = @constraint x^2 + y^2 - $a <= 0
Separator:
  - variables: x, y
  - expression: (x ^ 2 + y ^ 2) - 3 ∈ [-∞, 0]

lucaferranti added a commit to lucaferranti/IntervalConstraintProgramming.jl that referenced this issue Mar 4, 2021
@hisacro
Copy link

hisacro commented Dec 13, 2023

With the @constraint macro, the interpolation works if the variable is on the left-hand side. The following seems to work on 1.4 and 1.5

julia> a = 3
3

julia> C = @constraint x^2 + y^2 - $a <= 0
Separator:
  - variables: x, y
  - expression: (x ^ 2 + y ^ 2) - 3 ∈ [-∞, 0]

this stopped working on julia 1.9

a = 3
C = @constraint x^2 + y^2 - $a <= 0

ERROR: UndefVarError: `a` not defined
Stacktrace:
 [1] top-level scope
   @ ~/.julia/packages/IntervalConstraintProgramming/HiqgO/src/separator.jl:127

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.

5 participants