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

Move basis change to main compute function #1027

Merged
merged 79 commits into from
Jul 11, 2024
Merged

Move basis change to main compute function #1027

merged 79 commits into from
Jul 11, 2024

Conversation

YigitElma
Copy link
Collaborator

@YigitElma YigitElma commented May 20, 2024

Resolves #992
Resolves #1088

All compute quantities are now returned in toroidal $(R,\phi,Z)$ coordinates.

TODO:

  • Implement _curve computes too
  • Add test_compute_everthing_xyz

Copy link
Contributor

github-actions bot commented May 20, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.15 +/- 7.20     | +7.85e-04 +/- 3.70e-02 |  5.15e-01 +/- 3.6e-02  |  5.14e-01 +/- 8.9e-03  |
 test_build_transform_fft_midres         |     -0.75 +/- 4.36     | -4.54e-03 +/- 2.63e-02 |  5.98e-01 +/- 1.9e-02  |  6.02e-01 +/- 1.8e-02  |
 test_build_transform_fft_highres        |     -1.39 +/- 5.44     | -1.45e-02 +/- 5.66e-02 |  1.02e+00 +/- 3.9e-02  |  1.04e+00 +/- 4.1e-02  |
 test_equilibrium_init_lowres            |     +0.57 +/- 4.00     | +2.12e-02 +/- 1.50e-01 |  3.76e+00 +/- 1.4e-01  |  3.74e+00 +/- 4.1e-02  |
 test_equilibrium_init_medres            |     +1.76 +/- 2.35     | +7.36e-02 +/- 9.81e-02 |  4.25e+00 +/- 8.6e-02  |  4.17e+00 +/- 4.8e-02  |
 test_equilibrium_init_highres           |     +0.45 +/- 1.83     | +2.55e-02 +/- 1.03e-01 |  5.69e+00 +/- 8.1e-02  |  5.66e+00 +/- 6.5e-02  |
 test_objective_compile_dshape_current   |     -0.47 +/- 1.35     | -1.81e-02 +/- 5.17e-02 |  3.80e+00 +/- 4.3e-02  |  3.82e+00 +/- 2.9e-02  |
 test_objective_compile_atf              |     +0.58 +/- 1.94     | +4.78e-02 +/- 1.60e-01 |  8.26e+00 +/- 9.6e-02  |  8.22e+00 +/- 1.3e-01  |
 test_objective_compute_dshape_current   |     +0.45 +/- 3.33     | +5.58e-06 +/- 4.17e-05 |  1.26e-03 +/- 2.6e-05  |  1.25e-03 +/- 3.3e-05  |
 test_objective_compute_atf              |     -0.33 +/- 4.46     | -1.42e-05 +/- 1.89e-04 |  4.23e-03 +/- 1.3e-04  |  4.25e-03 +/- 1.4e-04  |
 test_objective_jac_dshape_current       |     +6.26 +/- 11.12    | +2.28e-03 +/- 4.06e-03 |  3.88e-02 +/- 3.7e-03  |  3.65e-02 +/- 1.8e-03  |
 test_objective_jac_atf                  |     -0.86 +/- 2.85     | -1.62e-02 +/- 5.36e-02 |  1.86e+00 +/- 3.0e-02  |  1.88e+00 +/- 4.4e-02  |
 test_perturb_1                          |     -0.13 +/- 1.53     | -1.74e-02 +/- 2.01e-01 |  1.31e+01 +/- 1.6e-01  |  1.32e+01 +/- 1.3e-01  |
 test_perturb_2                          |     -0.79 +/- 1.32     | -1.45e-01 +/- 2.42e-01 |  1.82e+01 +/- 2.1e-01  |  1.84e+01 +/- 1.2e-01  |
 test_proximal_jac_atf                   |     +0.12 +/- 1.08     | +8.69e-03 +/- 7.94e-02 |  7.35e+00 +/- 7.2e-02  |  7.34e+00 +/- 3.4e-02  |
 test_proximal_freeb_compute             |     -1.03 +/- 1.01     | -1.85e-03 +/- 1.81e-03 |  1.77e-01 +/- 1.4e-03  |  1.79e-01 +/- 1.1e-03  |
 test_proximal_freeb_jac                 |     -0.74 +/- 1.29     | -5.45e-02 +/- 9.55e-02 |  7.35e+00 +/- 5.3e-02  |  7.41e+00 +/- 7.9e-02  |
 test_solve_fixed_iter                   |     +1.24 +/- 9.37     | +1.84e-01 +/- 1.39e+00 |  1.51e+01 +/- 1.0e+00  |  1.49e+01 +/- 9.4e-01  |

@YigitElma
Copy link
Collaborator Author

So, the point of this PR is to get rid of repeated code. But if I do so, the test test_data_index_deps fails because we don't have data["phi"] inside compute functions anymore. I can try to add phi in that test. But I want to see all other tests pass first.

Copy link

codecov bot commented May 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.24%. Comparing base (56befac) to head (c6792ff).
Report is 2103 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1027      +/-   ##
==========================================
+ Coverage   94.97%   95.24%   +0.27%     
==========================================
  Files          87       87              
  Lines       21822    21633     -189     
==========================================
- Hits        20726    20605     -121     
+ Misses       1096     1028      -68     
Files with missing lines Coverage Δ
desc/coils.py 96.91% <100.00%> (ø)
desc/compute/__init__.py 100.00% <ø> (ø)
desc/compute/_basis_vectors.py 100.00% <ø> (+12.88%) ⬆️
desc/compute/_curve.py 100.00% <100.00%> (+0.54%) ⬆️
desc/compute/_surface.py 100.00% <100.00%> (+2.59%) ⬆️
desc/compute/data_index.py 96.66% <100.00%> (ø)
desc/compute/utils.py 96.36% <100.00%> (+0.18%) ⬆️
desc/equilibrium/equilibrium.py 96.30% <100.00%> (+<0.01%) ⬆️
desc/geometry/core.py 95.91% <100.00%> (ø)
desc/magnetic_fields/_core.py 96.40% <100.00%> (ø)
... and 1 more

@@ -140,6 +140,16 @@ def _compute(
data = data_index[parameterization][name]["fun"](
params=params, transforms=transforms, profiles=profiles, data=data, **kwargs
)
# to reduce repeated code, for 3D and naturally in rtz but desired in xyz basis
# quantities can be converted to xyz basis here
if (
Copy link
Collaborator

Choose a reason for hiding this comment

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

move this outside of recursive, have _compute functions assume things come in in rpz

@dpanici
Copy link
Collaborator

dpanici commented May 22, 2024

Enforce passed-in data is in rpz always (add to docstring)

@YigitElma YigitElma marked this pull request as draft May 27, 2024 18:16
# handle this.
assert queried_deps[p][name]["data"].issubset(
data | axis_limit_data
), err_msg
Copy link
Collaborator

@unalmis unalmis May 27, 2024

Choose a reason for hiding this comment

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

If you can't find a better way, then let's instead subtract phi from the latter set. FYI we removed the tests that ensures everything can be computed individually, i.e. without computing the entire dependency tree, and replaced it with this test which explicitly checks for this via inspecting the source code. For functions like the third derivatives of the basis vectors it's useful to keep this check as strict as possible.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Substracting "phi" may cause problems since we only want to remove it if the quantity is one of the 3d vectors which changed basis in the main compute function.
This was a temporary change. i will think of a better way to do it, once I finish the actual coding part.

Copy link
Member

Choose a reason for hiding this comment

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

I think this should be ok? We're ensuring that the dependencies are a subset of what actually gets computed right? as opposed to ensuring equality?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually since we deleted phi from dependencies, the previous version of this test might still be passing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@YigitElma In that case can you change this back

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nevermind I changed it back on my branch.

desc/compute/utils.py Outdated Show resolved Hide resolved
@YigitElma
Copy link
Collaborator Author

Make every compute function to return in rpz by default and make all of the basis changes in main compute function

tests/test_compute_funs.py Outdated Show resolved Hide resolved
@ddudt ddudt requested a review from f0uriest July 10, 2024 17:03
f0uriest
f0uriest previously approved these changes Jul 10, 2024
ddudt
ddudt previously approved these changes Jul 11, 2024
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.

We should wait to get an approval from at least one person who hasn't contributed to this PR.

@@ -248,8 +282,8 @@ def get_profiles(keys, obj, grid=None, has_axis=False, jitable=False, **kwargs):
Grid to compute quantity on.
has_axis : bool
Whether the grid to compute on has a node on the magnetic axis.
jitable: bool
Copy link
Collaborator

Choose a reason for hiding this comment

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

This was unused?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes it was

@@ -66,7 +66,7 @@ def test_frenet(self):
c.flip([0, 1, 0])
c.translate([1, 1, 1])
data = c.compute(
["frenet_tangent", "frenet_normal", "frenet_binormal"], basis="xyz", grid=0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting that these vectors are the same in xyz and rpz

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not confident they were being computed correctly on master

Copy link
Collaborator

@dpanici dpanici left a comment

Choose a reason for hiding this comment

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

Just realized, we should update the change log to reflect this as it's pretty major (that by default the compute function will return things in rpz, as before I think it wasn't always the case?)

@daniel-dudt daniel-dudt dismissed stale reviews from ddudt and f0uriest via c6792ff July 11, 2024 15:04
@ddudt ddudt requested review from dpanici, f0uriest and ddudt July 11, 2024 15:04
@f0uriest f0uriest merged commit 0fbee18 into master Jul 11, 2024
18 checks passed
@f0uriest f0uriest deleted the yge/rpz2xyz branch July 11, 2024 17:39
@dpanici dpanici mentioned this pull request Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix Something was fixed
Projects
None yet
6 participants