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

BUG: Cofunction object has no attribute '_ufl_class_' #3225

Closed
Ig-dolci opened this issue Nov 10, 2023 · 1 comment
Closed

BUG: Cofunction object has no attribute '_ufl_class_' #3225

Ig-dolci opened this issue Nov 10, 2023 · 1 comment
Assignees
Labels

Comments

@Ig-dolci
Copy link
Contributor

Steps to Reproduce

from firedrake import *
from firedrake.adjoint import *
continue_annotation()

def test_solve_cofunction_rhs():
    mesh = UnitSquareMesh(2, 2)
    V = FunctionSpace(mesh, "CG", 1)

    u = TrialFunction(V)
    v = TestFunction(V)
    a = inner(u, v) * dx

    L = Cofunction(V.dual())
    L.vector()[:] = 1.

    w = Function(V)
    solve(a == L, w)
    Aw = assemble(action(a, w))
    assert isinstance(Aw, Cofunction)
    
    assert np.allclose(Aw.dat.data_ro, L.dat.data_ro)

test_solve_cofunction_rhs()
get_working_tape().visualise("tape.pdf")

Error message

  File "/Users/ddolci/work/firedrake_main/src/ufl/ufl/formatting/ufl2unicode.py", line 351, in ufl2unicode
    return expression2unicode(ufl.as_ufl(expression))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ddolci/work/firedrake_main/src/ufl/ufl/formatting/ufl2unicode.py", line 357, in expression2unicode
    return map_expr_dag(rules, expression)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ddolci/work/firedrake_main/src/ufl/ufl/corealg/map_dag.py", line 34, in map_expr_dag
    result, = map_expr_dags(function, [expression], compress=compress,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ddolci/work/firedrake_main/src/ufl/ufl/corealg/map_dag.py", line 100, in map_expr_dags
    r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ddolci/work/firedrake_main/src/ufl/ufl/corealg/multifunction.py", line 99, in undefined
    raise ValueError(f"No handler defined for {o._ufl_class_.__name__}.")
                                               ^^^^^^^^^^^^^
AttributeError: 'Cofunction' object has no attribute '_ufl_class_'

Environment:

  • OS: MacOs
  • Python version: 3.11.6

Additional Info
Fix in the upstream for ufl2unicode works properly for Cofunction.

@Ig-dolci Ig-dolci added the bug label Nov 10, 2023
@Ig-dolci Ig-dolci self-assigned this Nov 10, 2023
@Ig-dolci Ig-dolci changed the title BUG: 'Cofunction' object has no attribute '_ufl_class_' BUG: Cofunction object has no attribute '_ufl_class_' Nov 10, 2023
@nbouziani
Copy link
Contributor

I don't think the fact that Cofunctions don't have a _ufl_class_ attribute is a bug as they are not Expr objects. The error you are observing is a consequence of BaseForm objects, such as Cofunction or FormSum, not having ufl2unicode support at the moment, as mentioned in the following issue firedrakeproject/ufl#43, so the error you are observing is expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants