Skip to content

Conversation

@joaopedrobiu6
Copy link
Collaborator

@joaopedrobiu6 joaopedrobiu6 commented Nov 27, 2024

This adds an Objective ParticleTracer that uses the guiding center equations of motion to trace particles' trajectories given a DESC Equilibrium. The goal of this objective is to optimize the equilibrium directly from quantities measured from the trajectories traced, e.g. the deviation from the initial flux surface.
It currently supports one-particle tracing and optimization of the equilibrium from that trajectory, and multiple-particle tracing. The optimization of the equilibrium from the multi-particle tracing is not yet fixed

TO DO LIST:

  • Run with fwd mode for deriv mode, and see if that fixes the NaNs with multiple particles
  • Run with the same particle twice, see if NaN occurs (make sure the conditions used worked with a single particle)
  • Look at the trajectories for the particles in the case where the optimization gets NaN on the first iteration. Did some exit the equilibrium (psi > 1)?
  • How to deal with particle trajectories that exit plasma (psi > 1)? Probably should just cut off integration there, since past the boundary any field info from DESC is nonsense and we do not want to be integrating the particles there
  • Make a tutorial notebook showing how to use
  • Move from jax.experimental to diffrax

This was developed by @joaopedrobiu6, @dpanici, @f0uriest and @rogeriojorge.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -1.54 +/- 8.94     | -8.55e-03 +/- 4.98e-02 |  5.48e-01 +/- 4.8e-02  |  5.56e-01 +/- 1.3e-02  |
 test_equilibrium_init_medres            |     +0.19 +/- 2.79     | +7.54e-03 +/- 1.10e-01 |  3.96e+00 +/- 8.4e-02  |  3.95e+00 +/- 7.1e-02  |
 test_equilibrium_init_highres           |     -0.68 +/- 2.13     | -3.34e-02 +/- 1.04e-01 |  4.86e+00 +/- 5.9e-02  |  4.90e+00 +/- 8.6e-02  |
 test_objective_compile_dshape_current   |     +1.95 +/- 6.05     | +5.80e-02 +/- 1.80e-01 |  3.03e+00 +/- 1.2e-01  |  2.98e+00 +/- 1.3e-01  |
-test_objective_compute_dshape_current   |    +39.76 +/- 2.64     | +1.44e-03 +/- 9.52e-05 |  5.05e-03 +/- 4.4e-05  |  3.61e-03 +/- 8.5e-05  |
 test_objective_jac_dshape_current       |     +5.12 +/- 7.23     | +1.99e-03 +/- 2.81e-03 |  4.09e-02 +/- 2.3e-03  |  3.89e-02 +/- 1.6e-03  |
-test_perturb_2                          |     +6.30 +/- 1.77     | +9.92e-01 +/- 2.78e-01 |  1.67e+01 +/- 1.1e-01  |  1.57e+01 +/- 2.6e-01  |
 test_proximal_jac_atf_with_eq_update    |     +0.43 +/- 1.37     | +7.42e-02 +/- 2.38e-01 |  1.75e+01 +/- 8.1e-02  |  1.74e+01 +/- 2.2e-01  |
 test_proximal_freeb_jac                 |     +0.87 +/- 1.58     | +5.13e-02 +/- 9.32e-02 |  5.94e+00 +/- 6.3e-02  |  5.89e+00 +/- 6.9e-02  |
 test_solve_fixed_iter_compiled          |     +8.58 +/- 3.92     | +1.55e+00 +/- 7.08e-01 |  1.96e+01 +/- 3.5e-01  |  1.81e+01 +/- 6.2e-01  |
-test_LinearConstraintProjection_build   |    +33.62 +/- 3.46     | +2.84e+00 +/- 2.92e-01 |  1.13e+01 +/- 2.1e-01  |  8.44e+00 +/- 2.0e-01  |
 test_objective_compute_ripple_spline    |    +13.39 +/- 7.96     | +4.41e-02 +/- 2.62e-02 |  3.73e-01 +/- 2.5e-02  |  3.29e-01 +/- 6.9e-03  |
 test_objective_grad_ripple_spline       |     +2.18 +/- 3.66     | +3.26e-02 +/- 5.48e-02 |  1.53e+00 +/- 2.8e-02  |  1.50e+00 +/- 4.7e-02  |
 test_build_transform_fft_midres         |     -0.45 +/- 7.85     | -2.50e-03 +/- 4.35e-02 |  5.52e-01 +/- 3.8e-02  |  5.55e-01 +/- 2.1e-02  |
 test_build_transform_fft_highres        |     +2.30 +/- 3.87     | +1.94e-02 +/- 3.26e-02 |  8.62e-01 +/- 1.6e-02  |  8.42e-01 +/- 2.9e-02  |
 test_equilibrium_init_lowres            |     +5.48 +/- 3.07     | +1.97e-01 +/- 1.10e-01 |  3.78e+00 +/- 7.1e-02  |  3.59e+00 +/- 8.4e-02  |
 test_objective_compile_atf              |     +6.04 +/- 2.76     | +3.68e-01 +/- 1.68e-01 |  6.46e+00 +/- 1.1e-01  |  6.10e+00 +/- 1.3e-01  |
-test_objective_compute_atf              |    +67.09 +/- 7.78     | +6.06e-03 +/- 7.02e-04 |  1.51e-02 +/- 6.8e-04  |  9.03e-03 +/- 1.8e-04  |
 test_objective_jac_atf                  |     -0.52 +/- 2.08     | -9.30e-03 +/- 3.72e-02 |  1.78e+00 +/- 1.9e-02  |  1.79e+00 +/- 3.2e-02  |
 test_perturb_1                          |     +1.68 +/- 4.59     | +2.23e-01 +/- 6.11e-01 |  1.35e+01 +/- 3.4e-01  |  1.33e+01 +/- 5.0e-01  |
 test_proximal_jac_atf                   |     -0.25 +/- 1.57     | -1.95e-02 +/- 1.25e-01 |  7.91e+00 +/- 4.0e-02  |  7.93e+00 +/- 1.2e-01  |
 test_proximal_freeb_compute             |     +6.22 +/- 3.17     | +1.03e-02 +/- 5.24e-03 |  1.75e-01 +/- 3.7e-03  |  1.65e-01 +/- 3.7e-03  |
 test_solve_fixed_iter                   |     +0.57 +/- 3.87     | +1.63e-01 +/- 1.11e+00 |  2.89e+01 +/- 8.1e-01  |  2.87e+01 +/- 7.6e-01  |
 test_objective_compute_ripple           |     +0.06 +/- 1.78     | +1.71e-03 +/- 5.06e-02 |  2.84e+00 +/- 3.7e-02  |  2.84e+00 +/- 3.4e-02  |
 test_objective_grad_ripple              |     -2.86 +/- 2.05     | -2.16e-01 +/- 1.55e-01 |  7.34e+00 +/- 3.3e-02  |  7.55e+00 +/- 1.5e-01  |

dpanici and others added 6 commits March 6, 2025 12:00
…article based on the dimension of the initial conditions. `particle_tracer.py` and `optimization.py` are adapted to this change.

Optimization doesn't work yet
Automatically chooses single or multiparticle based on the dimension of
the initial conditions. `particle_tracer.py` and `optimization.py` are
adapted to this change.

Optimization doesn't work yet
@dpanici
Copy link
Collaborator

dpanici commented Aug 20, 2025

Close once #1820 is in

YigitElma added a commit that referenced this pull request Dec 8, 2025
This PR is a combination of #734 and #1410.

The main structure is under discussion in #1657.


- Adds particle tracing capabilities in ``desc.particles`` module.
- Particle tracing is done via ``desc.particles.trace_particles``
function.
    - Particles can be initialized in couple different ways:
- ``ManualParticleInitializerLab`` : Initializes particles at given
positions in lab coordinates.
- ``ManualParticleInitializerFlux`` : Initializes particles at given
positions in flux coordinates.
- ``CurveParticleInitializer`` : Initializes N particles on a given
curve.
- ``SurfaceParticleInitializer`` : Initializes N particles on a given
surface.
    - Implemented particle trajectory models are:
- ``VacuumGuidingCenterTrajectory`` : Integrates the particle motion by
vacuum guiding center ODEs, conserving energy and mu.
- Particle trajectories can be plotted with
``desc.plotting.plot_particle_trajectories`` function.

We can delete #734 and #1410 once this is merged.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: joaopedrobiu6 <joaopedrofbiu@tecnico.ulisboa.pt>
Co-authored-by: Dario Panici <dpanici@princeton.edu>
Co-authored-by: Daniel Dudt <33005725+ddudt@users.noreply.github.com>
Co-authored-by: Dario Panici <37969854+dpanici@users.noreply.github.com>
Co-authored-by: Rory Conlin <roryconlin@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Kaya Unalmis <kayaunalmis@proton.me>
Co-authored-by: Rahul Gaur <19224702+rahulgaur104@users.noreply.github.com>
@YigitElma
Copy link
Collaborator

Closing as it is completed in #1820

@YigitElma YigitElma closed this Dec 8, 2025
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