-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug fix for proximal scalar optimization #1419
Changes from all commits
0d4c331
f106527
675773d
e583b74
edf5288
a80e86d
5bd497f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,6 +324,44 @@ def test_no_iterations(): | |
np.testing.assert_allclose(x0, out2["x"]) | ||
|
||
|
||
@pytest.mark.regression | ||
@pytest.mark.optimize | ||
def test_proximal_scalar(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a full regression test for this? Can't we just check that the function works? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose a unit test would suffice in this case now that we know what the problem was, but I think we should keep the regression test. I think this is the only test where we use a "proximal-scalar" optimization algorithm, and that seems like something worth testing. |
||
"""Test that proximal scalar optimization works.""" | ||
# test fix for GH issue #1403 | ||
|
||
# optimize to reduce DSHAPE volume from 100 m^3 to 90 m^3 | ||
eq = desc.examples.get("DSHAPE") | ||
optimizer = Optimizer("proximal-fmintr") # proximal scalar optimizer | ||
R_modes = np.vstack( | ||
( | ||
[0, 0, 0], | ||
eq.surface.R_basis.modes[ | ||
np.max(np.abs(eq.surface.R_basis.modes), 1) > 1, : | ||
], | ||
) | ||
) | ||
Z_modes = eq.surface.Z_basis.modes[ | ||
np.max(np.abs(eq.surface.Z_basis.modes), 1) > 1, : | ||
] | ||
objective = ObjectiveFunction(Volume(eq=eq, target=90)) # scalar objective function | ||
constraints = ( | ||
FixBoundaryR(eq=eq, modes=R_modes), | ||
FixBoundaryZ(eq=eq, modes=Z_modes), | ||
FixIota(eq=eq), | ||
FixPressure(eq=eq), | ||
FixPsi(eq=eq), | ||
ForceBalance(eq=eq), # force balance constraint for proximal projection | ||
) | ||
[eq], _ = optimizer.optimize( | ||
things=eq, | ||
objective=objective, | ||
constraints=constraints, | ||
verbose=3, | ||
) | ||
np.testing.assert_allclose(eq.compute("V")["V"], 90) | ||
|
||
|
||
@pytest.mark.regression | ||
@pytest.mark.slow | ||
@pytest.mark.optimize | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs of
grad
andhess
methods ofProximalProjection
say that it computes the gradient ofself.compute_scalar
which this PR just adds. Should we change them?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the docs are correct.$\frac{1}{2} \Sigma f^2$ , $f^T \cdot J$ , and $J^T \cdot J$ .
compute_scalar
computes the sum-of-squares errorcompute_grad
computes the gradient of that scalar error ascompute_hess
computes the Hessian of that scalar error asThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, wrappers have different syntax. I was expecting smth more like
ObjectiveFunction
s grad method,There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both implementations should be equivalent in theory. @f0uriest would changing this to take the gradient of the new
compute_scalar
be any faster than the existing implementation?