Skip to content

Commit

Permalink
Add test for #3352
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Aug 19, 2024
1 parent 2aaecea commit f3a07ed
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pyomo/repn/tests/ampl/test_nlv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,38 @@ def test_nested_external_expressions(self):
0 0
1 0
2 0
""",
OUT.getvalue(),
)
)

@unittest.skipUnless(numpy_available, "test requires numpy")
def test_objective_numpy_const(self):
# This tests issue #3352
m = ConcreteModel()
m.e = Expression(expr=numpy.float64(0))
m.obj = Objective(expr=m.e)

OUT = io.StringIO()
nl_writer.NLWriter().write(m, OUT, linear_presolve=False, scale_model=True)
self.assertEqual(
*nl_diff(
"""g3 1 1 0 #problem unknown
0 0 1 0 0 #vars, constraints, objectives, ranges, eqns
0 0 0 0 0 0 #nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
0 0 #network constraints: nonlinear, linear
0 0 0 #nonlinear vars in constraints, objectives, both
0 0 0 1 #linear network variables; functions; arith, flags
0 0 0 0 0 #discrete variables: binary, integer, nonlinear (b,c,o)
0 0 #nonzeros in Jacobian, obj. gradient
0 0 #max name lengths: constraints, variables
0 0 0 0 0 #common exprs: b,c,o,c1,o1
O0 0
n0
x0
r
b
k-1
""",
OUT.getvalue(),
)
Expand Down

0 comments on commit f3a07ed

Please sign in to comment.