Skip to content

Commit

Permalink
Merge pull request Pyomo#3109 from mrmundt/residual-python2
Browse files Browse the repository at this point in the history
Remove unnecessary `__future__` imports
  • Loading branch information
blnicho authored Jan 26, 2024
2 parents 00748f4 + 1dfefb5 commit f7fa223
Show file tree
Hide file tree
Showing 46 changed files with 24 additions and 80 deletions.
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/abstract2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# abstract2.py

from __future__ import division

from pyomo.environ import *

model = AbstractModel()
Expand Down
1 change: 0 additions & 1 deletion doc/OnlineDocs/src/scripting/concrete1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import division
from pyomo.environ import *

model = ConcreteModel()
Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/driveabs2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# driveabs2.py
from __future__ import division

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

Expand Down
2 changes: 1 addition & 1 deletion doc/OnlineDocs/src/scripting/driveconc1.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# driveconc1.py
from __future__ import division

import pyomo.environ as pyo
from pyomo.opt import SolverFactory

Expand Down
2 changes: 1 addition & 1 deletion examples/dae/stochpdegas_automatic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# stochastic pde model for natural gas network
# victor m. zavala / 2013

# from __future__ import division
#

from pyomo.environ import *
from pyomo.dae import *
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/constrained_layout/cons_layout_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"""

from __future__ import division

from pyomo.environ import ConcreteModel, Objective, Param, RangeSet, Set, Var, value

# Constrained layout model examples. These are from Nicolas Sawaya (2006).
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/eight_process/eight_proc_logical.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"""

from __future__ import division

from pyomo.core.expr.logical_expr import land, lor
from pyomo.core.plugins.transform.logical_to_linear import (
update_boolean_vars_from_binary,
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/eight_process/eight_proc_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
"""

from __future__ import division

from pyomo.environ import (
ConcreteModel,
Constraint,
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/eight_process/eight_proc_verbose_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"""

from __future__ import division

from pyomo.environ import (
ConcreteModel,
Constraint,
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/small_lit/ex_633_trespalacios.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"""

from __future__ import division

from pyomo.environ import *
from pyomo.gdp import *

Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/strip_packing/strip_packing_8rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
"""

from __future__ import division

from pyomo.environ import (
ConcreteModel,
NonNegativeReals,
Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/strip_packing/strip_packing_concrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"""

from __future__ import division

from pyomo.environ import ConcreteModel, NonNegativeReals, Objective, Param, Set, Var


Expand Down
2 changes: 0 additions & 2 deletions examples/gdp/two_rxn_lee/two_rxn_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Two reactor model from literature. See README.md."""

from __future__ import division

from pyomo.core import ConcreteModel, Constraint, Objective, Param, Var, maximize

# from pyomo.environ import * # NOQA
Expand Down
2 changes: 1 addition & 1 deletion examples/performance/dae/stochpdegas1_automatic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# stochastic pde model for natural gas network
# victor m. zavala / 2013

# from __future__ import division
#

from pyomo.environ import *
from pyomo.dae import *
Expand Down
1 change: 0 additions & 1 deletion examples/pyomobook/pyomo-components-ch/var_declaration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import pyomo.environ as pyo

model = pyo.ConcreteModel()
Expand Down
1 change: 0 additions & 1 deletion pyomo/contrib/community_detection/tests/test_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from __future__ import division

import logging

Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mcpp/pyomo_mcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Note: the self.mcpp.* functions are all C-style functions implemented
# in the compiled MC++ wrapper library
# Note: argument to pow must be an integer
from __future__ import division


import ctypes
import logging
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/mcpp/test_mcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
from __future__ import division


import logging
from math import pi
Expand Down
2 changes: 0 additions & 2 deletions pyomo/contrib/multistart/high_conf_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"""

from __future__ import division

from collections import Counter
from math import log, sqrt

Expand Down
2 changes: 0 additions & 2 deletions pyomo/contrib/multistart/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# ___________________________________________________________________________


from __future__ import division

import logging

from pyomo.common.config import (
Expand Down
2 changes: 0 additions & 2 deletions pyomo/contrib/multistart/reinit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Helper functions for variable reinitialization."""

from __future__ import division

import logging
import random

Expand Down
1 change: 0 additions & 1 deletion pyomo/contrib/preprocessing/plugins/bounds_to_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

"""Transformation to convert explicit bounds to variable bounds."""

from __future__ import division

from math import fabs
import math
Expand Down
1 change: 0 additions & 1 deletion pyomo/contrib/preprocessing/plugins/induced_linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

from __future__ import division

import logging
import textwrap
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/preprocessing/plugins/init_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ___________________________________________________________________________

"""Automatically initialize variables."""
from __future__ import division


from pyomo.core.base.var import Var
from pyomo.core.base.transformation import TransformationFactory
Expand Down
2 changes: 0 additions & 2 deletions pyomo/contrib/preprocessing/plugins/int_to_binary.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Transformation to reformulate integer variables into binary."""

from __future__ import division

from math import floor, log
import logging

Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/preprocessing/plugins/remove_zero_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# -*- coding: UTF-8 -*-
"""Transformation to remove zero terms from constraints."""
from __future__ import division


from pyomo.core import quicksum
from pyomo.core.base.constraint import Constraint
Expand Down
1 change: 0 additions & 1 deletion pyomo/contrib/preprocessing/plugins/var_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

"""Transformation to aggregate equal variables."""

from __future__ import division

from pyomo.common.collections import ComponentMap, ComponentSet
from pyomo.core.base import Block, Constraint, VarList, Objective, TransformationFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from __future__ import division

import pyomo.environ as pyo
from pyomo.contrib.pynumero.interfaces.external_grey_box import ExternalGreyBoxBlock
from pyomo.contrib.pynumero.examples.external_grey_box.react_example.reactor_model_outputs import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
box model interface.
"""

from __future__ import division

import numpy as np
from scipy.optimize import fsolve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
box model interface.
"""

from __future__ import division

import pyomo.environ as pyo
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/pynumero/sparse/tests/test_block_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from __future__ import division

import pyomo.common.unittest as unittest

from pyomo.contrib.pynumero.dependencies import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# and D.K. Owen 1998, Interfaces
#

from __future__ import division

from pyomo.environ import (
ConcreteModel,
Param,
Expand Down
2 changes: 1 addition & 1 deletion pyomo/contrib/sensitivity_toolbox/examples/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# Original implementation by Hans Pirany is in pyomo/examples/pyomo/suffixes
#
from __future__ import print_function

from pyomo.environ import (
ConcreteModel,
Param,
Expand Down
14 changes: 1 addition & 13 deletions pyomo/core/base/piecewise.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
*) piecewise for functions of the form y = f(x1,x2,...)
"""

# ****** NOTE: Nothing in this file relies on integer division *******
# I predict this will save numerous headaches as
# well as gratuitous calls to float() in this code
from __future__ import division

__all__ = ['Piecewise']

Expand Down Expand Up @@ -151,8 +147,6 @@ def _characterize_function(name, tol, f_rule, model, points, *index):
# expression generation errors in the checks below
points = [value(_p) for _p in points]

# we use future division to protect against the case where
# the user supplies integer type points for return values
if isinstance(f_rule, types.FunctionType):
values = [f_rule(model, *flatten_tuple((index, x))) for x in points]
elif f_rule.__class__ is dict:
Expand Down Expand Up @@ -272,7 +266,6 @@ def __call__(self, x):
yU = self._range_pts[i + 1]
if xL == xU: # a step function
return yU
# using future division
return yL + ((yU - yL) / (xU - xL)) * (x - xL)
raise ValueError(
"The point %s is outside the list of domain "
Expand All @@ -299,7 +292,6 @@ def construct(self, pblock, x_var, y_var):
# create a single linear constraint
LHS = y_var
F_AT_XO = y_pts[0]
# using future division
dF_AT_XO = (y_pts[1] - y_pts[0]) / (x_pts[1] - x_pts[0])
X_MINUS_XO = x_var - x_pts[0]
if bound_type == Bound.Upper:
Expand Down Expand Up @@ -739,7 +731,7 @@ def construct(self, pblock, x_var, y_var):
# create indexers
polytopes = range(1, len_x_pts)

# create constants (using future division)
# create constants
SLOPE = {
p: (y_pts[p] - y_pts[p - 1]) / (x_pts[p] - x_pts[p - 1]) for p in polytopes
}
Expand Down Expand Up @@ -908,7 +900,6 @@ def con1_rule(model, i):
rhs *= 0.0
else:
rhs *= OPT_M['UB'][i] * (1 - bigm_y[i])
# using future division
return (
y_var
- y_pts[i - 1]
Expand All @@ -922,7 +913,6 @@ def con1_rule(model, i):
rhs *= 0.0
else:
rhs *= OPT_M['LB'][i] * (1 - bigm_y[i])
# using future division
return (
y_var
- y_pts[i - 1]
Expand All @@ -944,7 +934,6 @@ def conAFF_rule(model, i):
rhs *= 0.0
else:
rhs *= OPT_M['LB'][i] * (1 - bigm_y[i])
# using future division
return (
y_var
- y_pts[i - 1]
Expand Down Expand Up @@ -974,7 +963,6 @@ def conAFF_rule(model, i):
pblock.bigm_domain_constraint_upper = Constraint(expr=x_var <= x_pts[-1])

def _M_func(self, a, Fa, b, Fb, c, Fc):
# using future division
return Fa - Fb - ((a - b) * ((Fc - Fb) / (c - b)))

def _find_M(self, x_pts, y_pts, bound_type):
Expand Down
1 change: 0 additions & 1 deletion pyomo/core/expr/logical_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from __future__ import division

import types
from itertools import islice
Expand Down
8 changes: 1 addition & 7 deletions pyomo/core/expr/numeric_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@

logger = logging.getLogger('pyomo.core')

from math import isclose

from pyomo.common.dependencies import attempt_import
from pyomo.common.deprecation import (
deprecated,
deprecation_warning,
relocated_module_attribute,
)
from pyomo.common.deprecation import deprecated, relocated_module_attribute
from pyomo.common.errors import PyomoException, DeveloperError
from pyomo.common.formatting import tostr
from pyomo.common.numeric_types import (
Expand Down
9 changes: 4 additions & 5 deletions pyomo/core/expr/numvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ def polynomial_degree(obj):
)


#
# It is very common to have only a few constants in a model, but those
# constants get repeated many times. KnownConstants lets us re-use /
# share constants we have seen before.
#
# Note:
# For now, all constants are coerced to floats. This avoids integer
# division in Python 2.x. (At least some of the time.)
Expand All @@ -273,6 +268,10 @@ def polynomial_degree(obj):
# need to index KnownConstants by both the class type and value, since
# INT, FLOAT and LONG values sometimes hash the same.
#
# It is very common to have only a few constants in a model, but those
# constants get repeated many times. KnownConstants lets us re-use /
# share constants we have seen before.
#
_KnownConstants = {}


Expand Down
Loading

0 comments on commit f7fa223

Please sign in to comment.