Hessians not working in dolfin adjoint

Hi, I have some troubles with hessians in dolfin adjoint. A minimal non working example follows:

from dolfin import *
from dolfin_adjoint import *

mesh = UnitSquareMesh(10,10)

S = VectorFunctionSpace(mesh, "CG", 1)
h = Function(S)

ALE.move(mesh, h)

V = FunctionSpace(mesh, "CG", 1)
u = Function(V)

w = TrialFunction(V)
v = TestFunction(V)
bcs = DirichletBC(V, 0 ,"on_boundary")
solve(inner(grad(w), grad(v)) * dx == v*dx(mesh), u ,bcs)

J = assemble(u**2 * dx(mesh))

Jhat = ReducedFunctional(J, Control(h))
taylor_to_dict(Jhat, Function(S), Function(S))

It produces:

Traceback (most recent call last):
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/snap/pycharm-professional/302/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 198, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "/snap/pycharm-professional/302/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/leonardo_mutti/PycharmProjects/masters_thesis/tests/ooc/mwe.py", line 22, in <module>
    taylor_to_dict(Jhat, Function(S), Function(S))
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/verification.py", line 125, in taylor_to_dict
    Hm = Enlist(J.hessian(hs))
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/tape.py", line 69, in wrapper
    return function(*args, **kwargs)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/reduced_functional.py", line 99, in hessian
    r = compute_hessian(self.functional, self.controls, m_dot, options=options, tape=self.tape)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/drivers.py", line 68, in compute_hessian
    tape.evaluate_hessian(markings=True)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/tape.py", line 204, in evaluate_hessian
    self._blocks[i].evaluate_hessian(markings=markings)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/tape.py", line 69, in wrapper
    return function(*args, **kwargs)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/pyadjoint/block.py", line 283, in evaluate_hessian
    hessian_output = self.evaluate_hessian_component(inputs,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin_adjoint_common/blocks/assembly.py", line 132, in evaluate_hessian_component
    hessian_outputs += adj_input * self.compat.assemble_adjoint_value(ddform)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin_adjoint_common/compat.py", line 290, in assemble_adjoint_value
    result = backend.assemble(*args, **kwargs)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin/fem/assembling.py", line 198, in assemble
    dolfin_form = _create_dolfin_form(form, form_compiler_parameters)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin/fem/assembling.py", line 56, in _create_dolfin_form
    return Form(form,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin/fem/form.py", line 43, in __init__
    ufc_form = ffc_jit(form, form_compiler_parameters=form_compiler_parameters,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin/jit/jit.py", line 47, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dolfin/jit/jit.py", line 97, in ffc_jit
    return ffc.jit(ufl_form, parameters=p)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/jitcompiler.py", line 217, in jit
    module = jit_build(ufl_object, module_name, parameters)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/jitcompiler.py", line 130, in jit_build
    module, signature = dijitso.jit(jitable=ufl_object,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/dijitso/jit.py", line 165, in jit
    header, source, dependencies = generate(jitable, name, signature, params["generator"])
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/jitcompiler.py", line 65, in jit_generate
    code_h, code_c, dependent_ufl_objects = compile_object(ufl_object,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/compiler.py", line 142, in compile_form
    return compile_ufl_objects(forms, "form", object_names,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/compiler.py", line 190, in compile_ufl_objects
    ir = compute_ir(analysis, prefix, parameters, jit)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/representation.py", line 182, in compute_ir
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/representation.py", line 182, in <listcomp>
    irs = [_compute_integral_ir(fd, form_id, prefix, element_numbers, classnames, parameters, jit)
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/representation.py", line 455, in _compute_integral_ir
    ir = r.compute_integral_ir(itg_data,
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/uflacs/uflacsrepresentation.py", line 82, in compute_integral_ir
    quadrature_rules, quadrature_rule_sizes = compute_quadrature_rules(
  File "/home/leonardo_mutti/anaconda3/envs/masters_thesis/venv_with_mshr/lib/python3.8/site-packages/ffc/uflacs/tools.py", line 64, in compute_quadrature_rules
    assert quadrature_rules[num_points][0] == points
AssertionError

Thanks a lot in advance. This is Fenics + dolfin adjoint 2019.1 on Python 3.8.

I believe i fixed this after the release of 2019.1.0 in: Bitbucket

1 Like

Perfect, this completely solves the problem, thanks!