DESC icon indicating copy to clipboard operation
DESC copied to clipboard

Particle Tracing

Open f0uriest opened this issue 2 years ago • 8 comments

Adds functionality for tracing particles in an arbitrary MagneticField, using either guiding center or full orbit equations.

f0uriest avatar Nov 03 '23 23:11 f0uriest

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -6.87 +/- 5.59     | -1.39e-03 +/- 1.13e-03 |  1.89e-02 +/- 1.3e-04  |  2.03e-02 +/- 1.1e-03  |
 test_build_transform_fft_midres         |     -0.07 +/- 1.05     | -7.41e-05 +/- 1.17e-03 |  1.11e-01 +/- 5.0e-04  |  1.11e-01 +/- 1.1e-03  |
 test_build_transform_fft_highres        |     -0.23 +/- 1.35     | -1.16e-03 +/- 6.99e-03 |  5.15e-01 +/- 3.3e-03  |  5.16e-01 +/- 6.2e-03  |
 test_equilibrium_init_lowres            |     -1.72 +/- 2.08     | -1.47e-02 +/- 1.78e-02 |  8.44e-01 +/- 1.4e-02  |  8.59e-01 +/- 1.1e-02  |
 test_equilibrium_init_medres            |     -1.55 +/- 1.40     | -1.98e-02 +/- 1.78e-02 |  1.26e+00 +/- 9.8e-03  |  1.27e+00 +/- 1.5e-02  |
 test_equilibrium_init_highres           |     -0.21 +/- 0.83     | -6.46e-03 +/- 2.50e-02 |  3.02e+00 +/- 1.8e-02  |  3.02e+00 +/- 1.7e-02  |
 test_objective_compile_dshape_current   |     -1.98 +/- 6.82     | -1.07e-01 +/- 3.68e-01 |  5.29e+00 +/- 2.9e-01  |  5.39e+00 +/- 2.2e-01  |
 test_objective_compile_atf              |     -0.95 +/- 5.84     | -1.63e-01 +/- 1.00e+00 |  1.70e+01 +/- 7.2e-01  |  1.72e+01 +/- 7.0e-01  |
 test_objective_compute_dshape_current   |     -1.08 +/- 1.06     | -3.60e-05 +/- 3.53e-05 |  3.31e-03 +/- 2.6e-05  |  3.34e-03 +/- 2.4e-05  |
 test_objective_compute_atf              |     -2.37 +/- 0.94     | -2.64e-04 +/- 1.05e-04 |  1.09e-02 +/- 4.3e-05  |  1.12e-02 +/- 9.6e-05  |
 test_objective_jac_dshape_current       |     -2.31 +/- 6.58     | -3.29e-03 +/- 9.36e-03 |  1.39e-01 +/- 5.2e-03  |  1.42e-01 +/- 7.8e-03  |
 test_objective_jac_atf                  |     -8.23 +/- 5.80     | -7.19e-01 +/- 5.06e-01 |  8.02e+00 +/- 5.0e-01  |  8.74e+00 +/- 8.0e-02  |
 test_perturb_1                          |     -1.04 +/- 12.62    | -1.14e-01 +/- 1.38e+00 |  1.08e+01 +/- 9.2e-01  |  1.09e+01 +/- 1.0e+00  |
 test_perturb_2                          |     -1.59 +/- 5.14     | -3.01e-01 +/- 9.70e-01 |  1.86e+01 +/- 6.0e-01  |  1.89e+01 +/- 7.6e-01  |

github-actions[bot] avatar Nov 04 '23 20:11 github-actions[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +1.25 +/- 1.62     | +1.56e-04 +/- 2.02e-04 |  1.26e-02 +/- 1.9e-04  |  1.25e-02 +/- 8.1e-05  |
 test_build_transform_fft_midres         |     -0.01 +/- 1.23     | -1.19e-05 +/- 1.13e-03 |  9.24e-02 +/- 7.0e-04  |  9.24e-02 +/- 9.0e-04  |
 test_build_transform_fft_highres        |     +1.21 +/- 0.72     | +5.62e-03 +/- 3.32e-03 |  4.69e-01 +/- 1.9e-03  |  4.63e-01 +/- 2.7e-03  |
 test_equilibrium_init_lowres            |     +2.70 +/- 1.62     | +2.13e-02 +/- 1.28e-02 |  8.12e-01 +/- 1.1e-02  |  7.91e-01 +/- 6.3e-03  |
 test_equilibrium_init_medres            |     +1.58 +/- 1.37     | +2.23e-02 +/- 1.94e-02 |  1.43e+00 +/- 1.5e-02  |  1.41e+00 +/- 1.3e-02  |
 test_equilibrium_init_highres           |     +0.61 +/- 1.32     | +2.54e-02 +/- 5.51e-02 |  4.21e+00 +/- 4.5e-02  |  4.18e+00 +/- 3.1e-02  |
 test_objective_compile_dshape_current   |     +1.16 +/- 9.78     | +4.73e-02 +/- 3.98e-01 |  4.12e+00 +/- 3.3e-01  |  4.07e+00 +/- 2.3e-01  |
 test_objective_compile_atf              |     -3.85 +/- 5.66     | -3.63e-01 +/- 5.34e-01 |  9.07e+00 +/- 3.2e-01  |  9.43e+00 +/- 4.3e-01  |
 test_objective_compute_dshape_current   |     -0.85 +/- 1.95     | -1.84e-05 +/- 4.25e-05 |  2.16e-03 +/- 2.7e-05  |  2.18e-03 +/- 3.3e-05  |
 test_objective_compute_atf              |     +1.72 +/- 1.21     | +1.30e-04 +/- 9.13e-05 |  7.70e-03 +/- 6.1e-05  |  7.57e-03 +/- 6.8e-05  |
 test_objective_jac_dshape_current       |     -3.41 +/- 12.79    | -1.61e-03 +/- 6.03e-03 |  4.55e-02 +/- 3.8e-03  |  4.71e-02 +/- 4.7e-03  |
 test_objective_jac_atf                  |     -3.18 +/- 6.69     | -7.55e-02 +/- 1.59e-01 |  2.30e+00 +/- 7.4e-02  |  2.37e+00 +/- 1.4e-01  |
 test_perturb_1                          |     -0.78 +/- 13.58    | -6.56e-02 +/- 1.14e+00 |  8.31e+00 +/- 7.7e-01  |  8.37e+00 +/- 8.4e-01  |
 test_perturb_2                          |     -5.08 +/- 5.34     | -7.50e-01 +/- 7.88e-01 |  1.40e+01 +/- 5.5e-01  |  1.48e+01 +/- 5.7e-01  |

github-actions[bot] avatar Dec 05 '23 12:12 github-actions[bot]

Codecov Report

Attention: Patch coverage is 8.69565% with 84 lines in your changes missing coverage. Please review.

Project coverage is 95.41%. Comparing base (ef9574e) to head (687abfd). Report is 38 commits behind head on master.

Files with missing lines Patch % Lines
desc/magnetic_fields/_core.py 8.69% 84 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #734      +/-   ##
==========================================
- Coverage   95.72%   95.41%   -0.31%     
==========================================
  Files         101      101              
  Lines       26349    26460     +111     
==========================================
+ Hits        25223    25248      +25     
- Misses       1126     1212      +86     
Files with missing lines Coverage Δ
desc/magnetic_fields/_core.py 87.59% <8.69%> (-8.79%) :arrow_down:

... and 10 files with indirect coverage changes

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

codecov[bot] avatar Dec 05 '23 12:12 codecov[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +1.24 +/- 7.18     | +6.73e-03 +/- 3.89e-02 |  5.49e-01 +/- 3.2e-02  |  5.43e-01 +/- 2.2e-02  |
 test_equilibrium_init_medres            |     +1.81 +/- 1.75     | +7.03e-02 +/- 6.79e-02 |  3.95e+00 +/- 5.5e-02  |  3.88e+00 +/- 4.0e-02  |
 test_equilibrium_init_highres           |     +0.45 +/- 2.48     | +2.17e-02 +/- 1.20e-01 |  4.85e+00 +/- 1.1e-01  |  4.83e+00 +/- 5.6e-02  |
 test_objective_compile_dshape_current   |     +2.71 +/- 6.26     | +8.04e-02 +/- 1.86e-01 |  3.05e+00 +/- 1.4e-01  |  2.97e+00 +/- 1.2e-01  |
-test_objective_compute_dshape_current   |    +40.98 +/- 2.30     | +1.46e-03 +/- 8.20e-05 |  5.03e-03 +/- 6.3e-05  |  3.57e-03 +/- 5.2e-05  |
 test_objective_jac_dshape_current       |     +5.55 +/- 6.03     | +2.11e-03 +/- 2.30e-03 |  4.02e-02 +/- 1.1e-03  |  3.81e-02 +/- 2.0e-03  |
-test_perturb_2                          |     +9.13 +/- 2.62     | +1.39e+00 +/- 3.99e-01 |  1.66e+01 +/- 1.8e-01  |  1.53e+01 +/- 3.6e-01  |
 test_proximal_jac_atf_with_eq_update    |     +0.81 +/- 0.95     | +1.37e-01 +/- 1.61e-01 |  1.71e+01 +/- 1.3e-01  |  1.69e+01 +/- 9.3e-02  |
 test_proximal_freeb_jac                 |     -0.02 +/- 0.91     | -1.43e-03 +/- 5.27e-02 |  5.78e+00 +/- 3.6e-02  |  5.78e+00 +/- 3.8e-02  |
 test_solve_fixed_iter_compiled          |     +5.22 +/- 2.59     | +9.41e-01 +/- 4.67e-01 |  1.90e+01 +/- 2.4e-01  |  1.80e+01 +/- 4.0e-01  |
-test_LinearConstraintProjection_build   |    +32.72 +/- 4.78     | +2.71e+00 +/- 3.96e-01 |  1.10e+01 +/- 2.9e-01  |  8.27e+00 +/- 2.7e-01  |
-test_objective_compute_ripple_spline    |    +11.67 +/- 2.75     | +3.88e-02 +/- 9.16e-03 |  3.72e-01 +/- 6.9e-03  |  3.33e-01 +/- 6.0e-03  |
 test_objective_grad_ripple_spline       |     +3.04 +/- 3.11     | +4.49e-02 +/- 4.60e-02 |  1.52e+00 +/- 3.2e-02  |  1.48e+00 +/- 3.3e-02  |
 test_build_transform_fft_midres         |     +0.30 +/- 8.00     | +1.60e-03 +/- 4.33e-02 |  5.43e-01 +/- 4.3e-02  |  5.41e-01 +/- 6.2e-03  |
 test_build_transform_fft_highres        |     +0.50 +/- 3.01     | +4.13e-03 +/- 2.48e-02 |  8.28e-01 +/- 2.2e-02  |  8.24e-01 +/- 1.2e-02  |
 test_equilibrium_init_lowres            |     -0.28 +/- 1.29     | -9.71e-03 +/- 4.56e-02 |  3.52e+00 +/- 3.1e-02  |  3.53e+00 +/- 3.3e-02  |
 test_objective_compile_atf              |     +3.69 +/- 2.87     | +2.24e-01 +/- 1.75e-01 |  6.31e+00 +/- 1.6e-01  |  6.08e+00 +/- 7.3e-02  |
-test_objective_compute_atf              |    +62.84 +/- 3.01     | +5.72e-03 +/- 2.74e-04 |  1.48e-02 +/- 1.9e-04  |  9.11e-03 +/- 2.0e-04  |
 test_objective_jac_atf                  |     -0.02 +/- 1.84     | -2.77e-04 +/- 3.34e-02 |  1.81e+00 +/- 2.7e-02  |  1.81e+00 +/- 2.0e-02  |
-test_perturb_1                          |    +11.69 +/- 2.34     | +1.41e+00 +/- 2.84e-01 |  1.35e+01 +/- 2.4e-01  |  1.21e+01 +/- 1.6e-01  |
 test_proximal_jac_atf                   |     +0.35 +/- 0.80     | +2.76e-02 +/- 6.32e-02 |  7.91e+00 +/- 4.0e-02  |  7.88e+00 +/- 4.9e-02  |
 test_proximal_freeb_compute             |     +7.51 +/- 3.69     | +1.22e-02 +/- 6.00e-03 |  1.75e-01 +/- 5.2e-03  |  1.63e-01 +/- 2.9e-03  |
 test_solve_fixed_iter                   |     +4.15 +/- 2.74     | +1.14e+00 +/- 7.52e-01 |  2.86e+01 +/- 4.7e-01  |  2.74e+01 +/- 5.8e-01  |
 test_objective_compute_ripple           |     -0.56 +/- 1.40     | -1.59e-02 +/- 4.00e-02 |  2.83e+00 +/- 2.4e-02  |  2.85e+00 +/- 3.2e-02  |
 test_objective_grad_ripple              |     +1.12 +/- 0.64     | +8.15e-02 +/- 4.70e-02 |  7.38e+00 +/- 4.3e-02  |  7.30e+00 +/- 1.9e-02  |

github-actions[bot] avatar Apr 16 '24 18:04 github-actions[bot]

If you want to get rid of some PRs, I can take this one. It looks interesting and I am bored:D

YigitElma avatar Sep 10 '24 12:09 YigitElma

If you want to get rid of some PRs, I can take this one. It looks interesting and I am bored:D

Sure, main thing it needs is some tests, so probably just need to come up with some simple magnetic fields for which we know the trajectory analytically and make sure they agree. Some ideas:

  • Uniform B (using VerticalField) to test basic motion (guiding center should move in straight line, full orbit should be a helix)
  • B with gradient (MagneticFieldFromUser with B = B0*x or something, to test grad B drift
  • Purely toroidal field to test gradB and curvature drift

f0uriest avatar Sep 11 '24 23:09 f0uriest

Do you have a symplectic orbit solver to compare with? I have one that I can add to the test. It calculates the the exact particle position instead of just guiding center. We only have to run it once, gyroaverage and save the data.

rahulgaur104 avatar Sep 11 '24 23:09 rahulgaur104

Do you have a symplectic orbit solver to compare with? I have one that I can add to the test. It calculates the the exact particle position instead of just guiding center. We only have to run it once, gyroaverage and save the data.

Yeah I benchmarked against SIMPLE with rogerio, I'll try to dig up the data

f0uriest avatar Sep 12 '24 23:09 f0uriest