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

Clean the Trapping variable names, #553

Merged
merged 15 commits into from
Sep 18, 2024
Merged

Clean the Trapping variable names, #553

merged 15 commits into from
Sep 18, 2024

Conversation

Jacob-Stevens-Haas
Copy link
Member

@Jacob-Stevens-Haas Jacob-Stevens-Haas commented Sep 4, 2024

Most significant changes are:

  • Clarifying the threshold-0 optimization step shape and terms
  • Making the final optimization step generic, i.e. (_equality_constrained_linlsq())
  • Minimizing H0tilde instead of H0
  • Refactoring out permutation asymmetry (_permutation_asymmetry()), conversion of Q to enstrophy basis (_convert_quad_terms_to_ens_basis()), and creating As (_create_A_symm())
  • Carrying around enstrophy matrix and it's root in the EnstrophyMat class (simplifies parameter signatures without relying on methods)

Most of these changes improve the testability of the code, although tests are not written for all of them (yet?). Furthermore, _solve_m_relax_and_split() needs work, but may need to be changed

Jacob-Stevens-Haas and others added 10 commits August 16, 2024 11:50
This makes it easier to reason about the problem at different steps
Note: Using einsum in place of tensordot because in tensordot:

    The shape of the result consists of the non-contracted axes of the first
    tensor, followed by the non-contracted axes of the second.

Whenever we multiply a projection matrix A like P^{1/2} A P^{-1/2}, using
tensordot means that the last axis of P^{-1/2} comes last, requiring an
additional transpose step.  Using einsum skips that step. See:

```python
import numpy as np

arr1 = np.random.rand(1, 1, 1, 2)
arr2 = np.random.rand(1, 1)

opt1 = np.tensordot(arr2, arr1, axes=([1], [0]))
opt1 = np.tensordot(opt1, arr2, axes=([1], [0]))
opt1 = np.transpose(opt1, axes=[0, 3, 1, 2])

opt2 = np.einsum("ya,abcd,bz->yzcd", arr2, arr1, arr2)

np.testing.assert_allclose(opt1, opt2) # passes
```
…should be multiplied by sqrt(mod_matrix) not mod_matrix, and added in the extra sqrt(P) factors in H0tilde term that gets minimized. All the notebooks working well for the local algorithm, including with the enstrophy, but global with enstrophy is still not working well. Possible reason is that the constraint is still on H0 and not on H0tilde.
This also involves creating a simple EnstrophyMat class.  A lot
of operations carry around the precomputed (inv)root, and we don't
need a whole trapping optimizer to check those operations.
Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.30%. Comparing base (137b19d) to head (7893d43).
Report is 16 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #553      +/-   ##
==========================================
+ Coverage   94.64%   95.30%   +0.65%     
==========================================
  Files          37       37              
  Lines        4018     4046      +28     
==========================================
+ Hits         3803     3856      +53     
+ Misses        215      190      -25     

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

@Jacob-Stevens-Haas Jacob-Stevens-Haas marked this pull request as ready for review September 17, 2024 20:17
Not necessarily the best test, but coverage should at least find any shape
errors that arise.  Also, remove tests for different regularizers from trapping,
now that that regularization is fully abstracted to superclass, with exception
of reg == 0 vs reg != 0
@Jacob-Stevens-Haas Jacob-Stevens-Haas merged commit 23da590 into master Sep 18, 2024
8 checks passed
@Jacob-Stevens-Haas Jacob-Stevens-Haas deleted the clean-shapes branch September 18, 2024 00:37
@Jacob-Stevens-Haas Jacob-Stevens-Haas restored the clean-shapes branch September 18, 2024 00:37
@Jacob-Stevens-Haas Jacob-Stevens-Haas deleted the clean-shapes branch September 18, 2024 00:38
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