Skip to content
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

Add Ability to Write Boozmn.nc style output files #680

Merged
merged 136 commits into from
Feb 10, 2025

Conversation

dpanici
Copy link
Collaborator

@dpanici dpanici commented Sep 19, 2023

Add make_boozmn_output utility function to vmec_utils, which allows DESC to write boozmn.nc style output files containing Boozer harmonics. I/O based heavily off of the hidden symmetries version of booz_xform

  • add documentation (in form of notebook or a page) on our Boozer transform setup and how to use and the meaning of our "|B|_mn_B" and how to get into the familiar double angle form - make issue
  • deprecate |B|_mn
  • make issue for asym boozmn and kick can down the road - only issue is the numnc from the DESC-saved boozmn is the opposite sign to the C++ saved boozmn. Not sure what the issue is... the DESC-saved nu agrees better with the DESC nu, and the other quantities are all in agreement from both C++ and DESC, so it is something subtle

@dpanici
Copy link
Collaborator Author

dpanici commented Sep 21, 2023

make a norm name in data index

@dpanici dpanici changed the title first commit, machinery working but need to figure out good way to fi… Add Ability to Write Boozmn.nc style output files Sep 21, 2023
@dpanici
Copy link
Collaborator Author

dpanici commented Sep 27, 2023

notes to self on Booz_xform

modenumbers are defined here:

  • if m=0, they only include n from 0 -> nboz
  • else if m is not 0, they include all n modes from -nboz -> nboz
  • this means that they include the (0,0) mode even for their sin terms, but they skip the (0,-nboz -_ nboz) modes. This may explain the discrepancy in modes I see

@dpanici dpanici marked this pull request as draft October 11, 2023 19:33
Copy link
Contributor

github-actions bot commented Nov 8, 2023

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.64 +/- 2.10     | +9.97e-05 +/- 3.25e-04 |  1.56e-02 +/- 2.9e-04  |  1.55e-02 +/- 1.5e-04  |
 test_build_transform_fft_midres         |     +0.16 +/- 1.35     | +1.55e-04 +/- 1.29e-03 |  9.51e-02 +/- 1.2e-03  |  9.50e-02 +/- 4.9e-04  |
 test_build_transform_fft_highres        |     +1.14 +/- 0.84     | +5.29e-03 +/- 3.88e-03 |  4.69e-01 +/- 3.3e-03  |  4.63e-01 +/- 2.1e-03  |
 test_equilibrium_init_lowres            |     +0.48 +/- 1.46     | +3.14e-03 +/- 9.60e-03 |  6.61e-01 +/- 7.5e-03  |  6.58e-01 +/- 6.0e-03  |
 test_equilibrium_init_medres            |     -0.17 +/- 0.92     | -1.74e-03 +/- 9.23e-03 |  1.00e+00 +/- 5.7e-03  |  1.01e+00 +/- 7.2e-03  |
 test_equilibrium_init_highres           |     +0.41 +/- 1.07     | +1.04e-02 +/- 2.74e-02 |  2.57e+00 +/- 1.6e-02  |  2.56e+00 +/- 2.2e-02  |
 test_objective_compile_dshape_current   |     -1.97 +/- 6.87     | -8.34e-02 +/- 2.91e-01 |  4.16e+00 +/- 2.1e-01  |  4.24e+00 +/- 2.0e-01  |
 test_objective_compile_atf              |     -3.31 +/- 4.88     | -3.18e-01 +/- 4.69e-01 |  9.29e+00 +/- 3.4e-01  |  9.61e+00 +/- 3.2e-01  |
 test_objective_compute_dshape_current   |     +0.07 +/- 2.30     | +1.56e-06 +/- 5.03e-05 |  2.19e-03 +/- 3.3e-05  |  2.19e-03 +/- 3.8e-05  |
 test_objective_compute_atf              |     -1.34 +/- 2.16     | -1.04e-04 +/- 1.67e-04 |  7.63e-03 +/- 1.0e-04  |  7.73e-03 +/- 1.3e-04  |
 test_objective_jac_dshape_current       |     -6.37 +/- 7.16     | -3.01e-03 +/- 3.38e-03 |  4.42e-02 +/- 1.5e-03  |  4.72e-02 +/- 3.0e-03  |
 test_objective_jac_atf                  |     -7.77 +/- 4.22     | -1.86e-01 +/- 1.01e-01 |  2.21e+00 +/- 5.0e-02  |  2.39e+00 +/- 8.8e-02  |
 test_perturb_1                          |     -1.10 +/- 11.89    | -9.66e-02 +/- 1.04e+00 |  8.67e+00 +/- 7.6e-01  |  8.77e+00 +/- 7.2e-01  |
 test_perturb_2                          |     -2.40 +/- 5.40     | -3.52e-01 +/- 7.91e-01 |  1.43e+01 +/- 6.2e-01  |  1.47e+01 +/- 4.9e-01  |

Copy link
Contributor

github-actions bot commented Nov 9, 2023

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.74 +/- 1.72     | +1.13e-04 +/- 2.63e-04 |  1.54e-02 +/- 2.1e-04  |  1.53e-02 +/- 1.5e-04  |
 test_build_transform_fft_midres         |     +0.54 +/- 1.12     | +5.06e-04 +/- 1.06e-03 |  9.44e-02 +/- 8.6e-04  |  9.39e-02 +/- 6.1e-04  |
 test_build_transform_fft_highres        |     +0.73 +/- 0.94     | +3.36e-03 +/- 4.34e-03 |  4.65e-01 +/- 3.9e-03  |  4.62e-01 +/- 2.0e-03  |
 test_equilibrium_init_lowres            |     +2.80 +/- 2.13     | +1.84e-02 +/- 1.40e-02 |  6.75e-01 +/- 1.3e-02  |  6.57e-01 +/- 5.4e-03  |
 test_equilibrium_init_medres            |     +0.00 +/- 2.85     | +3.23e-05 +/- 2.83e-02 |  9.94e-01 +/- 2.6e-02  |  9.94e-01 +/- 1.2e-02  |
 test_equilibrium_init_highres           |     +0.07 +/- 0.69     | +1.89e-03 +/- 1.78e-02 |  2.56e+00 +/- 1.1e-02  |  2.56e+00 +/- 1.4e-02  |
 test_objective_compile_dshape_current   |     -1.40 +/- 6.95     | -5.85e-02 +/- 2.91e-01 |  4.14e+00 +/- 2.5e-01  |  4.19e+00 +/- 1.6e-01  |
 test_objective_compile_atf              |     -0.55 +/- 8.21     | -5.14e-02 +/- 7.62e-01 |  9.22e+00 +/- 5.6e-01  |  9.27e+00 +/- 5.2e-01  |
 test_objective_compute_dshape_current   |     +0.83 +/- 2.06     | +1.80e-05 +/- 4.48e-05 |  2.19e-03 +/- 2.5e-05  |  2.17e-03 +/- 3.7e-05  |
 test_objective_compute_atf              |     -1.90 +/- 1.03     | -1.45e-04 +/- 7.82e-05 |  7.48e-03 +/- 4.9e-05  |  7.62e-03 +/- 6.1e-05  |
 test_objective_jac_dshape_current       |     +5.20 +/- 10.14    | +2.31e-03 +/- 4.51e-03 |  4.68e-02 +/- 3.6e-03  |  4.45e-02 +/- 2.8e-03  |
 test_objective_jac_atf                  |     -0.24 +/- 6.29     | -5.71e-03 +/- 1.47e-01 |  2.34e+00 +/- 5.8e-02  |  2.34e+00 +/- 1.4e-01  |
 test_perturb_1                          |     -1.35 +/- 12.01    | -1.16e-01 +/- 1.03e+00 |  8.45e+00 +/- 7.3e-01  |  8.57e+00 +/- 7.3e-01  |
 test_perturb_2                          |     -1.29 +/- 3.45     | -1.85e-01 +/- 4.95e-01 |  1.42e+01 +/- 4.1e-01  |  1.44e+01 +/- 2.8e-01  |

Copy link
Contributor

github-actions bot commented Nov 9, 2023

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +2.27 +/- 9.81     | +3.48e-04 +/- 1.50e-03 |  1.56e-02 +/- 1.5e-03  |  1.53e-02 +/- 2.7e-04  |
 test_build_transform_fft_midres         |     +2.74 +/- 1.39     | +2.54e-03 +/- 1.29e-03 |  9.53e-02 +/- 1.2e-03  |  9.28e-02 +/- 3.1e-04  |
 test_build_transform_fft_highres        |     +0.95 +/- 1.08     | +4.36e-03 +/- 4.96e-03 |  4.62e-01 +/- 3.9e-03  |  4.58e-01 +/- 3.0e-03  |
 test_equilibrium_init_lowres            |     -0.12 +/- 1.35     | -7.75e-04 +/- 8.80e-03 |  6.49e-01 +/- 6.6e-03  |  6.50e-01 +/- 5.8e-03  |
 test_equilibrium_init_medres            |     -0.04 +/- 0.92     | -3.69e-04 +/- 9.11e-03 |  9.88e-01 +/- 5.7e-03  |  9.89e-01 +/- 7.1e-03  |
 test_equilibrium_init_highres           |     +1.01 +/- 1.18     | +2.56e-02 +/- 2.98e-02 |  2.56e+00 +/- 2.6e-02  |  2.53e+00 +/- 1.5e-02  |
 test_objective_compile_dshape_current   |     +4.79 +/- 7.87     | +1.96e-01 +/- 3.22e-01 |  4.29e+00 +/- 2.2e-01  |  4.10e+00 +/- 2.3e-01  |
 test_objective_compile_atf              |     +2.39 +/- 5.66     | +2.23e-01 +/- 5.27e-01 |  9.54e+00 +/- 4.4e-01  |  9.31e+00 +/- 2.9e-01  |
 test_objective_compute_dshape_current   |     +1.45 +/- 2.72     | +3.17e-05 +/- 5.94e-05 |  2.22e-03 +/- 3.3e-05  |  2.19e-03 +/- 5.0e-05  |
 test_objective_compute_atf              |     +0.33 +/- 1.33     | +2.55e-05 +/- 1.02e-04 |  7.71e-03 +/- 9.5e-05  |  7.69e-03 +/- 3.7e-05  |
 test_objective_jac_dshape_current       |     +1.53 +/- 12.32    | +7.10e-04 +/- 5.72e-03 |  4.71e-02 +/- 2.4e-03  |  4.64e-02 +/- 5.2e-03  |
 test_objective_jac_atf                  |     -0.09 +/- 7.71     | -2.06e-03 +/- 1.80e-01 |  2.33e+00 +/- 1.5e-01  |  2.33e+00 +/- 9.3e-02  |
 test_perturb_1                          |     -1.74 +/- 11.99    | -1.53e-01 +/- 1.05e+00 |  8.63e+00 +/- 7.9e-01  |  8.78e+00 +/- 7.0e-01  |
 test_perturb_2                          |     -1.60 +/- 5.50     | -2.31e-01 +/- 7.93e-01 |  1.42e+01 +/- 5.6e-01  |  1.44e+01 +/- 5.6e-01  |

Copy link
Contributor

github-actions bot commented Nov 9, 2023

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -0.13 +/- 1.07     | -1.98e-05 +/- 1.65e-04 |  1.54e-02 +/- 1.2e-04  |  1.54e-02 +/- 1.1e-04  |
 test_build_transform_fft_midres         |     -0.83 +/- 1.27     | -7.86e-04 +/- 1.20e-03 |  9.39e-02 +/- 9.1e-04  |  9.47e-02 +/- 7.9e-04  |
 test_build_transform_fft_highres        |     +0.10 +/- 0.70     | +4.55e-04 +/- 3.24e-03 |  4.66e-01 +/- 2.1e-03  |  4.66e-01 +/- 2.5e-03  |
 test_equilibrium_init_lowres            |     +0.50 +/- 1.37     | +3.26e-03 +/- 8.88e-03 |  6.53e-01 +/- 5.3e-03  |  6.50e-01 +/- 7.2e-03  |
 test_equilibrium_init_medres            |     -0.57 +/- 1.52     | -5.75e-03 +/- 1.52e-02 |  9.96e-01 +/- 1.2e-02  |  1.00e+00 +/- 9.5e-03  |
 test_equilibrium_init_highres           |     -0.26 +/- 0.75     | -6.71e-03 +/- 1.92e-02 |  2.55e+00 +/- 1.5e-02  |  2.56e+00 +/- 1.2e-02  |
 test_objective_compile_dshape_current   |     +0.15 +/- 8.35     | +6.09e-03 +/- 3.46e-01 |  4.15e+00 +/- 2.2e-01  |  4.14e+00 +/- 2.6e-01  |
 test_objective_compile_atf              |     +0.66 +/- 5.56     | +6.07e-02 +/- 5.10e-01 |  9.24e+00 +/- 4.2e-01  |  9.18e+00 +/- 2.9e-01  |
 test_objective_compute_dshape_current   |     +0.01 +/- 2.04     | +3.11e-07 +/- 4.44e-05 |  2.18e-03 +/- 3.1e-05  |  2.18e-03 +/- 3.2e-05  |
 test_objective_compute_atf              |     -1.51 +/- 0.90     | -1.16e-04 +/- 6.93e-05 |  7.55e-03 +/- 4.1e-05  |  7.67e-03 +/- 5.6e-05  |
 test_objective_jac_dshape_current       |     -5.38 +/- 11.78    | -2.56e-03 +/- 5.60e-03 |  4.50e-02 +/- 4.3e-03  |  4.75e-02 +/- 3.6e-03  |
 test_objective_jac_atf                  |     -3.50 +/- 5.85     | -8.40e-02 +/- 1.40e-01 |  2.32e+00 +/- 6.8e-02  |  2.40e+00 +/- 1.2e-01  |
 test_perturb_1                          |     +0.24 +/- 13.29    | +2.04e-02 +/- 1.14e+00 |  8.58e+00 +/- 8.3e-01  |  8.56e+00 +/- 7.8e-01  |
 test_perturb_2                          |     -0.62 +/- 5.57     | -8.88e-02 +/- 8.03e-01 |  1.43e+01 +/- 7.0e-01  |  1.44e+01 +/- 4.0e-01  |

Copy link
Contributor

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -1.60 +/- 1.92     | -3.65e-04 +/- 4.37e-04 |  2.24e-02 +/- 3.2e-04  |  2.28e-02 +/- 2.9e-04  |
 test_build_transform_fft_midres         |     +1.25 +/- 0.85     | +1.65e-03 +/- 1.13e-03 |  1.34e-01 +/- 8.3e-04  |  1.32e-01 +/- 7.7e-04  |
 test_build_transform_fft_highres        |     +0.55 +/- 0.86     | +3.35e-03 +/- 5.19e-03 |  6.10e-01 +/- 3.7e-03  |  6.06e-01 +/- 3.7e-03  |
 test_equilibrium_init_lowres            |     -1.47 +/- 1.22     | -1.48e-02 +/- 1.22e-02 |  9.89e-01 +/- 6.6e-03  |  1.00e+00 +/- 1.0e-02  |
 test_equilibrium_init_medres            |     -1.76 +/- 1.06     | -2.64e-02 +/- 1.59e-02 |  1.48e+00 +/- 1.3e-02  |  1.50e+00 +/- 8.6e-03  |
 test_equilibrium_init_highres           |     -0.41 +/- 0.74     | -1.47e-02 +/- 2.65e-02 |  3.56e+00 +/- 1.9e-02  |  3.57e+00 +/- 1.8e-02  |
 test_objective_compile_dshape_current   |     -1.90 +/- 6.58     | -1.22e-01 +/- 4.22e-01 |  6.29e+00 +/- 2.8e-01  |  6.42e+00 +/- 3.2e-01  |
 test_objective_compile_atf              |     -0.55 +/- 3.67     | -1.04e-01 +/- 6.89e-01 |  1.87e+01 +/- 4.4e-01  |  1.88e+01 +/- 5.3e-01  |
 test_objective_compute_dshape_current   |     -2.77 +/- 3.84     | -1.13e-04 +/- 1.56e-04 |  3.96e-03 +/- 1.3e-04  |  4.07e-03 +/- 9.2e-05  |
 test_objective_compute_atf              |     -0.89 +/- 2.60     | -1.21e-04 +/- 3.52e-04 |  1.34e-02 +/- 2.7e-04  |  1.35e-02 +/- 2.2e-04  |
 test_objective_jac_dshape_current       |     +2.84 +/- 11.42    | +4.67e-03 +/- 1.87e-02 |  1.69e-01 +/- 9.0e-03  |  1.64e-01 +/- 1.6e-02  |
 test_objective_jac_atf                  |     -3.27 +/- 2.77     | -2.79e-01 +/- 2.37e-01 |  8.26e+00 +/- 1.9e-01  |  8.54e+00 +/- 1.5e-01  |
 test_perturb_1                          |     -0.88 +/- 10.48    | -1.15e-01 +/- 1.36e+00 |  1.29e+01 +/- 8.9e-01  |  1.30e+01 +/- 1.0e+00  |
 test_perturb_2                          |     -1.54 +/- 6.16     | -3.49e-01 +/- 1.40e+00 |  2.23e+01 +/- 1.0e+00  |  2.27e+01 +/- 9.7e-01  |

@dpanici dpanici requested a review from f0uriest February 6, 2025 01:24
CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Yigit Gunsur Elmacioglu <[email protected]>
YigitElma
YigitElma previously approved these changes Feb 6, 2025
f0uriest
f0uriest previously approved these changes Feb 6, 2025
YigitElma
YigitElma previously approved these changes Feb 7, 2025
Copy link
Collaborator

@ddudt ddudt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments

tests/test_plotting.py Show resolved Hide resolved
tests/test_compute_funs.py Outdated Show resolved Hide resolved
label="",
units="~",
units_long="None",
description="Inner product norm for boozer modes basis.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what this is, but it's not obvious from the name/description. Is this something that has to be its own compute quantity? It's really just a weighting used for other calculations, and it's a constant determined by the basis modes. I think it would make more sense to have it passed in with the transforms (or even add it as an attribute to the Basis class?).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a constant which has to be re-calculated for a few other things, so to me makes sense to ahve it computed once and stored. Whether that is here or elsewhere does not really matter, but to pass it in transforms I would need to compute it in like get_transforms or something, and that will require other special logic as well. If possible I'd like to keep it as is here, if people are curious they can check the source code like the other stuff in our list of variables.

This also could be used to transform other quantities to Boozer as well, so it is useful to have as a compute quantiity I think.

@dpanici dpanici dismissed stale reviews from f0uriest and YigitElma via 84a4236 February 7, 2025 21:01
YigitElma
YigitElma previously approved these changes Feb 7, 2025
f0uriest
f0uriest previously approved these changes Feb 9, 2025
@dpanici dpanici dismissed stale reviews from f0uriest and YigitElma via f2b7711 February 10, 2025 20:22
@dpanici
Copy link
Collaborator Author

dpanici commented Feb 10, 2025

For future reference, the norm thing comes from (from my quick check here)

image

If you consider the m=0 n=0 case and plug in $\Omega$ into eq 20 (the cosine eqn specifically), you find that

$$ \begin{align} \bar{\Omega}^C_{00} &= norm\frac{1}{4\pi^2} \bar{\Omega}^C_{00}\int_0^{2\pi}\int_0^{2\pi} d\theta_B d\zeta_B\\ &= \bar{\Omega}^C_{00} norm \end{align} $$

So for the m=0 n=0 mode, norm=1 is required to recover the Boozer Fourier coefficient.

For n=0 m!=0 (in first line here, all other modes are killed by the inner product and mutual orthogonality of the trig functions)

$$ \begin{align} \bar{\Omega}^C_{m0} &= norm\frac{1}{4\pi^2} \bar{\Omega}^C_{m0}\int_0^{2\pi} d\zeta_B \int_0^{2\pi} d\theta_B cos^2(m\theta_B)\\ &= \bar{\Omega}^C_{m0} norm \frac{1}{4\pi^2} (2\pi) (\pi)\\ &= \bar{\Omega}^C_{m0} norm / 2 \end{align} $$

So for the m!=0 n=0 mode, norm=2 is required to recover the Boozer Fourier coefficient. Same thing for the m=0 n!=0 mode, and for the m!=0 n!=0 mode, you find you need norm=4

@dpanici dpanici requested review from ddudt and removed request for daniel-dudt and ddudt February 10, 2025 20:32
@dpanici dpanici merged commit e1803c7 into master Feb 10, 2025
25 checks passed
@dpanici dpanici deleted the dp/boozmn_style_output branch February 10, 2025 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants