Skip to content

Latest commit

 

History

History
116 lines (82 loc) · 3.09 KB

errors.rst

File metadata and controls

116 lines (82 loc) · 3.09 KB

Common Warnings/Errors

>>> import pyomo.environ as pyo
.. py:currentmodule:: pyomo.environ


Warnings

W1001: Setting Var value not in domain

When setting :class:`Var` values (by either calling :meth:`Var.set_value()` or setting the :attr:`value` attribute), Pyomo will validate the incoming value by checking that the value is in the :attr:`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 :py:class:`Var` values (by either calling :meth:`set_value()` or setting the :attr:`value` attribute), Pyomo will validate the incoming value by checking that the value is within the range specified by :attr:`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 :class:`Set` or :class:`RangeSet` objects. This includes global sets like Reals, Integers, Binary, NonNegativeReals, etc., as well as model-specific :class:`Set` instances. The :attr:`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

Exceptions