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

🎨 Control coil enforcement, constraint stabilisation and general cleanup #3518

Merged
merged 13 commits into from
Sep 19, 2024

Conversation

je-cook
Copy link
Contributor

@je-cook je-cook commented Aug 12, 2024

Description

  • Fixes some bugs where control coils were not explicitly selected in parts of the equilibria optimisation problems.
  • Added rounding to field and force constraints (to 16 dp) which seems to stabilise them in local testing. I have it on good authority that the condition matrix of force constraint is infinite therefore very unstable. This seems to help a bit.
  • Some general cleanup around properties on component managers

This was done while doing some work towards passive coils

Interface Changes

Checklist

I confirm that I have completed the following checks:

  • Tests run locally and pass pytest tests --reactor
  • Code quality checks run locally and pass pre-commit run --from-ref develop --to-ref HEAD
  • Documentation built locally and checked sphinx-build -W documentation/source documentation/build

@je-cook je-cook added optimisation Tasks relating to optimisation quality Tasks relating to quality issues or improvements labels Aug 12, 2024
@je-cook je-cook requested review from a team as code owners August 12, 2024 08:03
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

Attention: Patch coverage is 83.15789% with 16 lines in your changes missing coverage. Please review.

Project coverage is 76.40%. Comparing base (60d6be1) to head (6dfb5d9).
Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
bluemira/equilibria/run.py 30.43% 16 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3518      +/-   ##
===========================================
+ Coverage    76.38%   76.40%   +0.01%     
===========================================
  Files          230      230              
  Lines        26677    26700      +23     
===========================================
+ Hits         20378    20399      +21     
- Misses        6299     6301       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

github-actions bot commented Aug 12, 2024

⚠️ Warning Report

Found 0 new warnings, 1 fixed warning. 🎉

All warnings (6)

On collect

  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ufl/core/ufl_type.py:56: DeprecationWarning: attach_operators_from_hash_data deprecated, please use UFLObject instead.

On runtest

  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ffcx/element_interface.py:23: DeprecationWarning: Use of elements created by UFL is deprecated. You should create elements directly using Basix.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ffcx/element_interface.py:26: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/ufl/core/expr.py:275: DeprecationWarning: Expr.ufl_domain() is deprecated, please use extract_unique_domain(expr) instead.
  • /home/runner/miniconda3/envs/bluemira/lib/python3.10/site-packages/basix/ufl.py:1909: DeprecationWarning: Converting elements created in UFL to Basix elements is deprecated. You should create the elements directly using basix.ufl.element instead
  • /home/runner/work/bluemira/bluemira/bluemira/radiation_transport/radiation_tools.py:731: DeprecationWarning: interp2dis deprecated!interp2d` is deprecated in SciPy 1.10 and will be removed in SciPy 1.12.0.

For legacy code, nearly bug-for-bug compatible replacements are
RectBivariateSpline on regular grids, and bisplrep/bisplev for
scattered 2D data.

In new code, for regular grids use RegularGridInterpolator instead.
For scattered data, prefer LinearNDInterpolator or
CloughTocher2DInterpolator.

For more details see
https://gist.github.com/ev-br/8544371b40f414b7eaf3fe6217209bff
`

@je-cook je-cook force-pushed the je-cook/control_enforcement branch 2 times, most recently from 11de02c to e1bafb3 Compare August 16, 2024 06:19
@je-cook je-cook force-pushed the je-cook/control_enforcement branch 3 times, most recently from dffe8de to a8e1f36 Compare August 29, 2024 09:21
@je-cook je-cook requested review from geograham and removed request for geograham September 13, 2024 12:33
Copy link
Contributor

@oliverfunk oliverfunk left a comment

Choose a reason for hiding this comment

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

I've gone through it quite carefully.

Two things:

  • All the spherical harmioncs stuff is using sig_fig_round, where the constraints use np.round. They obviously do different things, but I find the inconsistency slightly worrying.

  • The 15 sig figs used in the SH stuff should be a param.

Copy link

sonarcloud bot commented Sep 18, 2024

Copy link
Contributor

@geograham geograham left a comment

Choose a reason for hiding this comment

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

Been through the changes, all looks sensible and ready to merge.

Copy link
Contributor

@oliverfunk oliverfunk left a comment

Choose a reason for hiding this comment

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

Okay lgtm!

Perpahs in some doc. it could be stated that rounding constraint return values is generally recommended for improving numeric stability.

As a recommendation for constraint implementers.

@je-cook
Copy link
Contributor Author

je-cook commented Sep 19, 2024

As we talked about I think its very constraint specific for those constraints that are numerically unstable. As you said we could do something as part of a wider refactor of the eq opt stuff

@je-cook je-cook merged commit b57b186 into develop Sep 19, 2024
11 checks passed
@je-cook je-cook deleted the je-cook/control_enforcement branch September 19, 2024 09:23
geograham added a commit to geograham/bluemira that referenced this pull request Oct 11, 2024
geograham added a commit to geograham/bluemira that referenced this pull request Oct 16, 2024
je-cook added a commit that referenced this pull request Oct 16, 2024
* Add choose psi norm value option to SH constraint (LCFS is still default), also remove clipping, not nessisary since fixes in #3518

* remove unessisary

* Update bluemira/equilibria/optimisation/harmonics/harmonics_approx_functions.py

Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>

---------

Co-authored-by: je-cook <81617086+je-cook@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimisation Tasks relating to optimisation quality Tasks relating to quality issues or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants