Skip to content

SurfaceRZFourier conversion to Desc format - #628

Open
mishapadidar wants to merge 9 commits into
masterfrom
mp_surfacerzfourier_desc
Open

SurfaceRZFourier conversion to Desc format#628
mishapadidar wants to merge 9 commits into
masterfrom
mp_surfacerzfourier_desc

Conversation

@mishapadidar

@mishapadidar mishapadidar commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary
This PR introduces new methods to convert SurfaceRZFourier objects to and from the equivalent Desc format, FourierRZToroidalSurface. The methods are covered by unit tests which convert stellarator-symmetric and non-stellarator symmetric surfaces.

New Methods
Two new methods have been added to the SurfaceRZFourier class:

  • to_desc: converts an instance of a surface to the Desc format,
  • from_desc: a class method that builds a SurfaceRZFourier object from an existing Desc FourierRZToroidalSurface.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds bidirectional conversion between SurfaceRZFourier and DESC’s FourierRZToroidalSurface, with a roundtrip unit test to validate geometry preservation.

Changes:

  • Implement SurfaceRZFourier.from_desc(...) to build a Simsopt surface from a DESC surface.
  • Implement SurfaceRZFourier.to_desc() to export a Simsopt surface to DESC.
  • Add a DESC-enabled roundtrip test using VMEC input files.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/simsopt/geo/surfacerzfourier.py Adds to_desc / from_desc conversion logic and DESC imports/guards.
tests/geo/test_surface_rzfourier.py Adds a DESC roundtrip test to validate conversion preserves geometry and metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/simsopt/geo/surfacerzfourier.py Outdated
Comment thread src/simsopt/geo/surfacerzfourier.py
Comment thread src/simsopt/geo/surfacerzfourier.py
Comment thread tests/geo/test_surface_rzfourier.py Outdated
Comment thread tests/geo/test_surface_rzfourier.py Outdated
@mishapadidar
mishapadidar requested a review from Copilot May 8, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread tests/geo/test_surface_rzfourier.py
Comment thread src/simsopt/geo/surfacerzfourier.py
Comment thread src/simsopt/geo/surfacerzfourier.py
Comment thread src/simsopt/geo/surfacerzfourier.py Outdated
Comment on lines +600 to +601
@SimsoptRequires(DescFourierRZToroidalSurface is not None, "to_desc method requires Desc module")
def to_desc(self) -> DescFourierRZToroidalSurface:
Comment thread src/simsopt/geo/surfacerzfourier.py
@codecov

codecov Bot commented May 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.46%. Comparing base (5bd3f05) to head (3e68924).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #628      +/-   ##
==========================================
+ Coverage   90.42%   90.46%   +0.03%     
==========================================
  Files          84       84              
  Lines       17899    17953      +54     
==========================================
+ Hits        16186    16242      +56     
+ Misses       1713     1711       -2     
Flag Coverage Δ
unittests 90.46% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/simsopt/geo/surfacerzfourier.py 96.52% <100.00%> (+0.19%) ⬆️

... and 1 file with indirect coverage changes

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

Comment thread .github/workflows/tests.yml
Comment thread tests/geo/test_surface_rzfourier.py Outdated
Comment thread tests/geo/test_surface_rzfourier.py Outdated
Comment thread tests/geo/test_surface_rzfourier.py Outdated
@unittest.skipIf(DescFourierRZToroidalSurface is None, "desc python extension is not installed")
def test_to_from_desc_roundtrip(self):
"""Test that to_desc and from_desc correctly converts DESC surface back to simsopt."""
import os

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Move import os to top of file

Comment thread tests/geo/test_surface_rzfourier.py Outdated
Comment thread tests/geo/test_surface_rzfourier.py Outdated
Comment thread src/simsopt/geo/surfacerzfourier.py Outdated
return simsopt_surface

@SimsoptRequires(DescFourierRZToroidalSurface is not None, "to_desc method requires Desc module")
def to_desc(self) -> DescFourierRZToroidalSurface:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about add check_orientation=True as a kwarg to this method here that gets passed to line 638, so users have more control over whether the orientation is flipped or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. We default to check_orientation=False, so that from_desc(to_desc(...))) is the identity.

@mishapadidar
mishapadidar requested a review from landreman July 29, 2026 19:02
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.

3 participants