Skip to content

No tape-able operations at module level in adjoint tests#4867

Merged
JHopeCollins merged 5 commits intomainfrom
JHopeCollins/reduce-adjoint-tests-global-state
Feb 10, 2026
Merged

No tape-able operations at module level in adjoint tests#4867
JHopeCollins merged 5 commits intomainfrom
JHopeCollins/reduce-adjoint-tests-global-state

Conversation

@JHopeCollins
Copy link
Member

@JHopeCollins JHopeCollins commented Feb 6, 2026

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_tape to 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_tape in the fixtures.

@JHopeCollins JHopeCollins marked this pull request as ready for review February 10, 2026 08:52
Copy link
Contributor

@connorjward connorjward left a comment

Choose a reason for hiding this comment

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

LGTM

@JHopeCollins JHopeCollins merged commit 8ba4657 into main Feb 10, 2026
13 of 14 checks passed
@JHopeCollins JHopeCollins deleted the JHopeCollins/reduce-adjoint-tests-global-state branch February 10, 2026 11:54
j-bowhay pushed a commit to j-bowhay/firedrake that referenced this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants