-
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
Fix bug in boozer coordinate computation for Omnigenous magnetic field #1166
Conversation
unalmis
commented
Aug 6, 2024
•
edited
Loading
edited
- Move test compute everything to own file and exclude source grid quantities. from commit 8a8d9de.
- Remove xyz basis file in favor of correctness check to catch bug Quantities are computed wrong unless returned data is in cylindrical basis vectors #1088
- Debug zeta_B computation. zeta_B computation is sometimes wrong #1163 has been reproduced here (and on master by Dario). This issue was resolved after fixing the computation of zeta_B and theta_B for omnigenous fields.
| benchmark_name | dt(%) | dt(s) | t_new(s) | t_old(s) |
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
test_build_transform_fft_lowres | +5.26 +/- 7.49 | +2.77e-02 +/- 3.94e-02 | 5.54e-01 +/- 3.5e-02 | 5.26e-01 +/- 1.7e-02 |
test_build_transform_fft_midres | +0.83 +/- 5.68 | +5.23e-03 +/- 3.57e-02 | 6.33e-01 +/- 2.5e-02 | 6.28e-01 +/- 2.5e-02 |
test_build_transform_fft_highres | -0.15 +/- 3.48 | -1.66e-03 +/- 3.79e-02 | 1.09e+00 +/- 2.8e-02 | 1.09e+00 +/- 2.6e-02 |
test_equilibrium_init_lowres | +3.89 +/- 7.34 | +1.50e-01 +/- 2.83e-01 | 4.01e+00 +/- 1.6e-01 | 3.85e+00 +/- 2.3e-01 |
test_equilibrium_init_medres | +2.17 +/- 5.53 | +9.59e-02 +/- 2.44e-01 | 4.51e+00 +/- 1.7e-01 | 4.41e+00 +/- 1.8e-01 |
test_equilibrium_init_highres | +4.14 +/- 3.41 | +2.34e-01 +/- 1.93e-01 | 5.89e+00 +/- 1.4e-01 | 5.66e+00 +/- 1.3e-01 |
test_objective_compile_dshape_current | +0.40 +/- 2.20 | +1.59e-02 +/- 8.80e-02 | 4.02e+00 +/- 8.1e-02 | 4.00e+00 +/- 3.5e-02 |
test_objective_compile_atf | -1.27 +/- 2.57 | -1.09e-01 +/- 2.21e-01 | 8.49e+00 +/- 1.0e-01 | 8.60e+00 +/- 2.0e-01 |
test_objective_compute_dshape_current | -0.35 +/- 3.51 | -4.37e-06 +/- 4.42e-05 | 1.26e-03 +/- 2.4e-05 | 1.26e-03 +/- 3.7e-05 |
test_objective_compute_atf | -3.75 +/- 6.09 | -1.65e-04 +/- 2.68e-04 | 4.23e-03 +/- 1.3e-04 | 4.39e-03 +/- 2.3e-04 |
test_objective_jac_dshape_current | -7.47 +/- 9.23 | -3.01e-03 +/- 3.72e-03 | 3.73e-02 +/- 3.2e-03 | 4.03e-02 +/- 2.0e-03 |
test_objective_jac_atf | -7.57 +/- 3.10 | -1.50e-01 +/- 6.16e-02 | 1.84e+00 +/- 3.1e-02 | 1.99e+00 +/- 5.3e-02 |
test_perturb_1 | -2.70 +/- 1.96 | -3.88e-01 +/- 2.82e-01 | 1.40e+01 +/- 1.1e-01 | 1.44e+01 +/- 2.6e-01 |
test_perturb_2 | -0.71 +/- 2.75 | -1.40e-01 +/- 5.40e-01 | 1.95e+01 +/- 2.3e-01 | 1.96e+01 +/- 4.9e-01 |
test_proximal_jac_atf | -2.04 +/- 1.26 | -1.54e-01 +/- 9.53e-02 | 7.38e+00 +/- 3.5e-02 | 7.54e+00 +/- 8.9e-02 |
test_proximal_freeb_compute | -1.89 +/- 1.15 | -3.43e-03 +/- 2.09e-03 | 1.78e-01 +/- 1.2e-03 | 1.81e-01 +/- 1.7e-03 |
test_proximal_freeb_jac | -0.03 +/- 1.33 | -2.29e-03 +/- 9.91e-02 | 7.46e+00 +/- 5.4e-02 | 7.47e+00 +/- 8.3e-02 |
test_solve_fixed_iter | -0.66 +/- 5.69 | -1.24e-01 +/- 1.07e+00 | 1.87e+01 +/- 7.1e-01 | 1.88e+01 +/- 8.1e-01 | |
I can't seem to reproduce #1163 when trying on a CPU compute node on della, though it actually fails with very slim margins for some of the current density and force compoents. You are running on linux locally I assume as well? |
Yes. Fedora linux. CPU, jax 0.4.30, jaxlib 0.4.28. |
wait I cannot read, yes I also get that |
take a look at the omni field in test compute everything, see if it looks weird, try changing params and see if it is more stable |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1166 +/- ##
==========================================
+ Coverage 95.15% 95.46% +0.31%
==========================================
Files 87 87
Lines 22281 22243 -38
==========================================
+ Hits 21202 21235 +33
+ Misses 1079 1008 -71
|
I think that is just an artifact of plotting with |
I think I figured out the issue: it has to do with how I'm not sure what the solution is, but I'll let you figure that out. |
Why are these aliases? @register_compute_fun(
name="theta_B",
label="(\\theta_{B},\\zeta_{B})",
units="rad",
units_long="radians",
description="Boozer angular coordinates",
dim=1,
params=[],
transforms={},
profiles=[],
coordinates="rtz",
data=["alpha", "h"],
aliases=["zeta_B"], # should remove this
parameterization="desc.magnetic_fields._core.OmnigenousField",
)
....
# solve for (theta_B,zeta_B) corresponding to (eta,alpha)
booz = matrix @ jnp.vstack((data["alpha"], data["h"]))
data["theta_B"] = booz[0, :]
data["zeta_B"] = booz[1, :] Unless |
@ddudt That doesn't make sense. I plotted the same thing with regular contour and it still persists. These is something else going on with those blobs at the ends. Here's what the target looks like now |
They are aliases in the sense that if you ask for one of the two quantities, you get both. The problem is with the alias logic outside of the compute function, not in the compute function itself. I don't like this solution -- it creates redundant code and computations. Maybe we shouldn't call them aliases, but I'm sure we can think of another way to have a single compute function return multiple variables. |
Marking some quantity
The redundancy is cosmetic. The computation is only done once.
This would require plumbing that is outside the scope of this PR. In particular, the There is a failing regression test now. My guess is it's due to the plotting change and not the compute function change? Could you look into this sometime |
I think the following will work. It's similar to your change, but avoids needing the duplicate code:
|
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.
Omnigenity gives me the same results as before. Approving!
grid_compute = _get_grid(**grid_kwargs) | ||
if grid_plot is None: | ||
grid_kwargs = { | ||
"rho": rho, | ||
"theta": 91, | ||
"zeta": 91, | ||
"NFP": thing.NFP, | ||
"endpoint": True, | ||
"endpoint": eq_switch, |
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.
why can't there be an endpoint in the plot grid for the Omnigenous field?
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.
The old code used grid_compute
for the Omnigenous field, which also had endpoint=False
so this doesn't change that. The only thing this changes is to correctly plot on grid_plot
instead of the grid_compute
.
In theory I think it should be able to use endpoint=True
, but it was giving a worse looking plot for the test. I suspect it's an issue with tricontour
but I'm not sure.
If this resolves any of the issues on boozer stuff, make sure to link them to this |