Remove Instant dependency
With the use of dijitso
for much of the JIT in DOLFIN, Instant is used only in a small set of cases. Instant
is showing its age and is a heavy weight approach to something that could be simplified if made DOLFIN-specific.
Proposal is to add the JIT functionality presently provided by Instant into DOLFIN.
Comments (15)
-
-
I'll add a couple of more details later.
-
reporter Creating a template for user modules has been on my todo list for a long time. From some simple recent experiments, it might be that
pybind11
(http://pybind11.readthedocs.io/en/master/) might be better than Swig for supporting user-provided custom classes. -
Maybe pybind11 is better than swig if combined with autogenerated wrappers: http://cppbinder.readthedocs.io/en/latest/about.html
However I seriously doubt mixing swig and pybind11 is a good solution for anything.
-
For mechanisms for creating C++ objects via C-style factory functions, follow this trail:
Factory function definition template in ffc
Also need to export it as a symbol in the shared library compiled via dijitso
This is how dijitso imports the factory function with ctypes
This is how ffc jit calls the factory function to create an object (getting only a C pointer)
This is how dolfin swig can convert the pointer to a properly typed
shared_ptr
. -
Think I'm done here now.
-
reporter @martinal Could you give some more detail on what the
ExpressionWithAttributes::set
would do? Who would implement them? They would need set private data. Would the class that implementsset
be generated as part of the JIT? -
It would be implemented in the class generated by dolfin (in compilemodules/compile_expression.py or one of those files):
class JitExpr_019561923812934 : public dolfin::ExpressionWithAttributes { public: void set(string name, double value) { if (name == "f") throw wrong_type(); else if (name == "c") c = value; else throw unknown_name(); } void set(string name, shared_ptr<Function> value) { if (name == "f") f = value; else if (name == "c") throw wrong_type(); else throw unknown_name(); } private: // These are already generated as public members: double c; shared_ptr<Function> f; };
-
You could also as a first step just add generation of get/set functions like above without the base class and without making the member variables private.
-
reporter Bumping priority because the way Instant is using the DOLFIN CMake files has introduced some major JIT overhead.
-
reporter -
assigned issue to
-
assigned issue to
-
reporter - removed responsible
-
reporter The approach described above has been implemented in the pybind11 branch and is working well. It's fast!
-
reporter - changed status to wontfix
This will be dealt with in moving from SWIG to pybind11, see
#897. -
reporter - changed milestone to 2018.1
- Log in to comment
I promised a sketch of a solution for jit-compiled Expressions in dolfin without jitting swig wrappers. This solution covers most use cases, but not the all-out user defined class code. (That use case could arguably be better solved by writing a use module anyway, maybe someone can make a cookiecutter project to set up dolfin extensions with cmake and swig.)
In python, users write
and then can do
The challenges are thus to construct an instance of Expression from generated code, instantiate it with proper inherited classes in the python layer, and connect
e.c = 5.3
with setting a C++ member variabledouble c
of the generated code. Currently swig deals with this by wrapping the class we generate.Expression
subclassExpressionWithAttributes
Expression
subclasses must go through this predefined interface!ExpressionWithAttributes
.__getattr__
,__setattr__
implementations in the python layer to delegatee.c = 3
toe.set("c", 3)
CLS * create_expression_CLS() { return new CLS(); }
whereCLS
is the classname of the generated subclass (e.g.expression_${jitsignature}
)Expression(WithAttributes)
needs to subclassufl.Coefficient
?Draft of ExpressionWithAttributes:
If this is a separate subclass of Expression it doesn't have to be exposed to dolfin in C++ for this to work.