Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
871d169
Add new integrator scripts for field tracing and guiding center dynamics
EstevaoMGomes Apr 20, 2025
f86f5ee
Improve loss functions speed
EstevaoMGomes Apr 20, 2025
408c2c5
Refine integrator analysis
EstevaoMGomes Apr 21, 2025
6ff79db
Optimize rotation matrix computation in RotatedCurve function
EstevaoMGomes Apr 27, 2025
fdb1508
Edit fo and gc integration analysis plots
EstevaoMGomes Apr 28, 2025
415bbae
Improve loss functions computational efficiency
EstevaoMGomes Apr 28, 2025
f38fdea
Feature: gradient analysis
EstevaoMGomes Apr 28, 2025
079cdb7
Add block_until_ready to integrators analysis
EstevaoMGomes May 4, 2025
fe5d81d
Minor tweaks to gradient analysis plot
EstevaoMGomes May 4, 2025
9595ab4
Create Poincare Plots analysis
EstevaoMGomes May 4, 2025
108123e
Refactor integrators analysis: add cyclotron frequency calculation an…
EstevaoMGomes May 11, 2025
c80ff2c
Change loss functions to be quadratic & implement separation loss
EstevaoMGomes May 11, 2025
ea0af03
Minor improvements in coils class
EstevaoMGomes May 11, 2025
5617e7f
Add join method to Particles class and optimize tracing parameters in…
EstevaoMGomes May 11, 2025
0bb4462
Simplify curve appending logic in apply_symmetries_to_curves
EstevaoMGomes May 11, 2025
91f8cd0
Update cyclotron frequency calculation and adjust tracing parameters …
EstevaoMGomes May 12, 2025
549a43f
Enhance Particles class with phase angle parameter and update Tracing…
EstevaoMGomes May 12, 2025
23bf271
Refactor coil separation loss function and optimize tracing parameter…
EstevaoMGomes May 12, 2025
dcef625
Tentative to incorporate pytree methods for BiotSavart class
EstevaoMGomes May 12, 2025
3c96714
Refactor Tracing class initialization and improve parameter handling …
EstevaoMGomes May 14, 2025
b1a227e
Add gc_vs_fo.py for particle tracing and visualization; adjust parame…
EstevaoMGomes May 14, 2025
8332e1e
Add output directory creation and update file saving paths in analysi…
EstevaoMGomes May 19, 2025
c64a9c1
Add comparison_coils.py for BiotSavart field analysis and performance…
EstevaoMGomes May 19, 2025
f867857
Fix errors derived from dynamics refactoring
EstevaoMGomes May 21, 2025
7d7be44
Enhance plotting in gc_integrators.py: adjust figure sizes, add toler…
EstevaoMGomes May 21, 2025
53682b6
Change dynamics to accept Integrator name
EstevaoMGomes May 24, 2025
093f11d
Add comparison_gc.py for comparing gc trajectories between SIMSOPT an…
EstevaoMGomes May 24, 2025
1c6584c
Fixed energy calculation for fo trajectories
EstevaoMGomes May 26, 2025
32b84ad
Finalize gc analysis ESSOS vs SIMSOPT
EstevaoMGomes May 26, 2025
f902e22
Add comparison script for fo tracing & improve gc script plots
EstevaoMGomes May 28, 2025
823c6db
Fixed error in dynamics when tracing fieldlines
EstevaoMGomes May 28, 2025
32c36b3
Based on work from PR #19
EstevaoMGomes Jun 6, 2025
798731d
Fix energy calls in integrators analysis
EstevaoMGomes Jun 6, 2025
c3134b9
Fixed loss functions and enhanced coil separation logic
EstevaoMGomes Jun 25, 2025
5a728c0
Fixed coils&surface opt example
EstevaoMGomes Jun 25, 2025
43dd5a0
Added extra simsopt compilation runs
EstevaoMGomes Jun 25, 2025
e6cb9fa
Added field line comparisons & minor improvements to fo and gc compar…
EstevaoMGomes Jun 25, 2025
97f2985
Improve length calculation & refactor gammas to lazy initialization &…
EstevaoMGomes Jun 26, 2025
312dab3
Fix coils.from_simsopt imports
EstevaoMGomes Jun 26, 2025
32fa067
Add loss function comparison with simsopt
EstevaoMGomes Jun 26, 2025
d4bb387
Add surface comparison with simsopt
EstevaoMGomes Jun 26, 2025
00f2160
Refactor surfaces gamma to lazy initialization & add SquaredFlux func…
EstevaoMGomes Jun 26, 2025
9c2407b
Fix Coils.from_ imports
EstevaoMGomes Jun 27, 2025
8975934
Finished surface comparison
EstevaoMGomes Jun 27, 2025
70dcaa6
Finish simsopt comparison & improve analysis plots
EstevaoMGomes Jul 9, 2025
bbf6cc4
Update Ubuntu for workflows
EstevaoMGomes Jul 9, 2025
e844b67
Merge branch 'main' into eg/analysis
EstevaoMGomes Sep 8, 2025
7d807ff
Fixed near-axis & surfaces examples
EstevaoMGomes Sep 22, 2025
9853449
Fixed merge changes
EstevaoMGomes Sep 22, 2025
1395650
Deleting comparison_simsopt folder in examples
EstevaoMGomes Sep 22, 2025
ddb2282
Changing surfaces.py to correct the number of modes used, added optio…
eduardolneto Oct 14, 2025
a0374cc
Fix(coils, fields): turned field BiotSavart into a PyTree and modifie…
EstevaoMGomes Oct 21, 2025
c7378bb
Fix: minor fixes
EstevaoMGomes Oct 27, 2025
d3b073c
Merge branch 'en/surface_modes_hotfix' into eg/analysis
EstevaoMGomes Oct 27, 2025
d40fa9c
Fix(coils): assertion removal in Coils class; Perf(coils): vmap & sep…
EstevaoMGomes Oct 28, 2025
37252ef
Fix(analysis): precompile coil gammas for comparison with simsopt
EstevaoMGomes Oct 28, 2025
df5a525
Fix(surfaces): PyTree able Surfaces
EstevaoMGomes Nov 5, 2025
a4fad74
Fix(fields,surfaces): fixed mpol in vmec import
EstevaoMGomes Nov 5, 2025
ce7caf7
Fix(surfaces): jit and pjit fix
EstevaoMGomes Nov 12, 2025
43fd404
Feat (losses): Create losses files
EstevaoMGomes Nov 17, 2025
ac5c7bc
Fix (losses): Allow for grad usage during optimization
EstevaoMGomes Nov 17, 2025
c9efcf7
Clean (losses): Move example to correct file
EstevaoMGomes Nov 17, 2025
41a0c1a
Refactor (example): Simplify coils_from_vmec_surface example with new…
EstevaoMGomes Nov 17, 2025
2324cfe
Refactor (coils): Decache gamma calculation
EstevaoMGomes Nov 17, 2025
a2af497
refactored examples folder
rogeriojorge Dec 9, 2025
455356e
Feat (example): import optimize_surface_qs from rj/quasisymmetry_surface
EstevaoMGomes Nov 18, 2025
1163af7
[fix] get_derivatives_coils_particle_confinement_guidingcenter.py
EstevaoMGomes Feb 28, 2026
08a581a
[fix] trace_particles_vmec
EstevaoMGomes Feb 28, 2026
143aa01
[fix] trace_particles_vmec_Electric_field
EstevaoMGomes Feb 28, 2026
e88e480
[fix] trace_particles_coils_guidingcenter
EstevaoMGomes Feb 28, 2026
85f1f13
[wip] trace_particles_coils_guidingcenter_with_classifier now runs bu…
EstevaoMGomes Feb 28, 2026
39255d5
Fix examples for PR #29: API alignment, path fixes, restored loss wra…
Tejas7007 Jun 10, 2026
d22a300
Address review: restore comments, clarify docstrings, justify process…
Tejas7007 Jun 11, 2026
5ab6d09
Address review: use SurfaceRZFourier classmethods instead of polymorp…
Tejas7007 Jun 19, 2026
456168d
Fix solver dropped from Tracing PyTree, clean up loss_BdotN to accept…
Tejas7007 Jun 19, 2026
f712827
Update essos/losses.py
EstevaoMGomes Jun 20, 2026
a02781b
[refac] gradients example now using new losses implementation
EstevaoMGomes Jun 26, 2026
04999b3
Changing augmented_lagrangian to comply with custom_losses
eduardolneto Jun 26, 2026
20442c0
Changing coil_perturnation and coils for coil perturbation and stocha…
eduardolneto Jun 26, 2026
d970cb7
Adding sharding safe check for number of devices, adding capability o…
eduardolneto Jun 27, 2026
fc64159
Modifying losses.py to allow custom_losses to have a val_and_grad fun…
eduardolneto Jun 27, 2026
ab1fac8
Small changes on fields.py class near_axis to work as a dependecy of …
eduardolneto Jun 27, 2026
d64823c
Removing commented section
eduardolneto Jun 29, 2026
4c24857
Adding example of coils-vmec surface optimization with augmented lagr…
eduardolneto Jun 29, 2026
378a818
Making cahce behaviour of constraints custom class closer to custom_l…
eduardolneto Jul 1, 2026
6df0a09
Correcting number of fields for LagrangeMultiplier object in tests, r…
eduardolneto Jul 1, 2026
2c7e480
Correcting example optimizing_coils_vmec_surface_augmented_lagrangian…
eduardolneto Jul 1, 2026
3760c57
Changes
eduardolneto Jul 1, 2026
4feff61
Adding missing static metadate to coils pytree
eduardolneto Jul 1, 2026
1fa359b
Adding tests for ensure_unravelers
eduardolneto Jul 1, 2026
a910710
Solving the inconsistency between call_pytree and dofs_to_pytree and …
eduardolneto Jul 1, 2026
b5514d5
Removing differentiable loss functions for loss_fraction, escape/loss…
eduardolneto Jul 1, 2026
678761c
Removing commented old sharding session, and fixing identation on add…
eduardolneto Jul 2, 2026
ec54a61
Addressed issues with Initializing particles around axis function. Re…
eduardolneto Jul 2, 2026
91c39bb
Safeguarded v_perp values and made loss_fraction_collisions behave li…
eduardolneto Jul 2, 2026
eb72e45
Modified objective_functions.py to have the B dot N losses up to date…
eduardolneto Jul 2, 2026
8a7074d
Correncting timestep input on some of the particle objectives and als…
eduardolneto Jul 2, 2026
04685b8
Adding block_size to loretnz force objective
eduardolneto Jul 2, 2026
7097381
Changing coils optimization example slightly
eduardolneto Jul 2, 2026
2059260
Added example for coil-coild, surface-coil distance, likingnumber and…
eduardolneto Jul 2, 2026
24b1009
Unifying pertubr_curves_systematic and perturb_curves_statistic into …
eduardolneto Jul 3, 2026
8f118bc
Addressing some remaining bugs
eduardolneto Jul 3, 2026
972e16e
Addressed bug with model_mu in LavembergMarquardt method in augmented…
eduardolneto Jul 3, 2026
f073dcd
Adding lazy intizalization to CoildFromGamma which was renamed to Dis…
eduardolneto Jul 4, 2026
b39f433
Changing scaling_type from 1,2,jnp.infty, to L1 or 1, L2 or 2 and Lin…
eduardolneto Jul 4, 2026
f474e62
Added similar scaling behaviour and docstrings to the Coils/Curves cl…
eduardolneto Jul 4, 2026
13ca4a4
DiscretizedCoils now also has an option to scale the geometry gammas …
eduardolneto Jul 4, 2026
f5daf56
Added assertion for val_and_grad on test_custom_loss_named_unraveler()
eduardolneto Jul 4, 2026
b4429c0
Addresing unnecessary wrapped code in test_multiobjectives.py origini…
eduardolneto Jul 5, 2026
5e5bd94
Removing breaklines on examples
eduardolneto Jul 5, 2026
b02e9f3
Removing comments on examples
eduardolneto Jul 5, 2026
43dde59
Merge pull request #36 from uwplasma/en/review_eg/augmented_lagrangian
eduardolneto Jul 7, 2026
ac3ffa4
Merge pull request #37 from uwplasma/en/review_eg/coil_perturbations_fix
eduardolneto Jul 7, 2026
799d9a1
Merge pull request #38 from uwplasma/en/review_eg/dynamics_fix
eduardolneto Jul 7, 2026
c20dd00
Merge pull request #39 from uwplasma/en/review_eg/losse_val_grad
eduardolneto Jul 7, 2026
51db1de
Merge branch 'eg/analysis' into en/review_eg/fields_surfaces_objectiv…
eduardolneto Jul 7, 2026
fae3a97
Merge pull request #40 from uwplasma/en/review_eg/fields_surfaces_obj…
eduardolneto Jul 7, 2026
079abb6
Slightly correcting bugs in modifications coils.py
eduardolneto Jul 7, 2026
0a49f9c
refactor: extracted NearAxis field calculations to standalone pyQSC_J…
Jun 8, 2026
d268330
fix: update import paths for standalone pyqsc_jax package
Jun 8, 2026
3bd9bbf
fix: add missing BiotSavart import
Jun 8, 2026
448356f
ADD Dependency for near-axis refactor
Jun 8, 2026
22c0c39
Adding sfaeguard to coils and surfaces flatten/ubnflatten methods for…
eduardolneto Jul 11, 2026
df2b80e
Removing repeated cosntructor in from_sismopt methods
eduardolneto Jul 11, 2026
10cf2e4
Adding some chanmges
eduardolneto Jul 11, 2026
78c6997
Guard Coils.dofs_currents against None/bool sentinel leaves during Py…
Tejas7007 Jul 15, 2026
f642c13
Merge pull request #43 from Tejas7007/guard-dofs-currents-for-42
eduardolneto Jul 15, 2026
f94c079
Fixing test for objective functions
eduardolneto Jul 15, 2026
5a10318
Removing line braks and changing path from file to name
eduardolneto Jul 15, 2026
b2e6f48
Removing line braks and changing path from file to name
eduardolneto Jul 15, 2026
9536e33
Fixing collisions plotting bug
eduardolneto Jul 15, 2026
074cf7f
Merge pull request #42 from uwplasma/en/review_eg/examples_fix
eduardolneto Jul 16, 2026
75899e5
Adding scaling and chnaging function to work faster
eduardolneto Jul 16, 2026
66e2dcd
Fix PyTree scaling regression in coils/surfaces; add FullOrbitAdaptat…
Tejas7007 Jul 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions debug_from_simsopt_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import os
import jax
import jax.numpy as jnp

from essos.coils import Coils
from essos.fields import BiotSavart, Vmec
from essos.constants import (
ALPHA_PARTICLE_MASS,
ALPHA_PARTICLE_CHARGE,
FUSION_ALPHA_PARTICLE_ENERGY,
)
from essos.dynamics import GuidingCenter, Particles
from essos.objective_functions import normB_axis


def describe_case(label, coils, vmec_surface, initial_xyz, initial_vpar):
print(f"\n=== {label} ===")
print("n_base_curves:", coils.curves.n_base_curves)
print("n_segments:", coils.n_segments)
print("nfp:", coils.nfp, "stellsym:", coils.stellsym)
print("dofs_curves shape:", coils.dofs_curves.shape)
print("dofs_currents_raw shape:", coils.dofs_currents_raw.shape)
print("currents raw min/max:", float(jnp.min(coils.dofs_currents_raw)), float(jnp.max(coils.dofs_currents_raw)))
print("currents scale:", float(coils.currents_scale))
print("currents normalized min/max:", float(jnp.min(coils.dofs_currents)), float(jnp.max(coils.dofs_currents)))
print("gamma shape:", coils.gamma.shape)
print("gamma finite:", bool(jnp.all(jnp.isfinite(coils.gamma))))
print("gamma_dash finite:", bool(jnp.all(jnp.isfinite(coils.gamma_dash))))
print("gamma_dashdash finite:", bool(jnp.all(jnp.isfinite(coils.gamma_dashdash))))

field = BiotSavart(coils)
B_axis = normB_axis(field, npoints=200)
print("axis B mean before renorm:", float(jnp.mean(B_axis)))
coils.dofs_currents = coils.dofs_currents * 5.7 / jnp.mean(B_axis)
field = BiotSavart(coils)
print("axis B mean after renorm:", float(jnp.mean(normB_axis(field, npoints=200))))

print("surface gamma finite:", bool(jnp.all(jnp.isfinite(vmec_surface.gamma))))
print("initial xyz:", initial_xyz)
print("field.B(initial):", field.B(initial_xyz))
print("field.AbsB(initial):", float(field.AbsB(initial_xyz)))
print("field.dAbsB_by_dX(initial):", field.dAbsB_by_dX(initial_xyz))
print("field.curl_b(initial):", field.curl_b(initial_xyz))
print("field.kappa(initial):", field.kappa(initial_xyz))

finite_checks = {
"B": jnp.all(jnp.isfinite(field.B(initial_xyz))),
"AbsB": jnp.isfinite(field.AbsB(initial_xyz)),
"dAbsB_by_dX": jnp.all(jnp.isfinite(field.dAbsB_by_dX(initial_xyz))),
"curl_b": jnp.all(jnp.isfinite(field.curl_b(initial_xyz))),
"kappa": jnp.all(jnp.isfinite(field.kappa(initial_xyz))),
}
print("finite checks:", {k: bool(v) for k, v in finite_checks.items()})

particles = Particles(
initial_xyz=jnp.expand_dims(initial_xyz, 0),
mass=ALPHA_PARTICLE_MASS,
charge=ALPHA_PARTICLE_CHARGE,
energy=FUSION_ALPHA_PARTICLE_ENERGY,
)
initial_condition = jnp.array([initial_xyz[0], initial_xyz[1], initial_xyz[2], initial_vpar])
rhs = GuidingCenter(0.0, initial_condition, (field, particles, type("E", (), {"E_covariant": lambda self, x: jnp.zeros(3)})()))
print("GuidingCenter rhs:", rhs)
print("GuidingCenter rhs finite:", bool(jnp.all(jnp.isfinite(rhs))))


def main():
print(jax.devices())

simsopt_json = os.path.join("examples", "input_files", "QH_simple_scaled.json")
wout_file = os.path.join("examples", "input_files", "wout_QH_simple_scaled.nc")
vmec = Vmec(wout_file)

R0 = 17.0
initial_xyz = jnp.array([R0, 0.0, 0.0])
initial_vpar = 0.0

coils_true = Coils.from_simsopt(simsopt_json, nfp=4, stellsym=True)
describe_case("from_simsopt stellsym=True", coils_true, vmec.surface, initial_xyz, initial_vpar)

coils_false = Coils.from_simsopt(simsopt_json, nfp=4, stellsym=False)
describe_case("from_simsopt stellsym=False", coils_false, vmec.surface, initial_xyz, initial_vpar)

from simsopt import load

bs = load(simsopt_json)
base_coils = bs.coils[:6]
print("\n=== direct simsopt base coils ===")
print("n base coils:", len(base_coils))
print("current values:", [float(c.current.get_value()) for c in base_coils])
print("curve gamma shape:", jnp.asarray(base_coils[0].curve.gamma()).shape)
print("curve gamma first point:", jnp.asarray(base_coils[0].curve.gamma())[0])


if __name__ == "__main__":
main()
4 changes: 3 additions & 1 deletion essos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import jax.numpy as jnp
import matplotlib.pyplot as plt
from essos.coils import Coils, CreateEquallySpacedCurves
from essos.fields import near_axis, BiotSavart
from essos.fields import BiotSavart
from pyqsc_jax.near_axis import near_axis

from essos.dynamics import Tracing
from essos.optimization import optimize_loss_function
from essos.objective_functions import loss_coils_for_nearaxis
Expand Down
Loading
Loading