Skip to content

Commit 0977386

Browse files
author
Shilpa Narasimhan
committed
Apply Black formatting to DoE files
1 parent e9e4f4e commit 0977386

5 files changed

Lines changed: 20 additions & 25 deletions

File tree

pyomo/contrib/doe/doe.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,9 @@ def initialize_fim_inv(m, j, d):
29712971
model.L_inv[c, d].setlb(self.L_diagonal_lower_bound)
29722972

29732973
if self._gradient_method == GradientMethod.pynumero:
2974-
experiment_grad.construct_sensitivity_constraints(model.fd_scenario_blocks[0])
2974+
experiment_grad.construct_sensitivity_constraints(
2975+
model.fd_scenario_blocks[0]
2976+
)
29752977

29762978
def jacobian_rule(m, n, p):
29772979
"""
@@ -2987,7 +2989,9 @@ def jacobian_rule(m, n, p):
29872989
output_var = output_cuid.find_component_on(m.fd_scenario_blocks[0])
29882990

29892991
parameter_cuid = pyo.ComponentUID(p)
2990-
parameter_var = parameter_cuid.find_component_on(m.fd_scenario_blocks[0])
2992+
parameter_var = parameter_cuid.find_component_on(
2993+
m.fd_scenario_blocks[0]
2994+
)
29912995

29922996
i = experiment_grad.measurement_mapping[output_var]
29932997
j = experiment_grad.parameter_mapping[parameter_var]

pyomo/contrib/doe/tests/test_doe_solve.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,7 @@ def test_rescale_FIM(self):
767767

768768
# Get rescaled FIM from the scaled version
769769
param_vals = np.array(
770-
[
771-
[
772-
v
773-
for k, v in doe_obj.compute_FIM_model.unknown_parameters.items()
774-
]
775-
]
770+
[[v for k, v in doe_obj.compute_FIM_model.unknown_parameters.items()]]
776771
)
777772

778773
resc_FIM = rescale_FIM(FIM, param_vals)

pyomo/contrib/doe/tests/test_greybox.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@
4747
if numpy_available:
4848
# Randomly generated P.S.D. matrix
4949
# Matrix is 2x2 to match Rooney-Biegler parameters.
50-
testing_matrix = np.array(
51-
[
52-
[5.13730123, 1.08084953],
53-
[1.08084953, 1.57183404],
54-
]
55-
)
50+
testing_matrix = np.array([[5.13730123, 1.08084953], [1.08084953, 1.57183404]])
5651

5752
masking_matrix = np.triu(np.ones_like(testing_matrix))
5853

pyomo/contrib/doe/tests/test_utils.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
_SMALL_TOLERANCE_SYMMETRY,
2626
_SMALL_TOLERANCE_IMG,
2727
)
28+
2829
if not (numpy_available and scipy_available):
2930
raise unittest.SkipTest("Pyomo.DoE needs scipy and numpy to run tests")
3031

@@ -172,6 +173,7 @@ def test_get_FIM_metrics(self):
172173
fim_metrics["log10(Modified E-Optimality)"], expected['ME_opt']
173174
)
174175

176+
175177
@unittest.skipIf(not ipopt_available, "The 'ipopt' command is not available")
176178
@unittest.skipIf(not numpy_available, "Numpy is not available")
177179
class TestExperimentGradients(unittest.TestCase):
@@ -278,16 +280,15 @@ def test_polynomial_automatic_only_still_sets_both_jacobians(self):
278280
model, symbolic=False, automatic=True
279281
)
280282

281-
jacobian =(
283+
jacobian = (
282284
experiment_gradients.compute_gradient_outputs_wrt_unknown_parameters()
283285
)
284286
expected = self._get_expected_polynomial_gradient()
285287

286288
self.assertIsNotNone(experiment_gradients.jac_dict_sd)
287289
self.assertIsNotNone(experiment_gradients.jac_dict_ad)
288290
self.assertEqual(jacobian.shape, expected.shape)
289-
self.assertTrue(np.allclose(jacobian,expected))
290-
291+
self.assertTrue(np.allclose(jacobian, expected))
291292

292293
def test_polynomial_symbolic_only_still_sets_both_jacobians(self):
293294
"""Check that symbolic-only requests still initialize both Jacobian maps."""
@@ -298,7 +299,7 @@ def test_polynomial_symbolic_only_still_sets_both_jacobians(self):
298299
model, symbolic=True, automatic=False
299300
)
300301

301-
jacobian =(
302+
jacobian = (
302303
experiment_gradients.compute_gradient_outputs_wrt_unknown_parameters()
303304
)
304305
expected = self._get_expected_polynomial_gradient()
@@ -343,19 +344,20 @@ def test_rooney_biegler_gradients_match_closed_form(self):
343344
self.assertEqual(jacobian.shape, expected.shape)
344345
self.assertTrue(np.allclose(jacobian, expected, atol=1e-7, rtol=1e-7))
345346

346-
347-
348347
@unittest.skipIf(not scipy_available, "scipy is not available")
349348
@unittest.skipIf(not ipopt_available, "The 'ipopt' command is not available")
350-
def test_rooney_biegler_symbolic_and_automatic_jacobians_agree_at_perturbed_point(self):
349+
def test_rooney_biegler_symbolic_and_automatic_jacobians_agree_at_perturbed_point(
350+
self,
351+
):
351352
"""Check Rooney-Biegler Jacobian agreement at a perturbed operating point."""
352-
experiment = self._get_rooney_biegler_experiment(hour=7.0, y=19.8, asymptote=14.0, rate_constant=0.4)
353+
experiment = self._get_rooney_biegler_experiment(
354+
hour=7.0, y=19.8, asymptote=14.0, rate_constant=0.4
355+
)
353356
model = experiment.get_labeled_model()
354357

355358
experiment_gradients = self._assert_symbolic_and_automatic_jacobians_agree(
356359
model, atol=1e-6, rtol=1e-6
357360
)
358-
359361

360362
self.assertGreater(len(experiment_gradients.jac_dict_sd), 0)
361363
self.assertEqual(

pyomo/contrib/doe/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ def compute_FIM_metrics(FIM):
210210
# Modified E-optimality is based on the FIM condition number and penalizes
211211
# confidence ellipsoids that are highly elongated in one direction.
212212

213-
214213
ME_opt = np.log10(np.linalg.cond(FIM))
215214

216215
return (
@@ -294,7 +293,7 @@ class ExperimentGradients:
294293
295294
This helper implements the symbolic sensitivity path used in Pyomo.DoE.
296295
Instead of approximating sensitivities by finite-difference perturbations
297-
of the unknown parameters theta, it differentiates the
296+
of the unknown parameters theta, it differentiates the
298297
model F(x, u, theta) = 0 with respect to theta, with the design variables
299298
u fixed, and solves the resulting auxiliary sensitivity system
300299

0 commit comments

Comments
 (0)