No tape-able operations at module level in adjoint tests#4867
Merged
JHopeCollins merged 5 commits intomainfrom Feb 10, 2026
Merged
No tape-able operations at module level in adjoint tests#4867JHopeCollins merged 5 commits intomainfrom
JHopeCollins merged 5 commits intomainfrom
Conversation
connorjward
reviewed
Feb 6, 2026
leo-collins
pushed a commit
that referenced
this pull request
Feb 17, 2026
j-bowhay
pushed a commit
to j-bowhay/firedrake
that referenced
this pull request
Feb 24, 2026
connorjward
pushed a commit
that referenced
this pull request
Mar 3, 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.
I was getting some very odd and difficult to reproduce errors with the adjoint tests, for example a test was passing if I only passed that file to pytest, but was failing if I passed the test directory and just selected that test using
-k.It seems that if there are tape-able operations at module level in the adjoint tests, they pollute the global state when that test file is collected, even if the tests in that module are not run. This still appeared to happen even when I tried to switch off annotations with the module-level fixture, and used
set_working_tapeto wrap all my taped operations!This PR removes any tape-able operations from module level and stuffs them either inside the tests or inside fixtures which are called on a test-by-test basis when the tests are run (not when they are collected).
I also put the fixtures that manage the taping in the adjoint tests into the
conftest.py. We still need to "call" them in each adjoint test file by writing file-level fixtures that call the conftest fixtures, but at least all the logic is in one place.Uses dolfin-adjoint/pyadjoint#245 to slightly simplify the use of
set_working_tapein the fixtures.