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

CoilIntegratedCurvature objective #1485

Merged
merged 17 commits into from
Jan 29, 2025
Merged

CoilIntegratedCurvature objective #1485

merged 17 commits into from
Jan 29, 2025

Conversation

ddudt
Copy link
Collaborator

@ddudt ddudt commented Dec 20, 2024

A scalar version of convexity for a curve: $\int \kappa |\partial_s \mathbf{x}| ds = 2 \pi$

Similar to our existing CoilCurvature objective, which is signed to indicate convexity.

@ddudt ddudt added objectives Adding or improving objective functions coil stuff relating to coils and coil optimization labels Dec 20, 2024
@ddudt ddudt self-assigned this Dec 20, 2024
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.69%. Comparing base (b3b6dcc) to head (e6b117c).
Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1485      +/-   ##
==========================================
- Coverage   95.69%   95.69%   -0.01%     
==========================================
  Files         101      101              
  Lines       25614    25633      +19     
==========================================
+ Hits        24511    24529      +18     
- Misses       1103     1104       +1     
Files with missing lines Coverage Δ
desc/objectives/__init__.py 100.00% <ø> (ø)
desc/objectives/_coils.py 99.36% <100.00%> (+0.01%) ⬆️

... and 1 file with indirect coverage changes

Copy link
Contributor

github-actions bot commented Dec 20, 2024

|             benchmark_name             |         dt(%)          |         dt(s)          |        t_new(s)        |        t_old(s)        | 
| -------------------------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
 test_build_transform_fft_lowres         |     +6.35 +/- 4.95     | +3.65e-02 +/- 2.85e-02 |  6.12e-01 +/- 1.4e-02  |  5.76e-01 +/- 2.5e-02  |
-test_equilibrium_init_medres            |     +7.13 +/- 2.36     | +3.27e-01 +/- 1.08e-01 |  4.92e+00 +/- 4.2e-02  |  4.59e+00 +/- 9.9e-02  |
 test_equilibrium_init_highres           |     +4.40 +/- 2.45     | +2.63e-01 +/- 1.46e-01 |  6.23e+00 +/- 1.0e-01  |  5.97e+00 +/- 1.1e-01  |
 test_objective_compile_dshape_current   |     +2.09 +/- 5.37     | +9.53e-02 +/- 2.45e-01 |  4.66e+00 +/- 2.0e-01  |  4.56e+00 +/- 1.4e-01  |
 test_objective_compute_dshape_current   |     +6.79 +/- 14.27    | +3.71e-04 +/- 7.81e-04 |  5.84e-03 +/- 3.3e-04  |  5.47e-03 +/- 7.1e-04  |
 test_objective_jac_dshape_current       |     +0.48 +/- 10.08    | +2.26e-04 +/- 4.73e-03 |  4.71e-02 +/- 3.4e-03  |  4.69e-02 +/- 3.3e-03  |
 test_perturb_2                          |     +3.35 +/- 3.85     | +7.28e-01 +/- 8.37e-01 |  2.25e+01 +/- 2.1e-01  |  2.18e+01 +/- 8.1e-01  |
-test_proximal_freeb_jac                 |    +14.89 +/- 3.28     | +1.13e+00 +/- 2.48e-01 |  8.68e+00 +/- 1.3e-01  |  7.56e+00 +/- 2.1e-01  |
 test_solve_fixed_iter                   |     +5.38 +/- 4.14     | +1.82e+00 +/- 1.40e+00 |  3.57e+01 +/- 1.3e+00  |  3.39e+01 +/- 4.8e-01  |
 test_LinearConstraintProjection_build   |     -0.32 +/- 4.79     | -3.59e-02 +/- 5.33e-01 |  1.11e+01 +/- 3.9e-01  |  1.11e+01 +/- 3.7e-01  |
 test_build_transform_fft_midres         |     +0.82 +/- 3.30     | +5.05e-03 +/- 2.04e-02 |  6.25e-01 +/- 1.8e-02  |  6.20e-01 +/- 9.1e-03  |
 test_build_transform_fft_highres        |     +0.53 +/- 6.73     | +5.24e-03 +/- 6.65e-02 |  9.94e-01 +/- 6.4e-02  |  9.88e-01 +/- 1.9e-02  |
 test_equilibrium_init_lowres            |     -0.21 +/- 2.50     | -8.51e-03 +/- 9.97e-02 |  3.98e+00 +/- 6.9e-02  |  3.99e+00 +/- 7.2e-02  |
 test_objective_compile_atf              |     -0.54 +/- 1.74     | -4.53e-02 +/- 1.47e-01 |  8.37e+00 +/- 7.6e-02  |  8.42e+00 +/- 1.3e-01  |
 test_objective_compute_atf              |     +1.15 +/- 3.31     | +1.83e-04 +/- 5.29e-04 |  1.62e-02 +/- 4.0e-04  |  1.60e-02 +/- 3.4e-04  |
 test_objective_jac_atf                  |     -0.66 +/- 1.86     | -1.27e-02 +/- 3.59e-02 |  1.92e+00 +/- 2.4e-02  |  1.93e+00 +/- 2.6e-02  |
 test_perturb_1                          |     -0.35 +/- 2.32     | -5.26e-02 +/- 3.49e-01 |  1.50e+01 +/- 2.5e-01  |  1.50e+01 +/- 2.4e-01  |
 test_proximal_jac_atf                   |     +0.62 +/- 0.59     | +5.14e-02 +/- 4.85e-02 |  8.31e+00 +/- 4.2e-02  |  8.26e+00 +/- 2.4e-02  |
 test_proximal_freeb_compute             |     -0.50 +/- 1.56     | -1.02e-03 +/- 3.16e-03 |  2.02e-01 +/- 2.1e-03  |  2.03e-01 +/- 2.4e-03  |
 test_solve_fixed_iter_compiled          |     -0.60 +/- 0.94     | -1.26e-01 +/- 1.95e-01 |  2.07e+01 +/- 1.6e-01  |  2.08e+01 +/- 1.2e-01  |

@dpanici dpanici marked this pull request as ready for review January 15, 2025 18:34
desc/objectives/_coils.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@dpanici dpanici left a comment

Choose a reason for hiding this comment

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

  • give a self._endpoint attribute to CoilConvexity to be True
  • check for this attribute in _CoilObjective.build to decide if endpoint should be true or not (False by default if hasattr(self._endpoint) is False
  • move errorif statement to after super.build() in build of CoilConvexity
  • make docstring clearer for CoilConvexity
  • Fix docs

@dpanici
Copy link
Collaborator

dpanici commented Jan 22, 2025

Call it IntegratedCurvature

@ddudt ddudt added the P2 Medium Priority, not urgent but should be on the near-term agend label Jan 28, 2025
@ddudt ddudt requested review from dpanici, a team, rahulgaur104, f0uriest, sinaatalay, unalmis and YigitElma and removed request for a team January 28, 2025 18:06
desc/objectives/_coils.py Outdated Show resolved Hide resolved
data = tree_leaves(data, is_leaf=lambda x: isinstance(x, dict))
out = jnp.array(
[
trapezoid(
Copy link
Member

Choose a reason for hiding this comment

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

I think you can get the same thing if you leave off the endpoint and do (curvature*x_s*ds).sum(). The integrand is periodic so the endpoint and start are the same.

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 is slightly less accurate then the trapezoid integration (atol=2e-5 vs atol=1e-6 at the grid resolution used in the tests) but I still like this change for the simplicity.

desc/objectives/_coils.py Outdated Show resolved Hide resolved
tests/test_objective_funs.py Outdated Show resolved Hide resolved
tests/test_objective_funs.py Outdated Show resolved Hide resolved
tests/test_objective_funs.py Outdated Show resolved Hide resolved
tests/test_objective_funs.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
desc/objectives/_coils.py Outdated Show resolved Hide resolved
tests/test_objective_funs.py Outdated Show resolved Hide resolved
daniel-dudt and others added 2 commits January 28, 2025 15:00
Co-authored-by: Yigit Gunsur Elmacioglu <102380275+YigitElma@users.noreply.github.com>
@ddudt ddudt requested review from f0uriest and YigitElma January 28, 2025 22:04
@ddudt ddudt changed the title CoilConvexity objective CoilIntegratedCurvature objective Jan 28, 2025
YigitElma
YigitElma previously approved these changes Jan 28, 2025
YigitElma
YigitElma previously approved these changes Jan 28, 2025
f0uriest
f0uriest previously approved these changes Jan 29, 2025
desc/objectives/_coils.py Outdated Show resolved Hide resolved
@daniel-dudt daniel-dudt dismissed stale reviews from f0uriest and YigitElma via e6b117c January 29, 2025 20:46
@ddudt ddudt dismissed dpanici’s stale review January 29, 2025 20:46

made requested changes

@ddudt ddudt requested review from f0uriest and YigitElma January 29, 2025 20:46
@ddudt ddudt merged commit 48eb4d0 into master Jan 29, 2025
25 checks passed
@ddudt ddudt deleted the dd/convex branch January 29, 2025 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coil stuff relating to coils and coil optimization objectives Adding or improving objective functions P2 Medium Priority, not urgent but should be on the near-term agend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants