E-TE0612 — Unsupported argument type for is_same
Error Type |
|
|---|---|
Phase |
calling |
Python exception |
|
Message
`is_same` does not support values of type `{type_name}`.
Possible fix: pass JijModeling objects (such as `Problem`, `Constraint`, placeholders, decision variables, or expressions) or iterables of them.
({type_name} is the Python type shared by both arguments)
Cause
Both arguments to jm.is_same have the same Python type, but values of that type cannot be compared by is_same: they are neither JijModeling objects nor iterables.
jm.is_same first tries to compare its arguments as two JijModeling objects of the same kind — where numbers, strings, booleans, and tuples, lists, or dicts of such values also count as expressions — and then falls back to consuming both arguments as iterables and comparing them element by element.
Values that fit neither interpretation, such as None, a function taking no arguments, or objects from unrelated libraries, trigger this error; for example jm.is_same(None, None).
Fix
Pass JijModeling objects (or iterables of them) to jm.is_same, and compare everything else with Python’s own ==:
import jijmodeling as jm
problem1 = jm.Problem("p")
problem2 = jm.Problem("p")
a = problem1.Placeholder("a", dtype=float)
b = problem2.Placeholder("a", dtype=float)
assert jm.is_same(a, b)
If one of the values can be None, guard the call, for example x is not None and jm.is_same(x, y).