E-TE0610 — Invalid dictionary key
Error Type |
|
|---|---|
Phase |
building a model from Python |
Python exception |
|
Message
A dictionary key must be an integer or a string, but got `{type_name}`
({type_name} is the Python type of the rejected key component)
Cause
A concrete subscript component that must identify one entry of an indexed variable is neither an integer nor a string.
This is raised when a tuple key in a fixed_variables dictionary contains such a component — for example fixed_variables={"z": {(0, 3.5): 1.0}} — or when an element of the subscript argument of Compiler.get_decision_variable_by_name is of another type.
Fix
Use only integers and strings as subscript components:
compiler = jm.Compiler.from_problem(
problem,
instance_data,
fixed_variables={"z": {(0, 1): 1.0, ("label", 2): 0.0}},
)
compiler.get_decision_variable_by_name("z", [0, 1])
If the subscripts come from another library (for example NumPy indices or data-frame labels), convert them to plain values with int(...) or str(...) before building the key.