Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExternalObjective function to wrap external codes #1028

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft

Conversation

ddudt
Copy link
Collaborator

@ddudt ddudt commented May 21, 2024

Creates an abstract base class for wrapping external codes with finite differences, like GX, TERPSICHORE, etc.

TODO:

  • vectorize
  • reverse mode gradient
  • tests
  • tutorial

@ddudt ddudt changed the title Objective function to wrap external codes ExternalObjective function to wrap external codes May 21, 2024
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 96.05263% with 3 lines in your changes missing coverage. Please review.

Project coverage is 95.32%. Comparing base (225d44e) to head (37f9ee3).

Files Patch % Lines
desc/backend.py 75.00% 2 Missing ⚠️
desc/objectives/_generic.py 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1028      +/-   ##
==========================================
- Coverage   95.33%   95.32%   -0.01%     
==========================================
  Files          90       90              
  Lines       22643    22711      +68     
==========================================
+ Hits        21586    21650      +64     
- Misses       1057     1061       +4     
Files Coverage Δ
desc/integrals/surface_integral.py 100.00% <ø> (ø)
desc/objectives/__init__.py 100.00% <100.00%> (ø)
desc/utils.py 92.88% <100.00%> (+0.72%) ⬆️
desc/objectives/_generic.py 97.46% <97.43%> (-0.06%) ⬇️
desc/backend.py 89.94% <75.00%> (-0.31%) ⬇️

... and 3 files with indirect coverage changes

Copy link
Contributor

github-actions bot commented May 21, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +0.26 +/- 6.30     | +1.31e-03 +/- 3.20e-02 |  5.09e-01 +/- 3.1e-02  |  5.08e-01 +/- 8.5e-03  |
 test_build_transform_fft_midres         |     -0.23 +/- 1.78     | -1.36e-03 +/- 1.05e-02 |  5.90e-01 +/- 4.8e-03  |  5.91e-01 +/- 9.3e-03  |
 test_build_transform_fft_highres        |     +0.98 +/- 1.53     | +9.65e-03 +/- 1.51e-02 |  9.93e-01 +/- 1.1e-02  |  9.83e-01 +/- 1.1e-02  |
 test_equilibrium_init_lowres            |     +0.12 +/- 0.51     | +4.35e-03 +/- 1.87e-02 |  3.70e+00 +/- 1.3e-02  |  3.70e+00 +/- 1.4e-02  |
 test_equilibrium_init_medres            |     +0.25 +/- 1.55     | +9.93e-03 +/- 6.22e-02 |  4.01e+00 +/- 3.9e-02  |  4.00e+00 +/- 4.9e-02  |
 test_equilibrium_init_highres           |     +0.09 +/- 0.72     | +5.01e-03 +/- 3.84e-02 |  5.36e+00 +/- 3.0e-02  |  5.35e+00 +/- 2.4e-02  |
 test_objective_compile_dshape_current   |     +0.14 +/- 0.92     | +5.19e-03 +/- 3.49e-02 |  3.81e+00 +/- 3.1e-02  |  3.81e+00 +/- 1.7e-02  |
 test_objective_compile_atf              |     +0.12 +/- 1.10     | +9.30e-03 +/- 8.51e-02 |  7.74e+00 +/- 5.5e-02  |  7.73e+00 +/- 6.5e-02  |
 test_objective_compute_dshape_current   |     +0.61 +/- 1.27     | +2.11e-05 +/- 4.39e-05 |  3.49e-03 +/- 2.7e-05  |  3.47e-03 +/- 3.5e-05  |
 test_objective_compute_atf              |     +0.44 +/- 1.62     | +4.51e-05 +/- 1.65e-04 |  1.02e-02 +/- 1.0e-04  |  1.02e-02 +/- 1.3e-04  |
 test_objective_jac_dshape_current       |     +7.21 +/- 5.22     | +2.68e-03 +/- 1.94e-03 |  3.98e-02 +/- 1.1e-03  |  3.71e-02 +/- 1.6e-03  |
 test_objective_jac_atf                  |     +2.03 +/- 3.69     | +3.66e-02 +/- 6.65e-02 |  1.84e+00 +/- 5.7e-02  |  1.80e+00 +/- 3.5e-02  |
 test_perturb_1                          |     -1.06 +/- 1.33     | -1.28e-01 +/- 1.60e-01 |  1.19e+01 +/- 1.5e-01  |  1.21e+01 +/- 5.4e-02  |
 test_perturb_2                          |     -0.07 +/- 0.55     | -1.25e-02 +/- 9.31e-02 |  1.70e+01 +/- 7.3e-02  |  1.70e+01 +/- 5.8e-02  |
 test_proximal_jac_atf                   |     -0.63 +/- 0.92     | -5.09e-02 +/- 7.42e-02 |  7.98e+00 +/- 2.9e-02  |  8.03e+00 +/- 6.8e-02  |
 test_proximal_freeb_compute             |     +0.43 +/- 1.52     | +7.68e-04 +/- 2.74e-03 |  1.81e-01 +/- 2.1e-03  |  1.80e-01 +/- 1.8e-03  |
 test_proximal_freeb_jac                 |     -0.49 +/- 1.26     | -3.59e-02 +/- 9.26e-02 |  7.32e+00 +/- 8.1e-02  |  7.36e+00 +/- 4.4e-02  |
 test_solve_fixed_iter                   |     -0.10 +/- 61.14    | -5.07e-03 +/- 2.97e+00 |  4.85e+00 +/- 2.1e+00  |  4.86e+00 +/- 2.1e+00  |



@pytest.mark.unit
@pytest.mark.slow
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This takes a minute or so to run on my laptop, since VMECIO.save is slow. If we really need to speed this up we could either reduce the equilibrium resolution or manually save only the VMEC quantities that are used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I sped this up significantly by manually saving the few quantities instead of calling VMECIO.save

desc/objectives/_generic.py Outdated Show resolved Hide resolved
@ddudt ddudt marked this pull request as ready for review June 18, 2024 18:34
@ddudt ddudt requested review from dpanici and f0uriest June 18, 2024 18:35
desc/utils.py Outdated Show resolved Hide resolved
@ddudt ddudt changed the base branch from master to yge/cpu July 23, 2024 19:18
Base automatically changed from yge/cpu to master July 24, 2024 17:40
@dpanici
Copy link
Collaborator

dpanici commented Jul 24, 2024

Make a blocked grad and hess to allow rev mode with this objective (or have it use FD for grad and hess)

@dpanici
Copy link
Collaborator

dpanici commented Jul 24, 2024

Add a basic tutorial (call subprocess etc but just to run a simple python script not an actual external code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
funtionality New feature or request to do things the code can't do now. objectives Adding or improving objective functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants