Setup
Using array-valued symbolics (@variables x[1:n]) with a function that indexes into the vector produces a KeyError from ReversePropagation when building a Contractor.
Minimal repro
using IntervalArithmetic, IntervalConstraintProgramming, Symbolics
f(x) = (x[1] - 1)^2 + (x[2] - 2)^2 # typical vector-argument style
@variables s[1:2]
sv = collect(s)
expr = f(sv)
C = Contractor(expr, sv) # ❌ ERROR
Error
ERROR: KeyError: key getindex not found
Stacktrace:
[1] getindex(h::Dict{Any, Any}, key::Any) @ ./dict.jl:477
[2] rev(f_val::Function, z::Num, x::Num, y::Num)
@ ReversePropagation ~/.../ReversePropagation/src/reverse_icp.jl:76
[3] rev(eq::SymbolicUtils.Code.Assignment, params::Vector{Any})
@ ReversePropagation ~/.../ReversePropagation/src/reverse_icp.jl:39
[...]
[17] Contractor(ex::Num, vars::Vector{Num}) @ IntervalConstraintProgramming/src/contractor.jl:10
Workaround
Define the variables as scalars and pass them explicitly, so no getindex nodes appear in the traced expression:
@variables s1 s2
sv = [s1, s2]
expr = f(sv) # Julia indexing on a Vector{Num} — no Symbolics getindex node
C = Contractor(expr, sv) # ✓
Suggestion
The friendly API is @variables s[1:n], so it would be nice if the Contractor either (a) supported getindex in the reverse-propagation dictionary, or (b) produced a clearer error message suggesting the scalar-variable workaround.
This is especially awkward for higher-dim problems (e.g. Lennard-Jones clusters with 6–9 variables) where enumerating scalar variables is verbose.
Environment
- IntervalConstraintProgramming v0.15.0
- ReversePropagation v0.4.2
- IntervalArithmetic v1.0.6
- Symbolics v6.58.0
- Julia 1.12.5
Setup
Using array-valued symbolics (
@variables x[1:n]) with a function that indexes into the vector produces aKeyErrorfromReversePropagationwhen building aContractor.Minimal repro
Error
Workaround
Define the variables as scalars and pass them explicitly, so no
getindexnodes appear in the traced expression:Suggestion
The friendly API is
@variables s[1:n], so it would be nice if the Contractor either (a) supportedgetindexin the reverse-propagation dictionary, or (b) produced a clearer error message suggesting the scalar-variable workaround.This is especially awkward for higher-dim problems (e.g. Lennard-Jones clusters with 6–9 variables) where enumerating scalar variables is verbose.
Environment