From defc953b3a120cfbed1d44356e7a37381664ad12 Mon Sep 17 00:00:00 2001 From: Emma Johnson Date: Mon, 12 Aug 2024 20:36:14 -0600 Subject: [PATCH] Adding a test for cloning a multivariate piecewise linear function too --- .../piecewise/tests/test_nonlinear_to_pwl.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pyomo/contrib/piecewise/tests/test_nonlinear_to_pwl.py b/pyomo/contrib/piecewise/tests/test_nonlinear_to_pwl.py index 2f13532b63f..a42846c2802 100644 --- a/pyomo/contrib/piecewise/tests/test_nonlinear_to_pwl.py +++ b/pyomo/contrib/piecewise/tests/test_nonlinear_to_pwl.py @@ -376,6 +376,36 @@ def test_paraboloid_objective_uniform_grid(self): self.check_pw_linear_paraboloid(m, pwlf, x1, x2, y1, y2) + @unittest.skipUnless(numpy_available, "Numpy is not available") + @unittest.skipUnless(scipy_available, "Scipy is not available") + def test_multivariate_clone(self): + m = self.make_paraboloid_model() + + n_to_pwl = TransformationFactory('contrib.piecewise.nonlinear_to_pwl') + n_to_pwl.apply_to( + m, + num_points=2, + domain_partitioning_method=DomainPartitioningMethod.UNIFORM_GRID, + ) + + twin = m.clone() + + # check obj is transformed + self.assertFalse(twin.obj.active) + + pwlf = list( + twin.component_data_objects(PiecewiseLinearFunction, descend_into=True) + ) + self.assertEqual(len(pwlf), 1) + pwlf = pwlf[0] + + x1 = 0.00030000000000000003 + x2 = 2.9997 + y1 = 1.0006 + y2 = 6.9994 + + self.check_pw_linear_paraboloid(twin, pwlf, x1, x2, y1, y2) + @unittest.skipUnless(numpy_available, "Numpy is not available") @unittest.skipUnless(scipy_available, "Scipy is not available") def test_objective_target(self):