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

@pydef not overloading method correctly #470

Open
aterenin opened this issue Mar 15, 2018 · 7 comments
Open

@pydef not overloading method correctly #470

aterenin opened this issue Mar 15, 2018 · 7 comments

Comments

@aterenin
Copy link

The following code does not work.

@pydef type SDTExpression <: fenics.Expression
  eval(self, value, x) = begin
    value[1] = 1.0
    return
  end
end

The error it gives is as follows.

TypeError("expected an overload 'eval' or 'eval_cell' method",)

This makes no sense because I've defined one.

@aterenin
Copy link
Author

To add, the following Python code works perfectly fine.

class MyExpression0(Expression):
    def eval(self, value, x):
        value[0] = 1.0
        return

@aterenin aterenin reopened this Mar 15, 2018
@stevengj
Copy link
Member

stevengj commented Mar 15, 2018

Is this because the function name eval is special in Julia? What happens with other method names?

cc @cstjean

@aterenin
Copy link
Author

I don't think so. The following fails too.

@pydef type SDTExpression <: fenics.Expression
  eval_cell(self, value, x,y) = begin
    value[1] = 1.0
    return
  end
end

Python version works fine.

@cstjean
Copy link
Collaborator

cstjean commented Mar 15, 2018

I don't have time to look into this in detail, but googling the error, it seems to come from a project called DOLFIN?

Calling DOLFIN just-in-time (JIT) compiler, this may take some time.
Traceback (most recent call last):
  File "test_dolfin.py", line 148, in <module>
    spray_exp = Expression(ccp_expression)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dolfin/functions/expression.py", line 666, in __new__
    return object.__new__(create_compiled_expression_class(cpp_base))
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dolfin/functions/expression.py", line 187, in create_compiled_expression_class
    {"__init__": __init__})
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dolfin/functions/expression.py", line 357, in __new__
    raise TypeError("expected an overload 'eval' or 'eval_cell' method")
TypeError: expected an overload 'eval' or 'eval_cell' method

It looks like it's trying to JIT compile the function...

@aterenin
Copy link
Author

DOLFIN is a submodule of a differential equation solver called FEniCS.

It will attempt to JIT compile most code that it uses, but provides a Python interface for user-defined functions that to my understanding aren't JIT compiled and can thus callback into Python - the whole reason for using it.

I'm using the FEniCS Julia interface, using which I encountered the above. For my own use case, I've now worked around the issue, but there may still be an issue somewhere in the code.

@cstjean
Copy link
Collaborator

cstjean commented Mar 16, 2018

Hmmm, it looks like the Expression class has an ExpressionMetaClass, which is checking for the existence of eval_cell.

The problem is most likely that we initially create the SDTExpression class on this line, with no methods at all. This probably calls the ExpressionMetaClass code right away, hence the error. We could potentially fix it by creating the methods inside the Dict() call on that line instead of adding them subsequently in the loop. I don't have time to work on it, but I would be happy to review a PR if you're interested in making and testing that change.

That said, I believe that you will then hit #268 on this line. That's harder to fix.

This was referenced Mar 17, 2018
@cstjean
Copy link
Collaborator

cstjean commented Mar 23, 2018

You can try the latest master (Pkg.checkout("PyCall")). The immediate issue should be fixed.

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

No branches or pull requests

3 participants