replace: only expand CoefficientDerivative#451
Open
pbrubeck wants to merge 9 commits into
Open
Conversation
adabd95 to
8357fa8
Compare
8357fa8 to
a1e2e5d
Compare
CoefficientDerivativeRuleDispatcher registered the abstract Derivative type to reuse_if_untouched, so that foreign Derivative subtypes (e.g. irksome.TimeDerivative) are left alone. But since Grad, ReferenceGrad, etc. are themselves Derivative subtypes with no more specific registration on this subclass, they were *also* being left untouched -- including when they appear inside the content of a CoefficientDerivative that is about to be Gateaux-differentiated. That content needs the same normalization the full DerivativeRuleDispatcher gives it (e.g. pushing a spatial Grad down through Indexed to a bare terminal) before GateauxDerivativeRuleset can process it; skipping that step left GateauxDerivativeRuleset.Grad staring at Grad(Indexed(Coefficient, ...)) instead of Grad(Coefficient), which it does not know how to handle -- this is what test_replace_mixed_element hit via replace() on a mixed-element coefficient. Fix: recurse into a CoefficientDerivative's own content with a plain (cached) DerivativeRuleDispatcher instead of `self`, so nested content gets full normalization while everything *outside* CoefficientDerivative nodes keeps the narrow, foreign-Derivative-safe treatment. Also fix the resulting equality-vs-signature test flakiness in test_replace_mixed_element (independently built expressions can differ in dummy index numbering) and two pre-existing, unrelated mypy var-annotated errors in test_classcoverage.py that blocked `mypy test/` on this branch.
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.
replacewas unecessarily expanding all derivatives too early. This becomes a problem in Irksome where we introduce aTimeDerivativethat cannot be expanded in UFL.This PR avoids this problem by expanding
CoefficientDerivativeonly.