# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
import inspect
import textwrap
[docs]
class ApplicationError(Exception):
"""
An exception used when an external application generates an error.
"""
pass
[docs]
class PyomoException(Exception):
"""
Exception class for other Pyomo exceptions to inherit from,
allowing Pyomo exceptions to be caught in a general way
(e.g., in other applications that use Pyomo).
"""
pass
[docs]
class DeferredImportError(ImportError):
"""This exception is raised when something attempts to access a module
that was imported by :py:func:`.attempt_import`, but the module
import failed.
"""
pass
[docs]
class DeveloperError(PyomoException, NotImplementedError):
"""
Exception class used to throw errors that result from Pyomo
programming errors, rather than user modeling errors (e.g., a
component not declaring a 'ctype').
"""
def __str__(self):
return format_exception(
repr(super().__str__()),
prolog="Internal Pyomo implementation error:",
epilog="Please report this to the Pyomo Developers.",
exception=self,
)
[docs]
class InfeasibleConstraintException(PyomoException):
"""
Exception class used by Pyomo transformations to indicate
that an infeasible constraint has been identified (e.g. in
the course of range reduction).
"""
pass
[docs]
class IterationLimitError(PyomoException, RuntimeError):
"""A subclass of :py:class:`RuntimeError`, raised by an iterative method
when the iteration limit is reached.
TODO: solvers currently do not raise this exception, but probably
should (at least when non-normal termination conditions are mapped
to exceptions)
"""
[docs]
class IntervalException(PyomoException, ValueError):
"""
Exception class used for errors in interval arithmetic.
"""
pass
[docs]
class InvalidValueError(PyomoException, ValueError):
"""
Exception class used for value errors in compiled model representations
"""
pass
[docs]
class MouseTrap(PyomoException, NotImplementedError):
"""
Exception class used to throw errors for not-implemented functionality
that might be rational to support (i.e., we already gave you a cookie)
but risks taking Pyomo's flexibility a step beyond what is sane,
or solvable, or communicable to a solver, etc. (i.e., Really? Now you
want a glass of milk too?)
"""
def __str__(self):
return format_exception(
repr(super().__str__()),
prolog="Sorry, mouse, no cookies here!",
epilog="This is functionality we think may be rational to "
"support, but is not yet implemented (possibly due to developer "
"availability, complexity of edge cases, or general practicality "
"or tractability). However, please feed the mice: "
"pull requests are always welcome!",
exception=self,
)
[docs]
class NondifferentiableError(PyomoException, ValueError):
"""A Pyomo-specific ValueError raised for non-differentiable expressions"""
pass
[docs]
class TempfileContextError(PyomoException, IndexError):
"""A Pyomo-specific IndexError raised when attempting to use the
TempfileManager when it does not have a currently active context.
"""
pass
[docs]
class TemplateExpressionError(ValueError):
"""Special ValueError raised by getitem for template arguments
This exception is triggered by the Pyomo expression system when
attempting to get a member of an IndexedComponent using either a
TemplateIndex, or an expression containing a TemplateIndex.
Users should never see this exception.
"""
[docs]
def __init__(self, template, *args, **kwds):
self.template = template
super(TemplateExpressionError, self).__init__(*args, **kwds)