UnboundLocalError: local variable 'fn_space' referenced before assignment

Bug #1187366 reported by Martin Sandve Alnæs
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dolfin-adjoint
New
Undecided
Unassigned

Bug Description

With latest dolfin-adjoint, there's a bug in functional_partial_derivative, stacktrace:

  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/optimization.py", line 155, in minimize
    opt = algorithm(reduced_func.eval_array, dj, [p.data() for p in reduced_func.parameter], H = reduced_func.hessian_array, **kwargs)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/optimization.py", line 68, in minimize_scipy_generic
    res = scipy_minimize(J, m_global, method = method, **kwargs)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 351, in minimize
    return _minimize_lbfgsb(fun, x0, args, jac, bounds, **options)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/scipy/optimize/lbfgsb.py", line 294, in _minimize_lbfgsb
    f, g = func_and_grad(x)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/scipy/optimize/lbfgsb.py", line 250, in func_and_grad
    g = jac(x, *args)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/optimization.py", line 153, in <lambda>
    seed = dolfin.parameters["optimization"]["test_gradient_seed"])
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/reduced_functional.py", line 266, in derivative_array
    dJdm = self.derivative(forget=forget)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/reduced_functional.py", line 205, in derivative
    dfunc_value = drivers.compute_gradient(self.functional, self.parameter, forget=forget)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/drivers.py", line 144, in compute_gradient
    out = lparam[j].functional_partial_derivative(adjglobals.adjointer, J, adj_var.timestep)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/parameter.py", line 229, in functional_partial_derivative
    dparam = dolfin.Function(fn_space)
UnboundLocalError: local variable 'fn_space' referenced before assignment

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

I overlooked the first error (below) though. Between callbacks to replay_cb and eval_cb I get a missing cell problem. Probably fixable through attaching the mesh somewhere, I'll let you know.

/// Replay#0 at 0 of up0:0:1:Forward, ||up0:0:1:Forward|| = 8.28722
Unable to extract common cell; missing cell definition in form or expression.
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 314, in 'calling callback function'
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/libadjoint/libadjoint.py", line 544, in cfunc
    output_c[0] = self(adjointer, timestep, dependencies, values)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin_adjoint/functional.py", line 84, in __call__
    return dolfin.assemble(functional_value)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin/fem/assembling.py", line 169, in assemble
    common_cell=common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin/fem/form.py", line 56, in __init__
    common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin/compilemodules/jit.py", line 66, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/dolfin/compilemodules/jit.py", line 154, in jit
    return jit_compile(form, parameters=p, common_cell=common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/ffc/jitcompiler.py", line 77, in jit
    return jit_form(ufl_object, parameters, common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/ffc/jitcompiler.py", line 155, in jit_form
    element_mapping = _compute_element_mapping(form, common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/ffc/jitcompiler.py", line 106, in _compute_element_mapping
    common_cell = extract_common_cell(form, common_cell)
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/ufl/algorithms/preprocess.py", line 416, in extract_common_cell
    error("Unable to extract common cell; "\
  File "/home/martinal/opt/fenics/dorsal-hpc-unstable-27022013/lib/python2.7/site-packages/ufl/log.py", line 154, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Unable to extract common cell; missing cell definition in form or expression.
/// J evaluated #0: 0

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

In case someone else encounters this, handled by adding a dummy term to the form:

        # Hack: Add a zero term with a function that references the mesh
        R = FunctionSpace(mesh, "Real", 0)
        f0 = Function(R, name="dummy_zero_constant")
        J += f0**2*ds*dt[START_TIME]

The reason this was necessary is that the previous J only used Constants and so no mesh was available through the form when dolfin-adjoint assembled it.

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Ah. Hmm. Is there a way for us to nicely check if the UFL form that Functional gets has a mesh attached, and to print out a sensible error message if it doesn't?

Revision history for this message
Martin Sandve Alnæs (martinal) wrote :

This stuff isn't nice... But anyway that is the job of ufl and/or dolfin and not dolfin_adjoint.

Revision history for this message
Patrick Farrell (pefarrell) wrote :

Yes, but I was wondering if we can test for it in dolfin-adjoint -- otherwise people will report dolfin-adjoint bugs ;-)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.