Skip to content

Conversation

@ddudt
Copy link
Collaborator

@ddudt ddudt commented Jan 7, 2026

Resolves #1840

Restructures and generalizes the Grid classes. The new ABC AbstractGrid that all other grids inherit from does not assume a particular coordinate system. The new ABC AbstractRTZGrid is specific to ($\rho,\theta,\zeta$) coordinates and is the parent class of all existing grid classes in flux coordinates. Most of the changes involved moving existing code into one of these new ABCs.

The goal is to allow for new grid classes in the future that represent other coordinate systems, without changing the existing public API.

To-Do:

  • Ensure tests pass
  • Generalize Basis dimensions (no references to flux coords)
  • Include isinstance(grid, AbstractRTZGrid) checks wherever appropriate
  • Add 1D grids for coil filaments
  • Deprecate flux grid class names like Grid -> RTZGrid, etc.

@ddudt ddudt self-assigned this Jan 7, 2026
@ddudt ddudt added interface New feature or request to make the code more usable or compatibility with another code functionality New feature or request to do things the code can't do now. enhancement General label for enhancement. Please also tag with "Speed", "Interface", "Functionality", etc labels Jan 7, 2026
and self.grid.NFP != self.basis.NFP
and self.basis.N != 0
and grid.node_pattern != "custom"
and not isinstance(grid, Grid)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is equivalent to the old code, since the old Grid class was hard-coded to have node_pattern="custom". In the new code, node_pattern is only an attribute of the ConcentricGrid class.

)
def bounds(self):
"""Bounds of coordinates."""
return ((0, 1), (0, 2 * np.pi), (0, 2 * np.pi))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The toroidal bound is $2\pi$ and not $2\pi/N_{FP}$ because we want the weights to be scaled to the full volume of the torus.

@dpanici
Copy link
Collaborator

dpanici commented Jan 7, 2026

Add checks in objectives and inside geometric/magneticfield/coil compute methods to ensure grids passed in are correct (i.e. 1D for a filament coil, 3D for finite build coil, 1D or 2D rtz for surface)

@dpanici
Copy link
Collaborator

dpanici commented Jan 7, 2026

Rename AbstractRTZGrid to AbstractGridFlux instead of RTZ

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Memory benchmark result

|               Test Name                |      %Δ      |    Master (MB)     |      PR (MB)       |    Δ (MB)    |    Time PR (s)     |  Time Master (s)   |
| -------------------------------------- | ------------ | ------------------ | ------------------ | ------------ | ------------------ | ------------------ |
  test_objective_jac_w7x                 |   -0.50 %    |     4.033e+03      |     4.013e+03      |    -20.25    |       40.97        |       37.67        |
  test_proximal_jac_w7x_with_eq_update   |    1.69 %    |     6.506e+03      |     6.616e+03      |    109.96    |       165.34       |       164.95       |
  test_proximal_freeb_jac                |   -0.17 %    |     1.321e+04      |     1.319e+04      |    -21.93    |       88.77        |       86.16        |
  test_proximal_freeb_jac_blocked        |    0.09 %    |     7.530e+03      |     7.536e+03      |     6.49     |       76.94        |       74.81        |
  test_proximal_freeb_jac_batched        |   -0.35 %    |     7.500e+03      |     7.474e+03      |    -26.36    |       76.44        |       75.43        |
  test_proximal_jac_ripple               |   -1.76 %    |     3.482e+03      |     3.421e+03      |    -61.16    |       69.44        |       67.92        |
  test_proximal_jac_ripple_bounce1d      |   -0.80 %    |     3.588e+03      |     3.559e+03      |    -28.87    |       82.30        |       79.68        |
  test_eq_solve                          |    1.61 %    |     2.001e+03      |     2.034e+03      |    32.29     |       97.01        |       96.62        |

For the memory plots, go to the summary of Memory Benchmarks workflow and download the artifact.

x = x.reshape(shape, order="F")
return x

def copy_data_from_other(self, x, other_grid, surface_label="rho", tol=1e-14):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't like having a default surface_label="rho" now that this ABC is for general coordinates. But this was the previous default, so it would break old code if we changed or removed it. Same for the compress and expand methods above.

This is still likely the most common use case, so I'm fine with keeping it as the default even though it feels awkward.

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 91.56627% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.69%. Comparing base (8ad49a0) to head (f5c3e2f).

Files with missing lines Patch % Lines
desc/grid/flux.py 76.35% 35 Missing ⚠️
desc/grid/core.py 93.44% 12 Missing ⚠️
desc/grid/utils.py 98.56% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2053      +/-   ##
==========================================
- Coverage   95.75%   95.69%   -0.07%     
==========================================
  Files         102      105       +3     
  Lines       28344    28467     +123     
==========================================
+ Hits        27141    27241     +100     
- Misses       1203     1226      +23     
Files with missing lines Coverage Δ
desc/basis.py 97.74% <100.00%> (ø)
desc/equilibrium/coords.py 88.39% <100.00%> (ø)
desc/equilibrium/equilibrium.py 96.08% <100.00%> (ø)
desc/equilibrium/initial_guess.py 93.79% <100.00%> (ø)
desc/geometry/core.py 95.30% <100.00%> (ø)
desc/grid/__init__.py 100.00% <100.00%> (ø)
desc/integrals/surface_integral.py 100.00% <100.00%> (ø)
desc/magnetic_fields/_core.py 96.61% <100.00%> (ø)
desc/objectives/_bootstrap.py 97.43% <100.00%> (+0.03%) ⬆️
desc/objectives/_coils.py 99.41% <100.00%> (ø)
... and 14 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement General label for enhancement. Please also tag with "Speed", "Interface", "Functionality", etc functionality New feature or request to do things the code can't do now. interface New feature or request to make the code more usable or compatibility with another code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Grid API

5 participants