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

PR: Single-stage optimization add-ons #301

Merged
merged 42 commits into from
Jun 6, 2023
Merged

PR: Single-stage optimization add-ons #301

merged 42 commits into from
Jun 6, 2023

Conversation

rogeriojorge
Copy link
Contributor

The pull request introduces a few features to allow single-stage optimizations to be performed using SIMSOPT. In particular, these are the minimal set of changes needed to fully reproduce the results in https://arxiv.org/abs/2302.10622.
Brief list of changes:

  • Call to jac() in finite_difference allows non-dofs to be broadcasted in an MPI setting
  • Range of surface to be initialized by VMEC as an optional argument (then used in from_nphi_ntheta())
  • Squared flux objective now written as a surface integral of B.n/B instead of only B.n.

@@ -253,6 +258,7 @@ def _jac(self, x: RealArray = None):
x = xs[:, j]
mpi.comm_groups.bcast(x, root=0)
opt.x = x
self.opt.non_dofs = non_dofs
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is the non_dofs attribute used in the optimizable object? Is there any convention or standardization you have in mind here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that it should be an array of doubles. I have no other use cases in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This smells funny to me, because non_dofs is an attribute only of objects created by make_optimizable(). Most optimizable objects don't have a non_dofs attribute.

src/simsopt/objectives/fluxobjective.py Outdated Show resolved Hide resolved
src/simsopt/objectives/fluxobjective.py Outdated Show resolved Hide resolved
@rogeriojorge
Copy link
Contributor Author

@rogeriojorge
Copy link
Contributor Author

Ready to be reviewed again

@@ -93,6 +93,8 @@ def __init__(self,
"""
if x is None:
x = np.array([])
elif np.isscalar(x):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is not added the tests don't pass

Copy link
Contributor

Choose a reason for hiding this comment

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

Which test exactly doesn't pass? What exactly is the error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now not needed as dofs are now handled correctly in J

@rogeriojorge
Copy link
Contributor Author

I am not really sure why the tests are not passing, @landreman @mbkumar could you take a look?

@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Patch coverage: 96.29% and no project coverage change.

Comparison is base (c9eb233) 91.34% compared to head (e055240) 91.35%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #301   +/-   ##
=======================================
  Coverage   91.34%   91.35%           
=======================================
  Files          68       68           
  Lines       12009    12042   +33     
=======================================
+ Hits        10970    11001   +31     
- Misses       1039     1041    +2     
Flag Coverage Δ
unittests 91.35% <96.29%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/simsopt/objectives/fluxobjective.py 95.91% <92.59%> (-4.09%) ⬇️
src/simsopt/_core/finite_difference.py 94.06% <100.00%> (+0.05%) ⬆️
src/simsopt/_core/optimizable.py 90.35% <100.00%> (+0.19%) ⬆️
src/simsopt/mhd/boozer.py 87.09% <100.00%> (ø)
src/simsopt/mhd/vmec.py 93.00% <100.00%> (-0.04%) ⬇️
src/simsopt/objectives/least_squares.py 97.75% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rogeriojorge
Copy link
Contributor Author

All comments addressed, now waiting for the tests to finish.

@rogeriojorge
Copy link
Contributor Author

Updated branch with latest SIMSOPT master branch

@rogeriojorge rogeriojorge force-pushed the rj/single_stage_PR branch 2 times, most recently from c0962fe to be922d7 Compare May 25, 2023 15:08
@rogeriojorge
Copy link
Contributor Author

I found a way of keeping the old dofs and non-dofs structure. The single stage example has a few changes but now the whole simsopt has fewer changes and keeps the same old dofs and non-dofs structure. Hopefully all tests pass now.

@landreman landreman mentioned this pull request May 26, 2023
@landreman landreman self-requested a review June 6, 2023 22:11
@landreman landreman merged commit d1c7ae7 into master Jun 6, 2023
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.

3 participants