Skip to content

Commit

Permalink
Merge pull request #3 from Pyomo/main
Browse files Browse the repository at this point in the history
Update doe-develop1 with pyomo/main
  • Loading branch information
jialuw96 authored Oct 4, 2021
2 parents 51d8ad5 + f0bc6b5 commit 5133766
Show file tree
Hide file tree
Showing 85 changed files with 2,643 additions and 915 deletions.
4 changes: 2 additions & 2 deletions .coin-or/projDesc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ Carl D. Laird, Chair, Pyomo Management Committee, claird at andrew dot cmu dot e
Use explicit overrides to disable use of automated
version reporting.
-->
<stableVersionNumber>6.1.1</stableVersionNumber>
<releaseNumber>6.1.1</releaseNumber>
<stableVersionNumber>6.1.2</stableVersionNumber>
<releaseNumber>6.1.2</releaseNumber>

</developmentStatus>

Expand Down
4 changes: 3 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ omit =
# The [run] section must be at the end, as the build harness will add a
# "data_file" directive to the end of this file.
[run]
concurrency = multiprocessing,thread
concurrency =
multiprocessing
thread
parallel = True
source =
pyomo
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
Pyomo CHANGELOG
===============

-------------------------------------------------------------------------------
Pyomo 6.1.2 20 Aug 2021
-------------------------------------------------------------------------------

- General
- Add test for missing/extra __init__.py files (#2090)
- Update deprecation warnings to only be emitted once per context (#2095)
- Core
- Replace Set.card() with Set.at() (#2096)
- DAE
- Remove use of OrderedSet.__getitem__ from contset.py (#2091)
- Contributed Packages
- APPSI: Build/install APPSI extension outside of source tree (#2092)
- MindtPy: Support gurobi_persistent in LP/NLP-based B&B algorithm (#2071)

-------------------------------------------------------------------------------
Pyomo 6.1.1 17 Aug 2021
-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
We are pleased to announce the release of Pyomo 6.1.1.
We are pleased to announce the release of Pyomo 6.1.2.

Pyomo is a collection of Python software packages that supports a
diverse set of optimization capabilities for formulating and analyzing
Expand Down
1 change: 1 addition & 0 deletions doc/OnlineDocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# -- Options for intersphinx ---------------------------------------------

intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'matplotlib': ('https://matplotlib.org/stable/', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'pandas': ('https://pandas.pydata.org/docs/', None),
Expand Down
6 changes: 6 additions & 0 deletions doc/OnlineDocs/library_reference/common/deprecation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyomo.common.deprecation
========================

.. automodule:: pyomo.common.deprecation
:members:
:member-order: bysource
6 changes: 6 additions & 0 deletions doc/OnlineDocs/library_reference/common/fileutils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyomo.common.fileutils
======================

.. automodule:: pyomo.common.fileutils
:members:
:member-order: bysource
6 changes: 6 additions & 0 deletions doc/OnlineDocs/library_reference/common/formatting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pyomo.common.formatting
=======================

.. automodule:: pyomo.common.formatting
:members:
:member-order: bysource
3 changes: 3 additions & 0 deletions doc/OnlineDocs/library_reference/common/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ or rely on any other parts of Pyomo.
config.rst
dependencies.rst
deprecation.rst
fileutils.rst
formatting.rst
tempfiles.rst
timing.rst
7 changes: 7 additions & 0 deletions doc/OnlineDocs/library_reference/common/tempfiles.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

pyomo.common.tempfiles
======================

.. automodule:: pyomo.common.tempfiles
:members:
:member-order: bysource
1 change: 1 addition & 0 deletions doc/OnlineDocs/library_reference/solvers/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Solver Interfaces
gams.rst
cplex_persistent.rst
gurobi_persistent.rst
xpress_persistent.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
XpressPersistent
================

.. autoclass:: pyomo.solvers.plugins.solvers.xpress_persistent.XpressPersistent
:members:
:inherited-members:
:show-inheritance:
6 changes: 3 additions & 3 deletions doc/OnlineDocs/related_packages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ Domain-Specific Applications
+==========================+=========================================================+=============================================+
| Chama | https://github.com/sandialabs/chama | Sensor placement optimization |
+--------------------------+---------------------------------------------------------+---------------------------------------------+
| Egret | https://github.com/grid-parity-exchange/egret | Formulation and solution of Unit Commitment|
| Egret | https://github.com/grid-parity-exchange/egret | Formulation and solution of unit commitment|
| | | and optimal power flow problems |
+--------------------------+---------------------------------------------------------+---------------------------------------------+
| IDAES | https://github.com/idaes/idaes-pse | Institute for the Design of Advanced |
| | | Energy Systems |
+--------------------------+---------------------------------------------------------+---------------------------------------------+
| Prescient | https://github.com/grid-parity-exchange/prescient | Parallel solution of structured |
| | | NLPs. |
| Prescient | https://github.com/grid-parity-exchange/prescient | Production Cost Model for power systems |
| | | simulation and analysis |
+--------------------------+---------------------------------------------------------+---------------------------------------------+
| PyPSA | https://github.com/pypsa/pypsa | Python for Power system Analysis |
+--------------------------+---------------------------------------------------------+---------------------------------------------+
Expand Down
78 changes: 77 additions & 1 deletion pyomo/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,47 @@
ADVANCED_OPTION = 1
DEVELOPER_OPTION = 2

def Bool(val):
"""Domain validator for bool-like objects.
This is a more strict domain than ``bool``, as it will error on
values that do not "look" like a Boolean value (i.e., it accepts
``True``, ``False``, 0, 1, and the case insensitive strings
``'true'``, ``'false'``, ``'yes'``, ``'no'``, ``'t'``, ``'f'``,
``'y'``, and ``'n'``)
"""
if type(val) is bool:
return val
if isinstance(val, str):
v = val.upper()
if v in {'TRUE', 'YES', 'T', 'Y', '1'}:
return True
if v in {'FALSE', 'NO', 'F', 'N', '0'}:
return False
elif int(val) == float(val):
v = int(val)
if v in {0, 1}:
return bool(v)
raise ValueError(
"Expected Boolean, but received %s" % (val,))

def Integer(val):
"""Domain validation function admitting integers
This domain will admit integers, as well as any values that are
"reasonably exactly" convertible to integers. This is more strict
than ``int``, as it will generate errors for floating point values
that are not integer.
"""
ans = int(val)
# We want to give an error for floating point numbers...
if ans != float(val):
raise ValueError(
"Expected integer, but received %s" % (val,))
return ans

def PositiveInt(val):
"""Domain validation function admitting strictly positive integers
Expand Down Expand Up @@ -237,7 +278,38 @@ def __call__(self, value):
value, self._domain.__name__))


class Module:
class ListOf(object):
"""Domain validator for lists of a specified type
Parameters
----------
itemtype: type
The type for each element in the list
domain: Callable
A domain validator (callable that takes the incoming value,
validates it, and returns the appropriate domain type) for each
element in the list. If not specified, defaults to the
`itemtype`.
"""
def __init__(self, itemtype, domain=None):
self.itemtype = itemtype
if domain is None:
self.domain = self.itemtype
else:
self.domain = domain
self.__name__ = 'ListOf(%s)' % (
getattr(self.domain, '__name__', self.domain),)

def __call__(self, value):
if hasattr(value, '__iter__') and not isinstance(value, self.itemtype):
return [self.domain(v) for v in value]
else:
return [self.domain(value)]


class Module(object):
""" Domain validator for modules.
Modules can be specified as module objects, by module name,
Expand Down Expand Up @@ -585,6 +657,8 @@ def from_enum_or_string(cls, arg):
.. autosummary::
Bool
Integer
PositiveInt
NegativeInt
NonNegativeInt
Expand All @@ -595,6 +669,8 @@ def from_enum_or_string(cls, arg):
NonNegativeFloat
In
InEnum
ListOf
Module
Path
PathList
Expand Down
6 changes: 4 additions & 2 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import logging
import sys

from .deprecation import deprecated, deprecation_warning
from .deprecation import (
deprecated, deprecation_warning, in_testing_environment,
)
from . import numeric_types

class DeferredImportError(ImportError):
Expand Down Expand Up @@ -581,7 +583,7 @@ def _finalize_matplotlib(module, available):
# we are in the middle of testing, we need to switch the backend to
# 'Agg', otherwise attempts to generate plots on CI services without
# terminal windows will fail.
if any(m in sys.modules for m in ('nose', 'nose2', 'sphinx', 'pytest')):
if in_testing_environment():
module.use('Agg')
import matplotlib.pyplot

Expand Down
31 changes: 27 additions & 4 deletions pyomo/common/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def wrapper(*args, **kwargs):
wrapper.__doc__ += _deprecation_docstring(func, msg, version, remove_in)
return wrapper


def _find_calling_frame(module_offset):
g = [globals()]
calling_frame = inspect.currentframe().f_back
Expand All @@ -135,6 +136,19 @@ def _find_calling_frame(module_offset):
break
return calling_frame


def in_testing_environment():
"""Return True if we are currently running in a "testing" environment
This currently includes if nose, nose2, pytest, or Sphinx are
running (imported).
"""

return any(mod in sys.modules for mod in (
'nose', 'nose2', 'pytest', 'sphinx'))


def deprecation_warning(msg, logger=None, version=None,
remove_in=None, calling_frame=None):
"""Standardized formatter for deprecation warnings
Expand Down Expand Up @@ -168,7 +182,7 @@ def deprecation_warning(msg, logger=None, version=None,
# function/method that called deprecation_warning
cf = _find_calling_frame(1)
if cf is not None:
logger = cf.f_globals['__package__']
logger = cf.f_globals.get('__package__', None)
if logger is not None and not logger.startswith('pyomo'):
logger = None
if logger is None:
Expand All @@ -189,9 +203,18 @@ def deprecation_warning(msg, logger=None, version=None,
if calling_frame is not None:
info = inspect.getframeinfo(calling_frame)
msg += "\n(called from %s:%s)" % (info.filename.strip(), info.lineno)
if deprecation_warning.emitted_warnings is not None:
if msg in deprecation_warning.emitted_warnings:
return
deprecation_warning.emitted_warnings.add(msg)

logging.getLogger(logger).warning(msg)

if in_testing_environment():
deprecation_warning.emitted_warnings = None
else:
deprecation_warning.emitted_warnings = set()


def deprecated(msg=None, logger=None, version=None, remove_in=None):
"""Decorator to indicate that a function, method or class is deprecated.
Expand Down Expand Up @@ -376,14 +399,14 @@ class RenamedClass(type):
>>> class DerivedOldClass(OldClass):
... pass
WARNING: DEPRECATED: Declaring class 'DerivedOldClass' derived from
'OldClass'. The class 'OldClass' has been renamed to 'NewClass'
'OldClass'. The class 'OldClass' has been renamed to 'NewClass'.
(deprecated in 6.0) ...
As does instantiating the old class:
>>> old = OldClass()
WARNING: DEPRECATED: Instantiating class 'OldClass'. The class
'OldClass' has been renamed to 'NewClass' (deprecated in 6.0) ...
'OldClass' has been renamed to 'NewClass'. (deprecated in 6.0) ...
Finally, isinstance and issubclass still work, for example:
Expand All @@ -394,7 +417,7 @@ class RenamedClass(type):
>>> new = NewSubclass()
>>> isinstance(new, OldClass)
WARNING: DEPRECATED: Checking type relative to 'OldClass'. The class
'OldClass' has been renamed to 'NewClass' (deprecated in 6.0) ...
'OldClass' has been renamed to 'NewClass'. (deprecated in 6.0) ...
True
"""
Expand Down
Loading

0 comments on commit 5133766

Please sign in to comment.