Skip to content

Commit 946a42d

Browse files
authored
Merge branch 'main' into pyomonlp-scaling
2 parents d4e4e0a + ae354ae commit 946a42d

10 files changed

+98
-52
lines changed

.github/workflows/test_branches.yml

+6
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,9 @@ jobs:
855855
token: ${{ secrets.PYOMO_CODECOV_TOKEN }}
856856
name: ${{ matrix.TARGET }}
857857
flags: ${{ matrix.TARGET }}
858+
# downgrading after v0.7.0 broke tokenless upload
859+
# see codecov/codecov-action#1487
860+
version: v0.6.0
858861
fail_ci_if_error: true
859862

860863
- name: Upload other coverage reports
@@ -867,4 +870,7 @@ jobs:
867870
token: ${{ secrets.PYOMO_CODECOV_TOKEN }}
868871
name: ${{ matrix.TARGET }}/other
869872
flags: ${{ matrix.TARGET }},other
873+
# downgrading after v0.7.0 broke tokenless upload
874+
# see codecov/codecov-action#1487
875+
version: v0.6.0
870876
fail_ci_if_error: true

.github/workflows/test_pr_and_main.yml

+6
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,9 @@ jobs:
899899
token: ${{ secrets.PYOMO_CODECOV_TOKEN }}
900900
name: ${{ matrix.TARGET }}
901901
flags: ${{ matrix.TARGET }}
902+
# downgrading after v0.7.0 broke tokenless upload
903+
# see codecov/codecov-action#1487
904+
version: v0.6.0
902905
fail_ci_if_error: true
903906

904907
- name: Upload other coverage reports
@@ -911,4 +914,7 @@ jobs:
911914
token: ${{ secrets.PYOMO_CODECOV_TOKEN }}
912915
name: ${{ matrix.TARGET }}/other
913916
flags: ${{ matrix.TARGET }},other
917+
# downgrading after v0.7.0 broke tokenless upload
918+
# see codecov/codecov-action#1487
919+
version: v0.6.0
914920
fail_ci_if_error: true

pyomo/common/dependencies.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -999,10 +999,13 @@ def _finalize_numpy(np, available):
999999
# registration here (to bypass the deprecation warning) until we
10001000
# finally remove all support for it
10011001
numeric_types._native_boolean_types.add(t)
1002-
_floats = [np.float_, np.float16, np.float32, np.float64]
1002+
_floats = [np.float16, np.float32, np.float64]
10031003
# float96 and float128 may or may not be defined in this particular
10041004
# numpy build (it depends on platform and version).
10051005
# Register them only if they are present
1006+
if hasattr(np, 'float_'):
1007+
# Prepend to preserve previous functionality
1008+
_floats.insert(0, np.float_)
10061009
if hasattr(np, 'float96'):
10071010
_floats.append(np.float96)
10081011
if hasattr(np, 'float128'):
@@ -1013,10 +1016,13 @@ def _finalize_numpy(np, available):
10131016
# registration here (to bypass the deprecation warning) until we
10141017
# finally remove all support for it
10151018
numeric_types._native_boolean_types.add(t)
1016-
_complex = [np.complex_, np.complex64, np.complex128]
1019+
_complex = [np.complex64, np.complex128]
10171020
# complex192 and complex256 may or may not be defined in this
10181021
# particular numpy build (it depends on platform and version).
10191022
# Register them only if they are present
1023+
if hasattr(np, 'np.complex_'):
1024+
# Prepend to preserve functionality
1025+
_complex.insert(0, np.complex_)
10201026
if hasattr(np, 'complex192'):
10211027
_complex.append(np.complex192)
10221028
if hasattr(np, 'complex256'):

pyomo/common/unittest.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ def filter_fcn(self, line):
783783
return False
784784

785785
def filter_file_contents(self, lines, abstol=None):
786+
_numpy_scalar_re = re.compile(r'np.(int|float)\d+\(([^\)]+)\)')
786787
filtered = []
787788
deprecated = None
788789
for line in lines:
@@ -807,29 +808,49 @@ def filter_file_contents(self, lines, abstol=None):
807808
item_list = []
808809
items = line.strip().split()
809810
for i in items:
811+
# Split up lists, dicts, and sets
812+
while i and i[0] in '[{':
813+
item_list.append(i[0])
814+
i = i[1:]
815+
tail = []
816+
while i and i[-1] in ',:]}':
817+
tail.append(i[-1])
818+
i = i[:-1]
819+
810820
# A few substitutions to get tests passing on pypy3
811821
if ".inf" in i:
812822
i = i.replace(".inf", "inf")
813823
if "null" in i:
814824
i = i.replace("null", "None")
815825

816826
try:
817-
item_list.append(float(i))
827+
# Numpy 2.x changed the repr for scalars. Convert
828+
# the new scalar reprs back to the original (which
829+
# were indistinguishable from python floats/ints)
830+
np_match = _numpy_scalar_re.match(i)
831+
if np_match:
832+
item_list.append(float(np_match.group(2)))
833+
else:
834+
item_list.append(float(i))
818835
except:
819836
item_list.append(i)
837+
if tail:
838+
tail.reverse()
839+
item_list.extend(tail)
820840

821841
# We can get printed results objects where the baseline is
822842
# exactly 0 (and omitted) and the test is slightly non-zero.
823843
# We will look for the pattern of values printed from
824844
# results objects and remote them if they are within
825845
# tolerance of 0
826846
if (
827-
len(item_list) == 2
828-
and item_list[0] == 'Value:'
829-
and type(item_list[1]) is float
830-
and abs(item_list[1]) < (abstol or 0)
831-
and len(filtered[-1]) == 1
832-
and filtered[-1][0][-1] == ':'
847+
len(item_list) == 3
848+
and item_list[0] == 'Value'
849+
and item_list[1] == ':'
850+
and type(item_list[2]) is float
851+
and abs(item_list[2]) < (abstol or 0)
852+
and len(filtered[-1]) == 2
853+
and filtered[-1][1] == ':'
833854
):
834855
filtered.pop()
835856
else:

pyomo/core/kernel/register_numpy_types.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
# Historically, the lists included several numpy aliases
4646
numpy_int_names.extend(('int_', 'intc', 'intp'))
4747
numpy_int.extend((numpy.int_, numpy.intc, numpy.intp))
48-
numpy_float_names.append('float_')
49-
numpy_float.append(numpy.float_)
50-
numpy_complex_names.append('complex_')
51-
numpy_complex.append(numpy.complex_)
48+
if hasattr(numpy, 'float_'):
49+
numpy_float_names.append('float_')
50+
numpy_float.append(numpy.float_)
51+
if hasattr(numpy, 'complex_'):
52+
numpy_complex_names.append('complex_')
53+
numpy_complex.append(numpy.complex_)
5254

5355
# Re-build the old numpy_* lists
5456
for t in native_boolean_types:

pyomo/core/tests/unit/test_kernel_register_numpy_types.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
# Boolean
1717
numpy_bool_names = []
1818
if numpy_available:
19-
numpy_bool_names.append('bool_')
19+
if numpy.__version__[0] == '2':
20+
numpy_bool_names.append('bool')
21+
else:
22+
numpy_bool_names.append('bool_')
2023
# Integers
2124
numpy_int_names = []
2225
if numpy_available:
@@ -34,7 +37,8 @@
3437
# Reals
3538
numpy_float_names = []
3639
if numpy_available:
37-
numpy_float_names.append('float_')
40+
if hasattr(numpy, 'float_'):
41+
numpy_float_names.append('float_')
3842
numpy_float_names.append('float16')
3943
numpy_float_names.append('float32')
4044
numpy_float_names.append('float64')
@@ -46,7 +50,8 @@
4650
# Complex
4751
numpy_complex_names = []
4852
if numpy_available:
49-
numpy_complex_names.append('complex_')
53+
if hasattr(numpy, 'complex_'):
54+
numpy_complex_names.append('complex_')
5055
numpy_complex_names.append('complex64')
5156
numpy_complex_names.append('complex128')
5257
if hasattr(numpy, 'complex192'):

pyomo/core/tests/unit/test_numvalue.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,10 @@ def test_unknownNumericType(self):
552552

553553
@unittest.skipUnless(numpy_available, "This test requires NumPy")
554554
def test_numpy_basic_float_registration(self):
555-
self.assertIn(numpy.float_, native_numeric_types)
556-
self.assertNotIn(numpy.float_, native_integer_types)
557-
self.assertIn(numpy.float_, _native_boolean_types)
558-
self.assertIn(numpy.float_, native_types)
555+
self.assertIn(numpy.float64, native_numeric_types)
556+
self.assertNotIn(numpy.float64, native_integer_types)
557+
self.assertIn(numpy.float64, _native_boolean_types)
558+
self.assertIn(numpy.float64, native_types)
559559

560560
@unittest.skipUnless(numpy_available, "This test requires NumPy")
561561
def test_numpy_basic_int_registration(self):

pyomo/core/tests/unit/test_sets.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def setUp(self):
10511051
self.instance = self.model.create_instance(currdir + "setA.dat")
10521052
self.e1 = numpy.bool_(1)
10531053
self.e2 = numpy.int_(2)
1054-
self.e3 = numpy.float_(3.0)
1054+
self.e3 = numpy.float64(3.0)
10551055
self.e4 = numpy.int_(4)
10561056
self.e5 = numpy.int_(5)
10571057
self.e6 = numpy.int_(6)
@@ -1068,7 +1068,7 @@ def test_numpy_int(self):
10681068

10691069
def test_numpy_float(self):
10701070
model = ConcreteModel()
1071-
model.A = Set(initialize=[numpy.float_(1.0), numpy.float_(0.0)])
1071+
model.A = Set(initialize=[numpy.float64(1.0), numpy.float64(0.0)])
10721072
self.assertEqual(model.A.bounds(), (0, 1))
10731073

10741074

@@ -3213,7 +3213,7 @@ def test_numpy_membership(self):
32133213
self.assertEqual(numpy.int_(1) in Boolean, True)
32143214
self.assertEqual(numpy.bool_(True) in Boolean, True)
32153215
self.assertEqual(numpy.bool_(False) in Boolean, True)
3216-
self.assertEqual(numpy.float_(1.1) in Boolean, False)
3216+
self.assertEqual(numpy.float64(1.1) in Boolean, False)
32173217
self.assertEqual(numpy.int_(2) in Boolean, False)
32183218

32193219
self.assertEqual(numpy.int_(0) in Integers, True)
@@ -3222,7 +3222,7 @@ def test_numpy_membership(self):
32223222
# identically to 1
32233223
self.assertEqual(numpy.bool_(True) in Integers, True)
32243224
self.assertEqual(numpy.bool_(False) in Integers, True)
3225-
self.assertEqual(numpy.float_(1.1) in Integers, False)
3225+
self.assertEqual(numpy.float64(1.1) in Integers, False)
32263226
self.assertEqual(numpy.int_(2) in Integers, True)
32273227

32283228
self.assertEqual(numpy.int_(0) in Reals, True)
@@ -3231,14 +3231,14 @@ def test_numpy_membership(self):
32313231
# identically to 1
32323232
self.assertEqual(numpy.bool_(True) in Reals, True)
32333233
self.assertEqual(numpy.bool_(False) in Reals, True)
3234-
self.assertEqual(numpy.float_(1.1) in Reals, True)
3234+
self.assertEqual(numpy.float64(1.1) in Reals, True)
32353235
self.assertEqual(numpy.int_(2) in Reals, True)
32363236

32373237
self.assertEqual(numpy.int_(0) in Any, True)
32383238
self.assertEqual(numpy.int_(1) in Any, True)
32393239
self.assertEqual(numpy.bool_(True) in Any, True)
32403240
self.assertEqual(numpy.bool_(False) in Any, True)
3241-
self.assertEqual(numpy.float_(1.1) in Any, True)
3241+
self.assertEqual(numpy.float64(1.1) in Any, True)
32423242
self.assertEqual(numpy.int_(2) in Any, True)
32433243

32443244
def test_setargs1(self):

pyomo/repn/plugins/lp_writer.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,13 @@ def write(self, model):
458458
addSymbol(con, label)
459459
ostream.write(f'\n{label}:\n')
460460
self.write_expression(ostream, repn, False)
461-
ostream.write(f'>= {(lb - offset)!r}\n')
461+
ostream.write(f'>= {(lb - offset)!s}\n')
462462
elif lb == ub:
463463
label = f'c_e_{symbol}_'
464464
addSymbol(con, label)
465465
ostream.write(f'\n{label}:\n')
466466
self.write_expression(ostream, repn, False)
467-
ostream.write(f'= {(lb - offset)!r}\n')
467+
ostream.write(f'= {(lb - offset)!s}\n')
468468
else:
469469
# We will need the constraint body twice. Generate
470470
# in a buffer so we only have to do that once.
@@ -476,18 +476,18 @@ def write(self, model):
476476
addSymbol(con, label)
477477
ostream.write(f'\n{label}:\n')
478478
ostream.write(buf)
479-
ostream.write(f'>= {(lb - offset)!r}\n')
479+
ostream.write(f'>= {(lb - offset)!s}\n')
480480
label = f'r_u_{symbol}_'
481481
aliasSymbol(con, label)
482482
ostream.write(f'\n{label}:\n')
483483
ostream.write(buf)
484-
ostream.write(f'<= {(ub - offset)!r}\n')
484+
ostream.write(f'<= {(ub - offset)!s}\n')
485485
elif ub is not None:
486486
label = f'c_u_{symbol}_'
487487
addSymbol(con, label)
488488
ostream.write(f'\n{label}:\n')
489489
self.write_expression(ostream, repn, False)
490-
ostream.write(f'<= {(ub - offset)!r}\n')
490+
ostream.write(f'<= {(ub - offset)!s}\n')
491491

492492
if with_debug_timing:
493493
# report the last constraint
@@ -527,8 +527,8 @@ def write(self, model):
527527
# Note: Var.bounds guarantees the values are either (finite)
528528
# native_numeric_types or None
529529
lb, ub = v.bounds
530-
lb = '-inf' if lb is None else repr(lb)
531-
ub = '+inf' if ub is None else repr(ub)
530+
lb = '-inf' if lb is None else str(lb)
531+
ub = '+inf' if ub is None else str(ub)
532532
ostream.write(f"\n {lb} <= {v_symbol} <= {ub}")
533533

534534
if integer_vars:
@@ -565,7 +565,7 @@ def write(self, model):
565565
for v, w in getattr(soscon, 'get_items', soscon.items)():
566566
if w.__class__ not in int_float:
567567
w = float(f)
568-
ostream.write(f" {getSymbol(v)}:{w!r}\n")
568+
ostream.write(f" {getSymbol(v)}:{w!s}\n")
569569

570570
ostream.write("\nend\n")
571571

@@ -584,9 +584,9 @@ def write_expression(self, ostream, expr, is_objective):
584584
expr.linear.items(), key=lambda x: getVarOrder(x[0])
585585
):
586586
if coef < 0:
587-
ostream.write(f'{coef!r} {getSymbol(getVar(vid))}\n')
587+
ostream.write(f'{coef!s} {getSymbol(getVar(vid))}\n')
588588
else:
589-
ostream.write(f'+{coef!r} {getSymbol(getVar(vid))}\n')
589+
ostream.write(f'+{coef!s} {getSymbol(getVar(vid))}\n')
590590

591591
quadratic = getattr(expr, 'quadratic', None)
592592
if quadratic:
@@ -605,9 +605,9 @@ def _normalize_constraint(data):
605605
col = c1, c2
606606
sym = f' {getSymbol(getVar(vid1))} * {getSymbol(getVar(vid2))}\n'
607607
if coef < 0:
608-
return col, repr(coef) + sym
608+
return col, str(coef) + sym
609609
else:
610-
return col, '+' + repr(coef) + sym
610+
return col, f'+{coef!s}{sym}'
611611

612612
if is_objective:
613613
#

0 commit comments

Comments
 (0)