DESC icon indicating copy to clipboard operation
DESC copied to clipboard

Galerkin and Spectral Condensation

Open pkim1818 opened this issue 2 years ago • 9 comments
trafficstars

Adding objectives for galerkin projection of force error and spectral condensation.

Resolves #324

pkim1818 avatar Dec 28 '22 18:12 pkim1818

Codecov Report

Attention: Patch coverage is 18.07229% with 68 lines in your changes are missing coverage. Please review.

Project coverage is 94.82%. Comparing base (4c36708) to head (7dd4446).

:exclamation: Current head 7dd4446 differs from pull request most recent head e2fa16d. Consider uploading reports for the commit e2fa16d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #382      +/-   ##
==========================================
- Coverage   95.22%   94.82%   -0.41%     
==========================================
  Files          87       80       -7     
  Lines       21956    19461    -2495     
==========================================
- Hits        20908    18453    -2455     
+ Misses       1048     1008      -40     
Files Coverage Δ
desc/objectives/__init__.py 100.00% <ø> (ø)
desc/objectives/_geometry.py 89.66% <17.94%> (-6.63%) :arrow_down:
desc/objectives/_equilibrium.py 85.10% <18.18%> (-9.86%) :arrow_down:

... and 68 files with indirect coverage changes

codecov[bot] avatar Jan 05 '23 04:01 codecov[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.08 +/- 2.09     | +1.81e-05 +/- 4.74e-04 |  2.27e-02 +/- 2.8e-04  |  2.27e-02 +/- 3.8e-04  |
 test_build_transform_fft_midres         |     -0.40 +/- 1.48     | -5.30e-04 +/- 1.94e-03 |  1.31e-01 +/- 1.0e-03  |  1.31e-01 +/- 1.6e-03  |
 test_build_transform_fft_highres        |     -1.02 +/- 1.38     | -6.13e-03 +/- 8.30e-03 |  5.97e-01 +/- 6.3e-03  |  6.03e-01 +/- 5.4e-03  |
 test_equilibrium_init_lowres            |     +0.57 +/- 5.89     | +2.96e-03 +/- 3.06e-02 |  5.22e-01 +/- 2.7e-02  |  5.19e-01 +/- 1.5e-02  |
 test_equilibrium_init_medres            |     +1.35 +/- 5.25     | +8.90e-03 +/- 3.47e-02 |  6.70e-01 +/- 3.2e-02  |  6.61e-01 +/- 1.3e-02  |
 test_equilibrium_init_highres           |     -1.09 +/- 2.35     | -1.28e-02 +/- 2.77e-02 |  1.16e+00 +/- 1.2e-02  |  1.17e+00 +/- 2.5e-02  |
 test_objective_compile_dshape_current   |     -1.72 +/- 5.70     | -1.07e-01 +/- 3.54e-01 |  6.10e+00 +/- 2.5e-01  |  6.20e+00 +/- 2.5e-01  |
 test_objective_compile_atf              |     -0.01 +/- 4.19     | -1.62e-03 +/- 7.37e-01 |  1.76e+01 +/- 5.7e-01  |  1.76e+01 +/- 4.7e-01  |
 test_objective_compute_dshape_current   |     -2.69 +/- 5.01     | -1.08e-04 +/- 2.01e-04 |  3.90e-03 +/- 1.5e-04  |  4.01e-03 +/- 1.4e-04  |
 test_objective_compute_atf              |     -0.57 +/- 3.41     | -7.78e-05 +/- 4.66e-04 |  1.36e-02 +/- 2.9e-04  |  1.37e-02 +/- 3.7e-04  |
 test_objective_jac_dshape_current       |     -3.08 +/- 5.95     | -4.73e-03 +/- 9.13e-03 |  1.49e-01 +/- 6.0e-03  |  1.53e-01 +/- 6.9e-03  |
 test_objective_jac_atf                  |     +0.40 +/- 3.19     | +2.94e-02 +/- 2.36e-01 |  7.42e+00 +/- 1.4e-01  |  7.39e+00 +/- 1.9e-01  |
 test_perturb_1                          |     -2.15 +/- 13.93    | -2.24e-01 +/- 1.45e+00 |  1.02e+01 +/- 9.8e-01  |  1.04e+01 +/- 1.1e+00  |
 test_perturb_2                          |     +1.18 +/- 7.44     | +2.30e-01 +/- 1.45e+00 |  1.97e+01 +/- 7.3e-01  |  1.94e+01 +/- 1.2e+00  |

github-actions[bot] avatar Oct 17 '23 01:10 github-actions[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -1.49 +/- 2.30     | -2.88e-04 +/- 4.46e-04 |  1.91e-02 +/- 2.2e-04  |  1.94e-02 +/- 3.9e-04  |
 test_build_transform_fft_midres         |     -0.30 +/- 0.82     | -3.33e-04 +/- 9.20e-04 |  1.12e-01 +/- 6.9e-04  |  1.12e-01 +/- 6.1e-04  |
 test_build_transform_fft_highres        |     +0.26 +/- 0.59     | +1.31e-03 +/- 3.01e-03 |  5.13e-01 +/- 2.0e-03  |  5.11e-01 +/- 2.3e-03  |
 test_equilibrium_init_lowres            |     -0.94 +/- 1.74     | -8.05e-03 +/- 1.48e-02 |  8.44e-01 +/- 8.0e-03  |  8.52e-01 +/- 1.2e-02  |
 test_equilibrium_init_medres            |     -0.65 +/- 1.19     | -8.23e-03 +/- 1.50e-02 |  1.26e+00 +/- 8.3e-03  |  1.26e+00 +/- 1.2e-02  |
 test_equilibrium_init_highres           |     -0.22 +/- 0.75     | -6.71e-03 +/- 2.25e-02 |  3.01e+00 +/- 1.8e-02  |  3.01e+00 +/- 1.3e-02  |
 test_objective_compile_dshape_current   |     -1.49 +/- 6.31     | -7.91e-02 +/- 3.36e-01 |  5.25e+00 +/- 2.4e-01  |  5.33e+00 +/- 2.3e-01  |
 test_objective_compile_atf              |     +2.52 +/- 3.30     | +3.97e-01 +/- 5.21e-01 |  1.62e+01 +/- 3.6e-01  |  1.58e+01 +/- 3.8e-01  |
 test_objective_compute_dshape_current   |     -2.49 +/- 5.34     | -8.38e-05 +/- 1.80e-04 |  3.29e-03 +/- 2.2e-05  |  3.37e-03 +/- 1.8e-04  |
 test_objective_compute_atf              |     +1.96 +/- 1.51     | +2.15e-04 +/- 1.66e-04 |  1.12e-02 +/- 1.2e-04  |  1.10e-02 +/- 1.2e-04  |
 test_objective_jac_dshape_current       |     +3.47 +/- 7.20     | +4.75e-03 +/- 9.87e-03 |  1.42e-01 +/- 9.0e-03  |  1.37e-01 +/- 4.0e-03  |
 test_objective_jac_atf                  |     +0.32 +/- 2.69     | +2.28e-02 +/- 1.94e-01 |  7.24e+00 +/- 9.6e-02  |  7.21e+00 +/- 1.7e-01  |
 test_perturb_1                          |     -1.98 +/- 12.11    | -2.18e-01 +/- 1.33e+00 |  1.08e+01 +/- 8.6e-01  |  1.10e+01 +/- 1.0e+00  |
 test_perturb_2                          |     -1.11 +/- 5.37     | -2.10e-01 +/- 1.02e+00 |  1.88e+01 +/- 4.6e-01  |  1.90e+01 +/- 9.1e-01  |

github-actions[bot] avatar Oct 31 '23 15:10 github-actions[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -1.90 +/- 8.09     | -4.58e-04 +/- 1.95e-03 |  2.36e-02 +/- 6.6e-04  |  2.41e-02 +/- 1.8e-03  |
 test_build_transform_fft_midres         |     +1.79 +/- 1.00     | +2.40e-03 +/- 1.35e-03 |  1.37e-01 +/- 9.5e-04  |  1.34e-01 +/- 9.5e-04  |
 test_build_transform_fft_highres        |     +1.90 +/- 0.75     | +1.16e-02 +/- 4.58e-03 |  6.26e-01 +/- 2.7e-03  |  6.15e-01 +/- 3.7e-03  |
 test_equilibrium_init_lowres            |     -2.65 +/- 6.43     | -2.76e-02 +/- 6.71e-02 |  1.02e+00 +/- 4.4e-02  |  1.04e+00 +/- 5.0e-02  |
 test_equilibrium_init_medres            |     -1.06 +/- 1.79     | -1.61e-02 +/- 2.72e-02 |  1.50e+00 +/- 1.7e-02  |  1.52e+00 +/- 2.2e-02  |
 test_equilibrium_init_highres           |     -0.12 +/- 1.55     | -4.45e-03 +/- 5.61e-02 |  3.61e+00 +/- 3.4e-02  |  3.62e+00 +/- 4.5e-02  |
 test_objective_compile_dshape_current   |     +0.15 +/- 6.27     | +1.00e-02 +/- 4.07e-01 |  6.50e+00 +/- 3.0e-01  |  6.49e+00 +/- 2.7e-01  |
 test_objective_compile_atf              |     -1.87 +/- 2.73     | -3.67e-01 +/- 5.35e-01 |  1.92e+01 +/- 3.8e-01  |  1.96e+01 +/- 3.8e-01  |
 test_objective_compute_dshape_current   |     -5.76 +/- 8.21     | -2.48e-04 +/- 3.54e-04 |  4.07e-03 +/- 1.3e-04  |  4.31e-03 +/- 3.3e-04  |
 test_objective_compute_atf              |     -3.70 +/- 2.31     | -5.22e-04 +/- 3.26e-04 |  1.36e-02 +/- 2.4e-04  |  1.41e-02 +/- 2.2e-04  |
 test_objective_jac_dshape_current       |     +0.97 +/- 16.98    | +1.63e-03 +/- 2.84e-02 |  1.69e-01 +/- 1.7e-02  |  1.67e-01 +/- 2.2e-02  |
 test_objective_jac_atf                  |     -3.44 +/- 3.24     | -2.98e-01 +/- 2.81e-01 |  8.39e+00 +/- 1.1e-01  |  8.68e+00 +/- 2.6e-01  |
 test_perturb_1                          |     -1.63 +/- 8.90     | -2.20e-01 +/- 1.20e+00 |  1.32e+01 +/- 9.5e-01  |  1.34e+01 +/- 7.3e-01  |
 test_perturb_2                          |     -1.55 +/- 5.83     | -3.59e-01 +/- 1.35e+00 |  2.28e+01 +/- 7.4e-01  |  2.31e+01 +/- 1.1e+00  |

github-actions[bot] avatar Nov 08 '23 21:11 github-actions[bot]

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     -0.09 +/- 1.42     | -1.12e-05 +/- 1.79e-04 |  1.26e-02 +/- 9.9e-05  |  1.26e-02 +/- 1.5e-04  |
 test_build_transform_fft_midres         |     +0.24 +/- 1.73     | +2.21e-04 +/- 1.59e-03 |  9.26e-02 +/- 1.1e-03  |  9.24e-02 +/- 1.2e-03  |
 test_build_transform_fft_highres        |     -0.08 +/- 0.75     | -3.72e-04 +/- 3.45e-03 |  4.61e-01 +/- 2.4e-03  |  4.61e-01 +/- 2.5e-03  |
 test_equilibrium_init_lowres            |     -0.08 +/- 1.30     | -6.04e-04 +/- 1.04e-02 |  8.00e-01 +/- 7.1e-03  |  8.01e-01 +/- 7.6e-03  |
 test_equilibrium_init_medres            |     -0.37 +/- 1.01     | -5.22e-03 +/- 1.44e-02 |  1.42e+00 +/- 9.3e-03  |  1.43e+00 +/- 1.1e-02  |
 test_equilibrium_init_highres           |     -0.74 +/- 0.63     | -3.12e-02 +/- 2.64e-02 |  4.19e+00 +/- 2.2e-02  |  4.22e+00 +/- 1.5e-02  |
 test_objective_compile_dshape_current   |     +0.13 +/- 8.13     | +5.56e-03 +/- 3.38e-01 |  4.16e+00 +/- 2.5e-01  |  4.16e+00 +/- 2.3e-01  |
 test_objective_compile_atf              |     +0.47 +/- 6.76     | +4.33e-02 +/- 6.24e-01 |  9.28e+00 +/- 4.0e-01  |  9.24e+00 +/- 4.8e-01  |
 test_objective_compute_dshape_current   |     +1.09 +/- 64.09    | +2.31e-05 +/- 1.35e-03 |  2.14e-03 +/- 1.4e-03  |  2.11e-03 +/- 2.8e-05  |
 test_objective_compute_atf              |     +1.12 +/- 1.25     | +8.38e-05 +/- 9.41e-05 |  7.60e-03 +/- 5.4e-05  |  7.51e-03 +/- 7.7e-05  |
 test_objective_jac_dshape_current       |     +2.09 +/- 11.93    | +9.80e-04 +/- 5.61e-03 |  4.79e-02 +/- 3.7e-03  |  4.70e-02 +/- 4.2e-03  |
 test_objective_jac_atf                  |     +1.13 +/- 7.36     | +2.61e-02 +/- 1.70e-01 |  2.34e+00 +/- 1.2e-01  |  2.31e+00 +/- 1.2e-01  |
 test_perturb_1                          |     +0.46 +/- 14.38    | +3.85e-02 +/- 1.21e+00 |  8.47e+00 +/- 9.0e-01  |  8.43e+00 +/- 8.1e-01  |
 test_perturb_2                          |     +0.15 +/- 5.21     | +2.17e-02 +/- 7.42e-01 |  1.43e+01 +/- 5.4e-01  |  1.42e+01 +/- 5.1e-01  |

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

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_midres         |     +2.66 +/- 6.80     | +1.72e-02 +/- 4.40e-02 |  6.65e-01 +/- 4.0e-02  |  6.47e-01 +/- 1.9e-02  |
 test_build_transform_fft_highres        |     +1.62 +/- 6.34     | +1.51e-02 +/- 5.90e-02 |  9.46e-01 +/- 5.8e-02  |  9.31e-01 +/- 1.2e-02  |
 test_equilibrium_init_lowres            |     +2.28 +/- 3.17     | +9.32e-02 +/- 1.30e-01 |  4.18e+00 +/- 1.2e-01  |  4.09e+00 +/- 5.7e-02  |
 test_objective_compile_atf              |     -0.09 +/- 3.05     | -7.52e-03 +/- 2.55e-01 |  8.33e+00 +/- 1.8e-01  |  8.34e+00 +/- 1.8e-01  |
 test_objective_compute_atf              |     -0.42 +/- 4.43     | -6.85e-05 +/- 7.22e-04 |  1.62e-02 +/- 2.5e-04  |  1.63e-02 +/- 6.8e-04  |
 test_objective_jac_atf                  |     -0.62 +/- 1.36     | -1.22e-02 +/- 2.66e-02 |  1.95e+00 +/- 1.5e-02  |  1.96e+00 +/- 2.2e-02  |
 test_perturb_1                          |     -0.01 +/- 2.02     | -1.23e-03 +/- 3.13e-01 |  1.55e+01 +/- 2.3e-01  |  1.55e+01 +/- 2.1e-01  |
 test_proximal_jac_atf                   |     -0.11 +/- 1.45     | -9.32e-03 +/- 1.18e-01 |  8.16e+00 +/- 8.9e-02  |  8.17e+00 +/- 7.9e-02  |
 test_proximal_freeb_compute             |     -0.68 +/- 0.92     | -1.28e-03 +/- 1.73e-03 |  1.86e-01 +/- 1.4e-03  |  1.87e-01 +/- 1.0e-03  |
 test_solve_fixed_iter_compiled          |     +0.79 +/- 1.29     | +1.64e-01 +/- 2.67e-01 |  2.09e+01 +/- 2.3e-01  |  2.08e+01 +/- 1.4e-01  |
 test_objective_compute_ripple           |     -0.98 +/- 2.67     | -6.46e-03 +/- 1.75e-02 |  6.50e-01 +/- 1.1e-02  |  6.57e-01 +/- 1.4e-02  |
 test_objective_grad_ripple              |     -0.70 +/- 0.84     | -1.93e-02 +/- 2.31e-02 |  2.73e+00 +/- 1.4e-02  |  2.75e+00 +/- 1.9e-02  |
 test_build_transform_fft_lowres         |     -1.12 +/- 4.32     | -7.31e-03 +/- 2.82e-02 |  6.46e-01 +/- 2.5e-02  |  6.53e-01 +/- 1.4e-02  |
 test_equilibrium_init_medres            |     -0.85 +/- 2.23     | -4.00e-02 +/- 1.04e-01 |  4.64e+00 +/- 6.3e-02  |  4.68e+00 +/- 8.3e-02  |
 test_equilibrium_init_highres           |     +0.18 +/- 2.95     | +1.03e-02 +/- 1.66e-01 |  5.65e+00 +/- 1.1e-01  |  5.64e+00 +/- 1.2e-01  |
 test_objective_compile_dshape_current   |     -0.22 +/- 5.54     | -9.80e-03 +/- 2.42e-01 |  4.35e+00 +/- 1.8e-01  |  4.36e+00 +/- 1.7e-01  |
 test_objective_compute_dshape_current   |     +2.11 +/- 3.60     | +1.15e-04 +/- 1.96e-04 |  5.56e-03 +/- 1.5e-04  |  5.45e-03 +/- 1.2e-04  |
 test_objective_jac_dshape_current       |     +1.66 +/- 8.13     | +7.34e-04 +/- 3.60e-03 |  4.50e-02 +/- 2.9e-03  |  4.43e-02 +/- 2.2e-03  |
 test_perturb_2                          |     +0.07 +/- 2.30     | +1.43e-02 +/- 4.98e-01 |  2.17e+01 +/- 1.6e-01  |  2.17e+01 +/- 4.7e-01  |
 test_proximal_freeb_jac                 |     -0.09 +/- 1.81     | -6.46e-03 +/- 1.29e-01 |  7.16e+00 +/- 9.9e-02  |  7.17e+00 +/- 8.3e-02  |
 test_solve_fixed_iter                   |     -1.32 +/- 4.05     | -4.59e-01 +/- 1.41e+00 |  3.43e+01 +/- 8.3e-01  |  3.48e+01 +/- 1.1e+00  |
 test_LinearConstraintProjection_build   |     +0.38 +/- 3.56     | +4.22e-02 +/- 3.98e-01 |  1.12e+01 +/- 2.2e-01  |  1.12e+01 +/- 3.3e-01  |
 test_objective_compute_ripple_spline    |     -0.37 +/- 1.90     | -1.16e-03 +/- 5.90e-03 |  3.09e-01 +/- 4.8e-03  |  3.11e-01 +/- 3.5e-03  |
 test_objective_grad_ripple_spline       |     -2.29 +/- 2.35     | -3.55e-02 +/- 3.63e-02 |  1.51e+00 +/- 1.3e-02  |  1.55e+00 +/- 3.4e-02  |

github-actions[bot] avatar Jan 17 '24 21:01 github-actions[bot]

Can someone remind me what the issue was with the Galerkin projection? did it just not work well?

dpanici avatar Jan 17 '25 20:01 dpanici

Been messing around with the branch for fun, it kind of works especially if you allow your projected basis resolution to exceed the equilibrium resolution, but something is broken with the SpectralCondensation, in that the factorize_linear_constraints acts strangely.

https://gist.github.com/dpanici/315967873d9a82c96a451729fd44aeba

cool part for me is the cost consistently gets down to like 1e-12 range, this could be useful for deciding tolerances if we ever wanted to use this inside of proximal projection, for instance

dpanici avatar Feb 13 '25 22:02 dpanici

Been messing around with the branch for fun, it kind of works especially if you allow your projected basis resolution to exceed the equilibrium resolution, but something is broken with the SpectralCondensation, in that the factorize_linear_constraints acts strangely.

https://gist.github.com/dpanici/315967873d9a82c96a451729fd44aeba

cool part for me is the cost consistently gets down to like 1e-12 range, this could be useful for deciding tolerances if we ever wanted to use this inside of proximal projection, for instance

Couple comments,

  • For testing, it doesn't matter too much but I think if you just call eq.set_initial_guess(), this is not the actual initial guess we start with. Because it uses the axis and also final equilibrium's lambda. So, instead of having scaled surfaces concentric surfaces, you get something way closer to the final equilibrium.

  • Did you also try equilibrium with pressure? I tried this myself with Heliotron and the default basis (without and factor) gives extremely bad results, but thinks it has a sum of squares error of 2.008e-17 image

  • When you increase the basis to project the spectral coefficients, it again increases the size of the Jacobian and I don't think it helps to the purpose. Maybe we can come up with an heuristic to choose the final basis of the spectral coefficients. So, when you have given LMN resolution for R, Z and lambda, what is the highest frequency in image

YigitElma avatar Feb 24 '25 03:02 YigitElma