Support blocked linear systems. - #73
Merged
Merged
Conversation
After long dicussion with Gemini (August 2026), I disregarded all advice it gave, and figured out that one of the two issues were: - Since we use SNES and setCTX in the setFunction and setJacobian operations, we can't use the classical python-esque replacement of compiled forms. This invalidated the recompute for non-linear problems. Another issue covered by Claude (in another PR spawned by @finsberg) is that `u` was added as its own dependency if the problem was truely nonlinear. This is now fixed. Added tests to check this.
…result of the replay.
…f my own thoughts/changes: -As pyadjoint eagerly creates new functions, we have to recompile the forms (maybe we should use the data independent form creators, would align with redoxnics ideas). - Add convenience function to get arguments sorted by part. - Minor bug-fixes on using PETSc/non-PETSc vectors. - Correct usage of idx in evaluate_hessian_component. idx only relates to inputs. Output is in control space (always). Added check of this. - Instead of recreating vectors to attach to the tlm/adjoint solvers, instead use the vector that is created once and zero it out. Better for evyerone.
- Using compute_adjoint action on problems that mixes ufl.MixedFunctionSpace arguments and non-mixed arguments is a bad idea (looking at you prepare_hessian). Therefore we use the trick of creating a Lagrangian and differentiate it. - Various nested type-hinting to make the recursive code mypy friendly. - Action on a form does not like lists, only place that has a bit of split handling at the momment (_compute_residual).
Simplify the code for adjoint in linear solver.
Time-distributed control + blocked rewrite.
…o let adjoint_solver have its own internal state and then copy to correct array post solve.
finsberg
self-requested a review
August 28, 2026 07:31
finsberg
approved these changes
Aug 28, 2026
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
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.
Summary
Adds support for blocked forms
[[a00, ..., a0N], ...., [aN0, ..., aNN]]as input to LinearProblem.Bug-fixes for other problems
Various lessons learnt along the way
-As pyadjoint eagerly creates new functions, we have to recompile the forms (maybe we should use the data independent form creators, would align with redoxnics ideas).