-
Notifications
You must be signed in to change notification settings - Fork 172
Mesh independent optimization trick #4575
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
Open
jrmaddison
wants to merge
26
commits into
firedrakeproject:main
Choose a base branch
from
jrmaddison:jrmaddison/transformed_functional
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mesh independent optimization trick #4575
jrmaddison
wants to merge
26
commits into
firedrakeproject:main
from
jrmaddison:jrmaddison/transformed_functional
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9eabd47
to
1d9a838
Compare
… other minor updates
c3c5a86
to
90903a7
Compare
Example using SciPy+L-BFGS-B: preconditioned_optimization.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Trick for mesh-independent optimization with (at least some) optimizers which lack Riesz map support.
Requires dolfin-adjoint/pyadjoint#222
Problem
A source of mesh dependence in some Firedrake+pyadjoint optimizers is the use of an$l_2$ Riesz map. e.g. in a standard gradient-descent step optimizing over some FEM space $U$ we use
where$\tilde{u}_n$ are dofs for a function $u_n \in U$ and $\tilde{g}_n$ are dofs for a derivative $g_n \in U^*$ . The linear combination on the RHS mixes primal and dual space dofs.
Instead we should use a Riesz map
where e.g. for the$L^2$ Riesz map $M$ is the mass matrix.
If we try to fix this by applying a Riesz map to the derivative then we instead introduce errors when evaluating directional derivatives (dolfin-adjoint/pyadjoint#153),
The trick
This PR uses a basis where the mass matrix is an identity.
With
instead of minimizing$J$ , we minimize $J \circ \Pi$ , and then choose an $L^2$ orthonormal basis for the DG space $V$ . Since $V$ is DG we can find an $L^2$ orthonormal basis with element-wise support (see reference below).
Once we have a solution$m_*$ in $V$ to the larger problem, we map to obtain a solution in $U$ , $\Pi ( m_* )$ .
Non-uniqueness
In the case where$V$ is larger than $U$ we are optimizing over a larger space. Derivatives in directions $L^2$ orthogonal to $U$ are zero so e.g. for a gradient-based optimizer we might not 'wander out' of $U$ . However we can optionally add an extra penalty term,
What this looks like in code
The$L^2$ projection, and applying the chain rule (manually) for derivatives.
L2TransformedFunctional
is anAbstractReducedFunctional
which wraps aReducedFunctional
, performing the basis transformation andLimitations
RieszMap
is used to defineL2RieszMap
subclass). AProjector
might be better, but adjoint projection would need to be added (simple but would need to decide on an API).PC
. This uses undocumented PETSc behaviour, and there might be more efficient ways to do this.Function
s /Cofunction
s, which is a bit misleading since the FEM basis is not used.Reference
The transformation is related to the factorization of a mass matrix in section 4.1 of https://doi.org/10.1137/18M1175239. Their matrix$H$ is the composition of
Precisely: the transformation used here is obtained by applying the$L^2$ Riesz map to the result, with a simplification $M_D^{-1} C = C^{-T}$ so that only Cholesky factor inverse actions are needed.