Subject: [Ffc] JIT compile strangeness

From: Harish Narayanan <[email-masked]>
Date: Mon, 01 Feb 2010 16:12:28 +0000

I am now running into the following strange error. Upon the first run of
the following python code:

from dolfin import *

mesh = UnitSquare(4, 4)
BDM = FunctionSpace(mesh, "BDM", 1)
DG = FunctionSpace(mesh, "DG", 0)
mixed_space = MixedFunctionSpace([BDM, DG])

u, p = Function(mixed_space).split()

uh = project(u)
ph = project(p)

I receive an error of the following sort. But upon subsequent runs, it
gets picked up from cache correctly and runs without complaining.

raceback (most recent call last):
  File "trial3.py", line 11, in <module>
    ph = project(p)
  File "fenics-path/lib/python2.5/site-packages/dolfin/fem/project.py",
line 42, in project
    V = _extract_function_space(v)
  File "fenics-path/lib/python2.5/site-packages/dolfin/fem/project.py",
line 84, in _extract_function_space
    V = FunctionSpace(mesh, "CG", 1)
  File
"fenics-path/lib/python2.5/site-packages/dolfin/function/functionspace.py",
line 226, in __init__
    FunctionSpaceBase.__init__(self, mesh, element)
  File
"fenics-path/lib/python2.5/site-packages/dolfin/function/functionspace.py",
line 44, in __init__
    ufc_element, ufc_dofmap = jit(self._ufl_element)
  File
"fenics-path/lib/python2.5/site-packages/dolfin/compilemodules/jit.py",
line 44, in mpi_jit
    return local_jit(*args, **kwargs)
  File
"fenics-path/lib/python2.5/site-packages/dolfin/compilemodules/jit.py",
line 103, in jit
    return jit_compile(form, parameters=p)
  File "fenics-path/lib/python2.5/site-packages/ffc/jit.py", line 59, in jit
    return jit_element(object, parameters)
  File "fenics-path/lib/python2.5/site-packages/ffc/jit.py", line 147,
in jit_element
    return _extract_element_and_dofmap(module, form_data)
  File "fenics-path/lib/python2.5/site-packages/ffc/jit.py", line 179,
in _extract_element_and_dofmap
    return (getattr(module, module.__name__ + ("_finite_element_%d" % i))(),
AttributeError: 'module' object has no attribute
'form_8c658e9e24652ee956904c0c5a2f5dc9e2b97c2b_finite_element_2

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 17:41:38 +0100

Works for me. Maybe instant-clean might help?

--
Anders

On Mon, Feb 01, 2010 at 04:12:28PM +0000, Harish Narayanan wrote:
> _______________________________________________
> Mailing list: https://launchpad.net/~ffc
> Post to     : [email-masked]
> Unsubscribe : https://launchpad.net/~ffc
> More help   : https://help.launchpad.net/ListHelp

---

From: Harish Narayanan <[email-masked]>
Date: Mon, 01 Feb 2010 17:03:45 +0000

> Works for me. Maybe instant-clean might help?

I've tried an instant-clean. I also wiped out my .py files from
site-packages and installed everything from scratch.

Harish

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 18:20:32 +0100

> site-packages and installed everything from scratch.

Very strange. I ran the exact same script as you pasted in your email.

Is anyone else able to run the test?

--
Anders

---

From: Marie Rognes <[email-masked]>
Date: Mon, 01 Feb 2010 18:21:35 +0100

> Is anyone else able to run the test?

Works fine here.

--
Marie
> --
> Anders
>   
> ------------------------------------------------------------------------
>

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 18:22:55 +0100

> >Is anyone else able to run the test?

Must be a platform thing then. Harish, are you trying to run this on
an iPad? You might be missing a flash-plugin.

--
Anders

---

From: Harish Narayanan <[email-masked]>
Date: Mon, 01 Feb 2010 17:27:46 +0000

> an iPad? You might be missing a flash-plugin.

That's exactly it!

Harish

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 21:38:49 +0100

Can anyone else check if you see this bug or if it is Harish-specific?
Kristian? Garth?

--
Anders

---

From: Kristian Oelgaard <[email-masked]>
Date: Mon, 1 Feb 2010 22:15:34 +0100 (CET)

> Can anyone else check if you see this bug or if it is Harish-specific?

It didn't break here. I got:

Matrix of size 50 x 50 has 548 nonzero entries.
Sorting sparsity pattern.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Solving linear system of size 50 x 50 (uBLAS Krylov solver).
*** Warning: Conjugate-gradient method not yet programmed for uBLASKrylovSolver. Using GMRES.
Krylov solver converged in 0 iterations.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Matrix of size 25 x 25 has 137 nonzero entries.
Sorting sparsity pattern.
Calling FFC just-in-time (JIT) compiler, this may take some time.
Solving linear system of size 25 x 25 (uBLAS Krylov solver).
*** Warning: Conjugate-gradient method not yet programmed for uBLASKrylovSolver. Using GMRES.
Krylov solver converged in 0 iterations.

at the end.

Kristian

> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAktnO9kACgkQTuwUCDsYZdFZXACglHgYCUolR04s9+6/1lxxr+vP
> yksAnRXVRSaCcQBRZEQU6RsBQmY2lYDy
> =GfCd
> -----END PGP SIGNATURE-----
>

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 22:21:47 +0100

> Krylov solver converged in 0 iterations.

I get

# python harishtest.py
Matrix of size 50 x 50 has 548 nonzero entries.
Solving linear system of size 50 x 50 (Krylov solver).
PETSc Krylov solver (cg, ilu) converged in 0 iterations.
Matrix of size 25 x 25 has 137 nonzero entries.
Solving linear system of size 25 x 25 (Krylov solver).
PETSc Krylov solver (cg, ilu) converged in 0 iterations.

--
Anders

---

From: Johan Hake <[email-masked]>
Date: Mon, 1 Feb 2010 13:23:27 -0800

> Can anyone else check if you see this bug or if it is Harish-specific?

Works here too. Same output as Kristian, but using PETSc backend.

Johan

---

From: Harish Narayanan <[email-masked]>
Date: Mon, 01 Feb 2010 21:46:50 +0000

> Can anyone else check if you see this bug or if it is Harish-specific?

I guess it is me-specific, but it is showing up and disappearing almost
entirely at random. I'll present it once more when (if) I am able to
narrow it down.

Harish

---

From: Anders Logg <[email-masked]>
Date: Mon, 1 Feb 2010 23:02:29 +0100

> entirely at random. I'll present it once more when (if) I am able to

ok, try adding something like

  print dir(module)

inside the function _extract_element_and_dofmap in jit.py in FFC.

That should give you some hint on what goes wrong.

--
Anders

---

From: Marie Rognes <[email-masked]>
Date: Tue, 02 Feb 2010 12:29:55 +0100

More compile strangeness:  Clean cache, error at first run,
things running at second run:

meg@localhost ~/local/src/fenics/adaptivity/demo $ instant-clean
Instant cache is empty
meg@localhost ~/local/src/fenics/adaptivity/demo $ python test.py
Calling FFC just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    L = assemble(v*dx)
  File 
"/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/assemble.py", 
line 88, in assemble
    dolfin_form = Form(form, function_spaces, coefficients, 
form_compiler_parameters)
  File 
"/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/form.py", line 
39, in __init__
    function_spaces)
  File 
"/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/form.py", line 
60, in _extract_function_spaces
    if not isinstance(func.function_space(), cpp.FunctionSpace):
AttributeError: 'Argument' object has no attribute 'function_space'
meg@localhost ~/local/src/fenics/adaptivity/demo $ python test.py
L =  <PETScVector of size 24>

Anyone else experience this?

from dolfin import *
mesh = UnitSquare(2,2)
V_h = FunctionSpace(mesh, "DG", 1)
v = TestFunction(V_h)
L = assemble(v*dx)
print "L = ", L

---

From: Anders Logg <[email-masked]>
Date: Tue, 2 Feb 2010 13:08:03 +0100

On Tue, Feb 02, 2010 at 12:29:55PM +0100, Marie Rognes wrote:
>  File "/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/assemble.py",
> line 88, in assemble
> "/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/form.py",
> line 39, in __init__
>    function_spaces)
>  File
> "/home/meg/local/lib64/python2.6/site-packages/dolfin/fem/form.py",
> line 60, in _extract_function_spaces

Same problem here. I'll fix it.

--
Anders

---

From: Harish Narayanan <[email-masked]>
Date: Tue, 02 Feb 2010 12:08:51 +0000

> V_h = FunctionSpace(mesh, "DG", 1)

Me, me, me! :)

Harish

---

From: Anders Logg <[email-masked]>
Date: Tue, 2 Feb 2010 13:47:11 +0100

> > V_h = FunctionSpace(mesh, "DG", 1)

This is fixed now. It was an intricate caching problem relating to
reuse of the dummy form v*dx that FFC creates when JIT compiling
elements (for use in DOLFIN FunctionSpace).

I fixed it by making sure FormData is not cached when compiling
elements but a proper solution (removal of the FFC dummy form) should
be implemented instead. I've added a FIXME in jit.py.

--
Anders

---

From: Marie Rognes <[email-masked]>
Date: Tue, 02 Feb 2010 13:54:24 +0100

Anders Logg wrote:
> This is fixed now.

Hurray!

--
Marie

>  It was an intricate caching problem relating to

---

From: Harish Narayanan <[email-masked]>
Date: Tue, 02 Feb 2010 12:56:56 +0000

On 02/02/2010 12:54, Marie Rognes wrote:
>>>> line

!!

---

From: "Garth N. Wells" <[email-masked]>
Date: Tue, 02 Feb 2010 22:45:13 +0000

> be implemented instead. I've added a FIXME in jit.py.

This works for Marie's form, but the it's broken for the below form.

Garth

from dolfin import *
from numpy import random

mesh = UnitSquare(24, 24)
n = FacetNormal(mesh)
V = FunctionSpace(mesh, "DG", 1)
v = TestFunction(V)
u = Function(V)

# Fill vector with some numbers
random.seed(2)
u.vector().set_local( random.rand(u.vector().size()) )

flux = variable(grad(u))

L2 = dot(jump(v, n), avg(flux))*dS
print "Norm case 2 (using variable): ", assemble(L2).norm("l2")