diff --git a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_aerostructures.py b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_aerostructures.py index 30c4bcfa7..affd5de4e 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_aerostructures.py +++ b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_aerostructures.py @@ -83,7 +83,7 @@ def test_gpkit_style_solve(): sol = opti.solve() - assert sol.value(D) == pytest.approx(303.1, abs=0.1) + assert sol(D) == pytest.approx(303.1, abs=0.1) def test_geometric_program_solve(): @@ -132,7 +132,7 @@ def test_geometric_program_solve(): sol = opti.solve() - assert sol.value(D) == pytest.approx(303.1, abs=0.1) + assert sol(D) == pytest.approx(303.1, abs=0.1) def test_non_log_transformed_solve(): @@ -186,7 +186,7 @@ def test_non_log_transformed_solve(): sol = opti.solve() - assert sol.value(D) == pytest.approx(303.1, abs=0.1) + assert sol(D) == pytest.approx(303.1, abs=0.1) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py index 7126f8a2e..89f4d2fed 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py +++ b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py @@ -28,11 +28,11 @@ def test_normal_problem(): sol = opti.solve() - print(f"Chord = {sol.value(chord)}") - print(f"Span = {sol.value(span)}") + print(f"Chord = {sol(chord)}") + print(f"Span = {sol(span)}") - assert sol.value(chord) == pytest.approx(0.2288630528244024) - assert sol.value(span) == pytest.approx(4.369425242121806) + assert sol(chord) == pytest.approx(0.2288630528244024) + assert sol(span) == pytest.approx(4.369425242121806) def test_log_transformed_problem(): @@ -51,11 +51,11 @@ def test_log_transformed_problem(): sol = opti.solve() - print(f"Chord = {sol.value(chord)}") - print(f"Span = {sol.value(span)}") + print(f"Chord = {sol(chord)}") + print(f"Span = {sol(span)}") - assert sol.value(chord) == pytest.approx(0.2288630528244024) - assert sol.value(span) == pytest.approx(4.369425242121806) + assert sol(chord) == pytest.approx(0.2288630528244024) + assert sol(span) == pytest.approx(4.369425242121806) def test_log_transformed_negativity_error(): @@ -81,11 +81,11 @@ def test_fixed_variable(): sol = opti.solve() - print(f"Chord = {sol.value(chord)}") - print(f"Span = {sol.value(span)}") + print(f"Chord = {sol(chord)}") + print(f"Span = {sol(span)}") - assert sol.value(chord) == pytest.approx(1) - assert sol.value(span) == pytest.approx(1) + assert sol(chord) == pytest.approx(1) + assert sol(span) == pytest.approx(1) def test_fully_fixed_problem(): @@ -104,11 +104,11 @@ def test_fully_fixed_problem(): sol = opti.solve() - print(f"Chord = {sol.value(chord)}") - print(f"Span = {sol.value(span)}") + print(f"Chord = {sol(chord)}") + print(f"Span = {sol(span)}") - assert sol.value(chord) == pytest.approx(1) - assert sol.value(span) == pytest.approx(1) + assert sol(chord) == pytest.approx(1) + assert sol(span) == pytest.approx(1) def test_overconstrained_fully_fixed_problem(): @@ -128,11 +128,11 @@ def test_overconstrained_fully_fixed_problem(): sol = opti.solve() - print(f"Chord = {sol.value(chord)}") - print(f"Span = {sol.value(span)}") + print(f"Chord = {sol(chord)}") + print(f"Span = {sol(span)}") - # assert sol.value(chord) == pytest.approx(1) - # assert sol.value(span) == pytest.approx(1) + # assert sol(chord) == pytest.approx(1) + # assert sol(span) == pytest.approx(1) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_bounds.py b/aerosandbox/optimization/test_optimization/test_opti_bounds.py index 74fdc6d26..c9aea1b7b 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_bounds.py +++ b/aerosandbox/optimization/test_optimization/test_opti_bounds.py @@ -10,7 +10,7 @@ def test_bounds(): sol = opti.solve() - assert sol.value(x) == pytest.approx(3) + assert sol(x) == pytest.approx(3) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_hanging_chain.py b/aerosandbox/optimization/test_optimization/test_opti_hanging_chain.py index 21b88cf1e..a52f901b2 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_hanging_chain.py +++ b/aerosandbox/optimization/test_optimization/test_opti_hanging_chain.py @@ -83,7 +83,7 @@ def my_callback(iter: int): callback=my_callback ) - assert sol.value(potential_energy) == pytest.approx(626.462, abs=1e-3) + assert sol(potential_energy) == pytest.approx(626.462, abs=1e-3) if plot: plt.show() diff --git a/aerosandbox/optimization/test_optimization/test_opti_log_transform.py b/aerosandbox/optimization/test_optimization/test_opti_log_transform.py index 3ed539ea8..354363abd 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_log_transform.py +++ b/aerosandbox/optimization/test_optimization/test_opti_log_transform.py @@ -9,7 +9,7 @@ def test_bounds(): opti.minimize(x) sol = opti.solve() - assert sol.value(x) == pytest.approx(7) + assert sol(x) == pytest.approx(7) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_optimal_control_manual_integration.py b/aerosandbox/optimization/test_optimization/test_opti_optimal_control_manual_integration.py index 312852493..1a1d3c866 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_optimal_control_manual_integration.py +++ b/aerosandbox/optimization/test_optimization/test_opti_optimal_control_manual_integration.py @@ -74,7 +74,7 @@ def test_rocket_control_problem(plot=False): sol = opti.solve() # solve - assert sol.value(a_max) == pytest.approx(0.02181991952, rel=1e-3) # solved externally with Julia JuMP + assert sol(a_max) == pytest.approx(0.02181991952, rel=1e-3) # solved externally with Julia JuMP if plot: import matplotlib.pyplot as plt @@ -84,7 +84,7 @@ def test_rocket_control_problem(plot=False): fig, ax = plt.subplots(1, 1, figsize=(8, 6), dpi=200) for i, val, lab in zip(np.arange(3), [x, v, a], ["$x$", "$v$", "$a$"]): plt.subplot(3, 1, i + 1) - plt.plot(sol.value(val), label=lab) + plt.plot(sol(val), label=lab) plt.xlabel(r"Time [s]") plt.ylabel(lab) plt.legend() diff --git a/aerosandbox/optimization/test_optimization/test_opti_parametric_sensitivites.py b/aerosandbox/optimization/test_optimization/test_opti_parametric_sensitivites.py index ef4d254ea..1f3f8aa64 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_parametric_sensitivites.py +++ b/aerosandbox/optimization/test_optimization/test_opti_parametric_sensitivites.py @@ -37,11 +37,11 @@ def test_rosenbrock_constrained(plot=False): for r_value in r_values ] fs = [ - sol.value(f) + sol(f) for sol in sols ] duals = [ - sol.value(dual) # Ensure the dual can be evaluated + sol(dual) # Ensure the dual can be evaluated for sol in sols ] diff --git a/aerosandbox/optimization/test_optimization/test_opti_poorly_scaled.py b/aerosandbox/optimization/test_optimization/test_opti_poorly_scaled.py index a409aca07..9998a365b 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_poorly_scaled.py +++ b/aerosandbox/optimization/test_optimization/test_opti_poorly_scaled.py @@ -31,8 +31,8 @@ def test_opti_poorly_scaled_constraints(constraint_jacobian_condition_number=1e1 sol = opti.solve() # Check - assert sol.value(x) == pytest.approx(0.9, abs=1e-4) - assert sol.value(y) == pytest.approx(0.81, abs=1e-4) + assert sol(x) == pytest.approx(0.9, abs=1e-4) + assert sol(y) == pytest.approx(0.81, abs=1e-4) def test_opti_poorly_scaled_objective(objective_hessian_condition_number=1e10): @@ -51,9 +51,9 @@ def test_opti_poorly_scaled_objective(objective_hessian_condition_number=1e10): sol = opti.solve() # Check - assert sol.value(x) == pytest.approx(0, abs=1e-2) - assert sol.value(y) == pytest.approx(0, abs=1e-2) - assert sol.value(f) == pytest.approx(0, abs=1e-4) + assert sol(x) == pytest.approx(0, abs=1e-2) + assert sol(y) == pytest.approx(0, abs=1e-2) + assert sol(f) == pytest.approx(0, abs=1e-4) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_rosenbrock.py b/aerosandbox/optimization/test_optimization/test_opti_rosenbrock.py index de23766df..02e0876ba 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_rosenbrock.py +++ b/aerosandbox/optimization/test_optimization/test_opti_rosenbrock.py @@ -37,7 +37,7 @@ def test_2D_rosenbrock(): # 2-dimensional rosenbrock sol = opti.solve() for i in [x, y]: - assert sol.value(i) == pytest.approx(1, abs=1e-4) + assert sol(i) == pytest.approx(1, abs=1e-4) def test_2D_rosenbrock_circle_constrained(): # 2-dimensional rosenbrock, constrained to be within the unit circle. @@ -58,8 +58,8 @@ def test_2D_rosenbrock_circle_constrained(): # 2-dimensional rosenbrock, constr sol = opti.solve() # Check - assert sol.value(x) == pytest.approx(0.7864, abs=1e-4) - assert sol.value(y) == pytest.approx(0.6177, abs=1e-4) + assert sol(x) == pytest.approx(0.7864, abs=1e-4) + assert sol(y) == pytest.approx(0.6177, abs=1e-4) # (Solution also given here: https://www.mathworks.com/help/optim/ug/example-nonlinear-constrained-minimization.html#brg0p3g-2 ) @@ -81,7 +81,7 @@ def test_ND_rosenbrock_constrained(N=10): # N-dimensional rosenbrock sol = opti.solve() # solve for i in range(N): - assert sol.value(x[i]) == pytest.approx(1, abs=1e-4) + assert sol(x[i]) == pytest.approx(1, abs=1e-4) def test_2D_rosenbrock_frozen(): @@ -98,9 +98,9 @@ def test_2D_rosenbrock_frozen(): # Optimize sol = opti.solve() - assert sol.value(x) == pytest.approx(0.161, abs=1e-3) - assert sol.value(y) == pytest.approx(0, abs=1e-3) - assert sol.value(f) == pytest.approx(0.771, abs=1e-3) + assert sol(x) == pytest.approx(0.161, abs=1e-3) + assert sol(y) == pytest.approx(0, abs=1e-3) + assert sol(f) == pytest.approx(0.771, abs=1e-3) if __name__ == '__main__': diff --git a/aerosandbox/optimization/test_optimization/test_opti_save_load.py b/aerosandbox/optimization/test_optimization/test_opti_save_load.py index 7c676b4fa..ca835ee01 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_save_load.py +++ b/aerosandbox/optimization/test_optimization/test_opti_save_load.py @@ -28,7 +28,7 @@ def test_opti(): sol = opti.solve() for i in [x, y]: - assert sol.value(i) == pytest.approx(1, abs=1e-4) + assert sol(i) == pytest.approx(1, abs=1e-4) def test_save_opti(tmp_path): @@ -68,12 +68,12 @@ def test_save_and_load_opti(tmp_path): sol = opti.solve() opti.save_solution() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(1) - assert sol.value(f) == pytest.approx(0) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(1) + assert sol(f) == pytest.approx(0) ### Round 2 optimization: Cat 1 is fixed from before; slightly different objective now opti = asb.Opti( @@ -90,12 +90,12 @@ def test_save_and_load_opti(tmp_path): # Optimize, save to cache, print sol = opti.solve() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(2) - assert sol.value(f) == pytest.approx(1) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(2) + assert sol(f) == pytest.approx(1) def test_save_and_load_opti_uncategorized(tmp_path): @@ -116,12 +116,12 @@ def test_save_and_load_opti_uncategorized(tmp_path): sol = opti.solve() opti.save_solution() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(1) - assert sol.value(f) == pytest.approx(0) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(1) + assert sol(f) == pytest.approx(0) ### Round 2 optimization: Cat 1 is fixed from before; slightly different objective now opti = asb.Opti( @@ -138,12 +138,12 @@ def test_save_and_load_opti_uncategorized(tmp_path): # Optimize, save to cache, print sol = opti.solve() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(1) - assert sol.value(f) == pytest.approx(2) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(1) + assert sol(f) == pytest.approx(2) def test_save_and_load_opti_vectorized(tmp_path): @@ -165,12 +165,12 @@ def test_save_and_load_opti_vectorized(tmp_path): sol = opti.solve() opti.save_solution() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(2) - assert sol.value(f) == pytest.approx(0) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(2) + assert sol(f) == pytest.approx(0) ### Round 2 optimization: Cat 1 is fixed from before; slightly different objective now opti = asb.Opti( @@ -187,12 +187,12 @@ def test_save_and_load_opti_vectorized(tmp_path): # Optimize, save to cache, print sol = opti.solve() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(4) - assert sol.value(f) == pytest.approx(12) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(4) + assert sol(f) == pytest.approx(12) def test_save_and_load_opti_freeze_override(tmp_path): @@ -214,12 +214,12 @@ def test_save_and_load_opti_freeze_override(tmp_path): sol = opti.solve() opti.save_solution() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(1) - assert sol.value(y) == pytest.approx(1) - assert sol.value(f) == pytest.approx(0) + assert sol(x) == pytest.approx(1) + assert sol(y) == pytest.approx(1) + assert sol(f) == pytest.approx(0) ### Round 2 optimization: Cat 1 is fixed from before but then overridden; slightly different objective now opti = asb.Opti( @@ -236,12 +236,12 @@ def test_save_and_load_opti_freeze_override(tmp_path): # Optimize, save to cache, print sol = opti.solve() for i in ["x", "y", "f"]: - print(f"{i}: {sol.value(eval(i))}") + print(f"{i}: {sol(eval(i))}") # Test - assert sol.value(x) == pytest.approx(3) - assert sol.value(y) == pytest.approx(2) - assert sol.value(f) == pytest.approx(1) + assert sol(x) == pytest.approx(3) + assert sol(y) == pytest.approx(2) + assert sol(f) == pytest.approx(1) if __name__ == '__main__':