Skip to content
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

Constant and derivative #3261

Merged
merged 11 commits into from
Mar 6, 2024
Merged

Constant and derivative #3261

merged 11 commits into from
Mar 6, 2024

Conversation

JDBetteridge
Copy link
Member

Description

Improvements to some oversights with the changes I previously made to Constant.

  • derivative now substitutes the symbolic constant back into the form after taking the derivative. This allows the user to perform solves with the resultant form, which was not the case before.
  • Removes superfluous numbering code in derivative, which was not necessary if I had done things correctly in the first place.
  • Adds ufl2unicode support for Constant via various hackery.

Comment on lines 211 to 224
def _unicode_format_firedrake_constant(self, o):
"""Format a Firedrake constant."""
i = o.count()
var = "💩"
if len(o.ufl_shape) == 1:
var += UC.combining_right_arrow_above
elif len(o.ufl_shape) > 1 and self.colorama_bold:
var = f"{colorama.Style.BRIGHT}{var}{colorama.Style.RESET_ALL}"
return f"{var}{subscript_number(i)}"


# This monkey patches ufl2unicode support for Firedrake constants
Expression2UnicodeHandler.firedrake_constant = _unicode_format_firedrake_constant
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's the right place to add ufl2unicode support for constants, see my comment here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, this code is disgusting. I envision my code as being a temporary workaround current issues whilst someone with more UFL skills fixes this upstream.

@JDBetteridge JDBetteridge force-pushed the JDBetteridge/constant_and_derivative branch from 7b83329 to 852e8ed Compare March 5, 2024 14:42
@JDBetteridge JDBetteridge marked this pull request as ready for review March 5, 2024 14:45
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.

I think this is basically fine, but a better mathematician than me should really take a look at this.

I think eventually we might want to consider dropping support for differentiating wrt constants. Downstream users that rely on this functionality (hopefully not many!) could do the replacement themselves.

tests/regression/test_constant.py Outdated Show resolved Hide resolved
Co-authored-by: Connor Ward <c.ward20@imperial.ac.uk>
@dham dham merged commit 08735b4 into master Mar 6, 2024
10 checks passed
@dham dham deleted the JDBetteridge/constant_and_derivative branch March 6, 2024 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing constant handlers BUG: Errors when differentiating with respect to a Constant
5 participants