-
Notifications
You must be signed in to change notification settings - Fork 26
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
Scaled Linear Constraints #1158
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1158 +/- ##
=======================================
Coverage 95.46% 95.47%
=======================================
Files 87 87
Lines 22268 22277 +9
=======================================
+ Hits 21258 21268 +10
+ Misses 1010 1009 -1
|
| benchmark_name | dt(%) | dt(s) | t_new(s) | t_old(s) |
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
test_build_transform_fft_lowres | -4.86 +/- 7.14 | -2.71e-02 +/- 3.99e-02 | 5.31e-01 +/- 3.7e-02 | 5.58e-01 +/- 1.6e-02 |
test_build_transform_fft_midres | +2.30 +/- 3.82 | +1.48e-02 +/- 2.45e-02 | 6.58e-01 +/- 2.0e-02 | 6.43e-01 +/- 1.5e-02 |
test_build_transform_fft_highres | +0.99 +/- 3.78 | +9.92e-03 +/- 3.80e-02 | 1.02e+00 +/- 2.8e-02 | 1.01e+00 +/- 2.6e-02 |
test_equilibrium_init_lowres | +0.10 +/- 7.09 | +3.58e-03 +/- 2.67e-01 | 3.77e+00 +/- 1.7e-01 | 3.77e+00 +/- 2.1e-01 |
test_equilibrium_init_medres | +1.01 +/- 6.30 | +4.26e-02 +/- 2.67e-01 | 4.28e+00 +/- 1.9e-01 | 4.23e+00 +/- 1.8e-01 |
test_equilibrium_init_highres | +1.92 +/- 4.20 | +1.08e-01 +/- 2.36e-01 | 5.72e+00 +/- 2.1e-01 | 5.62e+00 +/- 1.1e-01 |
test_objective_compile_dshape_current | -2.58 +/- 1.94 | -1.01e-01 +/- 7.59e-02 | 3.81e+00 +/- 6.8e-02 | 3.91e+00 +/- 3.4e-02 |
test_objective_compile_atf | -0.41 +/- 2.26 | -3.44e-02 +/- 1.88e-01 | 8.31e+00 +/- 1.7e-01 | 8.35e+00 +/- 8.6e-02 |
test_objective_compute_dshape_current | +0.76 +/- 3.21 | +9.50e-06 +/- 4.03e-05 | 1.27e-03 +/- 2.5e-05 | 1.26e-03 +/- 3.2e-05 |
test_objective_compute_atf | +1.17 +/- 5.61 | +5.03e-05 +/- 2.41e-04 | 4.35e-03 +/- 1.2e-04 | 4.30e-03 +/- 2.1e-04 |
test_objective_jac_dshape_current | +0.50 +/- 10.86 | +1.91e-04 +/- 4.13e-03 | 3.82e-02 +/- 2.8e-03 | 3.81e-02 +/- 3.1e-03 |
test_objective_jac_atf | -1.09 +/- 2.80 | -2.13e-02 +/- 5.47e-02 | 1.93e+00 +/- 3.8e-02 | 1.95e+00 +/- 3.9e-02 |
test_perturb_1 | -3.30 +/- 5.82 | -4.55e-01 +/- 8.04e-01 | 1.34e+01 +/- 2.3e-01 | 1.38e+01 +/- 7.7e-01 |
test_perturb_2 | +1.11 +/- 3.45 | +2.03e-01 +/- 6.35e-01 | 1.86e+01 +/- 4.0e-01 | 1.84e+01 +/- 4.9e-01 |
-test_proximal_jac_atf | +8.47 +/- 1.31 | +6.31e-01 +/- 9.74e-02 | 8.08e+00 +/- 5.5e-02 | 7.44e+00 +/- 8.1e-02 |
test_proximal_freeb_compute | +0.41 +/- 1.16 | +7.41e-04 +/- 2.08e-03 | 1.80e-01 +/- 1.5e-03 | 1.79e-01 +/- 1.4e-03 |
test_proximal_freeb_jac | -1.19 +/- 1.31 | -8.89e-02 +/- 9.75e-02 | 7.38e+00 +/- 5.1e-02 | 7.47e+00 +/- 8.3e-02 |
test_solve_fixed_iter | +0.98 +/- 11.71 | +1.77e-01 +/- 2.11e+00 | 1.82e+01 +/- 1.3e+00 | 1.80e+01 +/- 1.6e+00 | |
with the usual automatic scaling the variable the optimizer sees is |
See my reply to your comment on the issue. The underlying problem is with how the linear constraints are projected/recovered, not with the optimization itself. So the automatic scaling within the optimizer does not resolve the issue. |
Is it better to just open a new PR rather than having a "revert all commits" commit? |
It was only 3 commits so not too big of a deal. Technically I think this is the more "correct" git approach so we don't have loose ends in the commit history from unused branches |
Can always delete branches, but this is fine |
tests/test_bootstrap.py
Outdated
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.
This test shouldn't have needed to change, since the scales are all 1. I think the bootstrap current optimization is just really sensitive and the extra identity matrices changed the numerics slightly. Is that plausible?
Resolves #1155
After discussion with @dpanici, we decided the best solution was to add an attribute to the_Coil
class to normalize the magnitude of the current. This effectively allows the user to specify the currents in units other than Amps, e.g. MA, so that the raw values are closer to order unity. This makes the optimization work well with linear constraints on the coil currents.New solution: Adds a diagonal scaling matrix
D
based on the magnitude of the values of the particular solution. This scales the variables projected/recovered from the linear constraints such that relative changes in the optimization variablesx_reduced
result in proportional relative changes in the full state vectorx_full
.TODO:
Z
byD
where necessary in perturbations, constraint wrappers, etc.