Skip to content

Major refactoring for JAX-style classes.#29

Open
EstevaoMGomes wants to merge 77 commits into
mainfrom
eg/analysis
Open

Major refactoring for JAX-style classes.#29
EstevaoMGomes wants to merge 77 commits into
mainfrom
eg/analysis

Conversation

@EstevaoMGomes

Copy link
Copy Markdown
Collaborator

Refactor of coils & surfaces to be proper PyTrees;
Added a loss wrapper to differentiate with respect to the dogs (PyTree leaves);
Added analysis & validation of the code

- Implemented `fo_integrators.py` for full orbit tracing with various methods and parameters.
- Implemented `gc_integrators.py` for guiding center dynamics with adaptative and constant step sizes.
- Enhanced `Tracing` class in `dynamics.py` to support multiple methods and step sizes.
…ance plots, and improve layout for better visualization
@EstevaoMGomes

Copy link
Copy Markdown
Collaborator Author

Tests need fixing;
All examples should be fixed;
Future (minor) changes may affect some examples, such as turning gamma from a property to a function;
Coils should have the normalized dofs as leaves and should not update the normalization at runtime.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR implements a major refactoring to make coils and surfaces proper JAX PyTrees, enabling automatic differentiation. It introduces a new loss wrapper system for gradient-based optimization and adds comprehensive analysis and validation code comparing ESSOS with SIMSOPT.

Key changes:

  • Refactored Coils, Curves, SurfaceRZFourier, and BiotSavart classes as JAX PyTrees with proper tree flattening/unflattening
  • Added essos/losses.py with custom_loss and composite_loss classes for differentiable loss functions
  • Updated API: Coils_from_json()Coils.from_json(), tracing.energy property → tracing.energy() method
  • Added extensive analysis scripts for validation against SIMSOPT

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 39 comments.

Show a summary per file
File Description
essos/losses.py New module implementing base_loss, custom_loss, and composite_loss classes for automatic differentiation
essos/surfaces.py Refactored SurfaceRZFourier as PyTree with cached properties and improved initialization
essos/coils.py Refactored Curves and Coils as PyTrees with cached properties, changed to classmethod constructors
essos/fields.py Added MagneticField base class and registered BiotSavart as PyTree
essos/dynamics.py Changed energy from cached property to method, added Particles.join() method
essos/objective_functions.py Removed deprecated loss functions, added new coil separation and curvature losses
essos/optimization.py Updated surface instantiation to include mpol/ntor parameters
examples/optimize_coils_vmec_surface.py Major rewrite using new loss wrapper API instead of old optimization functions
examples/trace_particles_coils_guidingcenter.py Updated imports and API calls (from_json, energy method)
examples/trace_fieldlines_coils.py Updated to use Coils.from_json()
examples/optimize_coils_particle_confinement_fullorbit.py Minor formatting and parameter updates
examples/optimize_coils_and_surface.py Added mpol/ntor parameters, simplified loss calculations
examples/input_files/*. Updated VMEC input file coefficients
examples/comparisons_SIMSOPT/*.py Deleted old comparison scripts
examples/compare_guidingcenter_fullorbit.py Updated particle initialization and energy calculation
analysis/*.py New analysis scripts for validation and benchmarking

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

Comment thread essos/coils.py
Comment thread essos/surfaces.py
Comment thread essos/surfaces.py
Comment thread essos/losses.py Outdated
Comment thread examples/comparisons_simsopt/coils.py
Comment thread examples/comparisons_simsopt/guiding_center.py
Comment thread examples/paper/poincare_plots.py Outdated
Comment thread examples/paper/poincare_plots.py Outdated
Comment thread examples/comparisons_simsopt/surfaces.py Outdated
Comment thread examples/coil_optimization/optimize_coils_vmec_surface.py
@rogeriojorge rogeriojorge mentioned this pull request Jun 5, 2026
Tejas7007 and others added 5 commits June 20, 2026 10:08
…ppers, solver kwarg in Tracing, override setters for Curves gamma
Copilot review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@EstevaoMGomes EstevaoMGomes marked this pull request as ready for review June 20, 2026 08:20
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