Import geerated code to other programs

22 views
Skip to first unread message

Ash

unread,
Nov 25, 2019, 12:47:35 PM11/25/19
to sympy
Hello,
I have gone through the code generation tutorial (https://github.com/shyamashi/scipy-2017-codegen-tutorial/blob/master/notebooks/08-cythonizing.ipynb) and converted my matrices (mass & coriolis) into a 'C' code and created two folders MassMatrix and Coriolisvector. The following two lines are the one which I used

from
sympy.utilities.autowrap import autowrap auto_odes = autowrap(mass_matrix, backend='cython', tempdir='./MassMatrix')

Inside MassMatrix folder, I see file names starting with 'wrapper.', setup.py etc.. Is there a way to rename this file (wrapper) when it's being created? Also, I
ran the command 'python setup.py install' and tried to do

from MassMatrix.wrapper_module_0 import autofunc_c as MM

It throws an error 'No module named 'MassMatrix.wrapper_module_0'. Can anyone tell me what am I doing wrong? Is there a more elegant way to do this?
My folder structure is

ABC
MassMatrix
Coriolis

All the above are names of folders and I am inside ABC folder

Thanks in advance for any help

Aaron Meurer

unread,
Nov 25, 2019, 12:53:22 PM11/25/19
to sympy
What are the files inside the MassMatrix folder? Make sure you have an
__init__.py file there.

Aaron Meurer

>
> Thanks in advance for any help
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/21abfcb4-46cc-462b-9abd-75c0d21fd641%40googlegroups.com.

Ash

unread,
Nov 25, 2019, 1:11:04 PM11/25/19
to sympy
Thanks for the reply. I did have __init__.py in my MassMatrix folder but still the error persists. Attaching a screenshot of the folder


massmatrix.png


Ash


On Monday, 25 November 2019 17:53:22 UTC, Aaron Meurer wrote:
On Mon, Nov 25, 2019 at 10:47 AM Ash <shya...@gmail.com> wrote:
>
> Hello,
> I have gone through the code generation tutorial (https://github.com/shyamashi/scipy-2017-codegen-tutorial/blob/master/notebooks/08-cythonizing.ipynb) and converted my matrices (mass & coriolis) into a 'C' code and created two folders MassMatrix and Coriolisvector. The following two lines are the one which I used
>
>
> from sympy.utilities.autowrap import autowrap
> auto_odes = autowrap(mass_matrix, backend='cython', tempdir='./MassMatrix')
>
> Inside MassMatrix folder, I see file names starting with 'wrapper.', setup.py etc.. Is there a way to rename this file (wrapper) when it's being created? Also, I
> ran the command 'python setup.py install' and tried to do
>
> from MassMatrix.wrapper_module_0 import autofunc_c as MM
>
> It throws an error 'No module named 'MassMatrix.wrapper_module_0'. Can anyone tell me what am I doing wrong? Is there a more elegant way to do this?
> My folder structure is
>
> ABC
>    MassMatrix
>    Coriolis
>
> All the above are names of folders and I am inside ABC folder

What are the files inside the MassMatrix folder? Make sure you have an
__init__.py file there.

Aaron Meurer

>
> Thanks in advance for any help
>
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sy...@googlegroups.com.

Aaron Meurer

unread,
Nov 25, 2019, 1:13:55 PM11/25/19
to sympy
If MassMatrix is your module, then generally setup.py should sit alongside the module, not inside of it. 

Aaron Meurer

To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/07d204d4-290d-4cee-a39a-f9dba038530c%40googlegroups.com.

Ash

unread,
Nov 26, 2019, 7:40:01 AM11/26/19
to sympy
Thanks Aaron for the reply
I tried to install by running 'python setup.py install' outside the MassMatrix folder. I also set path variable in setup.py for the various modules (like wrapper_module_0.pyx etc) as follows
af = '/home/ash/Ash/model_predictive_control/src/Lm/'

ext_mods = [Extension(
    af+'wrapper_module_3', [af+'wrapper_module_3.pyx', af+'wrapped_code_3.c'],
    include_dirs=[np.get_include()],
    library_dirs=[],
    libraries=[],
    extra_compile_args=['-std=c99'],
    extra_link_args=[]

Still the import (from MassMatrix.wrapper_module_0 import autofunc_c as MM) does not work

Ash
Reply all
Reply to author
Forward
0 new messages