Common Warnings/Errors
Warnings
W1001: Setting Var value not in domain
When setting Var
values (by either calling Var.set_value()
or setting the value
attribute), Pyomo will validate the
incoming value by checking that the value is in
the
Var.domain
. Any values not in the domain will generate this
warning:
>>> m = pyo.ConcreteModel()
>>> m.x = pyo.Var(domain=pyo.Integers)
>>> m.x = 0.5
WARNING (W1001): Setting Var 'x' to a value `0.5` (float) not in domain
Integers.
See also https://pyomo.readthedocs.io/en/stable/errors.html#w1001
>>> print(m.x.value)
0.5
Users can bypass all domain validation by setting the value using:
>>> m.x.set_value(0.75, skip_validation=True)
>>> print(m.x.value)
0.75
W1002: Setting Var value outside the bounds
When setting Var
values (by either calling set_value()
or setting the value
attribute), Pyomo will validate the
incoming value by checking that the value is within the range specified by
Var.bounds
. Any values outside the bounds will generate this
warning:
>>> m = pyo.ConcreteModel()
>>> m.x = pyo.Var(domain=pyo.Integers, bounds=(1, 5))
>>> m.x = 0
WARNING (W1002): Setting Var 'x' to a numeric value `0` outside the bounds
(1, 5).
See also https://pyomo.readthedocs.io/en/stable/errors.html#w1002
>>> print(m.x.value)
0
Users can bypass all domain validation by setting the value using:
>>> m.x.set_value(10, skip_validation=True)
>>> print(m.x.value)
10
Errors
E2001: Variable domains must be an instance of a Pyomo Set
Variable domains are always Pyomo Set
or RangeSet
objects. This includes global sets like Reals
, Integers
,
Binary
, NonNegativeReals
, etc., as well as model-specific
Set
instances. The Var.domain
setter will attempt to
convert assigned values to a Pyomo Set, with any failures leading to
this warning (and an exception from the converter):
>>> m = pyo.ConcreteModel()
>>> m.x = pyo.Var()
>>> m.x.domain = 5
Traceback (most recent call last):
...
TypeError: Cannot create a Set from data that does not support __contains__...
ERROR (E2001): 5 is not a valid domain. Variable domains must be an instance
of a Pyomo Set or convertable to a Pyomo Set.
See also https://pyomo.readthedocs.io/en/stable/errors.html#e2001