← Back to team overview

yade-dev team mailing list archive

Re: Interesting python usage

 

> Thanks for answering me on a public holiday.
The definition of public holiday is space-dependent ;-)
>   The reason is, I need the Optimisation library, to be used in the
> Interaction Geometry functor.  I want to give input and take output
> from the library to do calculations.  Unfortunately the library is in
> python.
Ok, I see. In that can just copy those few lines from
PeriodicPythonRunner inside your functor (it actually just calls
pyRunString from lib/pyutil/gil.hpp).

> Since I want to use the python library to perform calculations for my
> Interaction functor, I will have to connect it to C.  If I can run
> periodicpythonrunner from C, for my purpose, please explain more to
> me.  If not, the problem that the python script file, which contains
> my function, cannot detect yade's syntax/functions like
> O.bodies[1],etc .  Please help me.     
You still didn't say what happens. I imagine you need to do "from yade
import *" before you go using O.bodies &c. (the O object is really
yade.O).

Expect the functor to be very slow, though. Not slower than say
PeriodicPythonRunner, but if you call it every time from Ig2
functor... :-|

Don't use PyRun_SimpleFile in the functor, it will have to _parse_ and
_byte-compile_ that file AT EVERY CALL OVER AND OVER! Import that file
as module (pyRunString("import myModule");) (as I said in last post) and
just call the function you need via
pyRunString("myModule.myFunction()"). (There would be faster ways, like
getting python::object of that function and calling it without going
through strings... Up to your imagination)

(My guess is that eventually you will better, for performance, solve the
shared library problem -- ask people distributing that software.)

Cheers, v.






Follow ups

References