Skip to content

Conversation

@moorepants
Copy link
Member

No description provided.

@moorepants
Copy link
Member Author

The pycompilation caching seems to work. On the problem in https://github.com/brocksam/muscle-driven-bicycle-paper if I run the optimal control script twice in a row, the second run takes no time for the compilation step taking total time to instantiate the problem from 180 seconds to 54 seconds (approximately).

I did notice that if I open IPython and run the script twice in a row that the cached compilation did not seem to load (always took 180 seconds to complete). Not sure why.

@moorepants
Copy link
Member Author

To clarify:

python ocp.py
python ocp.py

shows the speed up on the second run but:

$ ipython
run ocp.py
run ocp.py

didn't.

@moorepants
Copy link
Member Author

Bjorn pointed out to me that a version of pycompilation is in sympy/utilities/_compilation.

I have it working but I don't know if it caches the compiled code.

@moorepants
Copy link
Member Author

In the sympy version the import_module_from_file has a kwarg only_if_newer_than. It may be a way to import an old complied version if some dependent files haven't changed.

@moorepants
Copy link
Member Author

SymPy includes pycompilation (private modules), so we could just use it from SymPy instead of the standalone package.

@moorepants
Copy link
Member Author

The SymPy _compilation code states it isn't tested on windows and mac, so that would need to be addressed in SymPy before we add compatibility.

@csu-hmc csu-hmc deleted a comment from Peter230655 Oct 26, 2025
@moorepants
Copy link
Member Author

On ubuntu:

>           raise CompileError(msg)
E           sympy.utilities._compilation.util.CompileError: Error executing '/usr/bin/gcc -fPIC -c -std=c99 -o ./ufuncify_matrix_0_c.o -I/home/runner/miniconda3/envs/test/lib/python3.10/site-packages/numpy/_core/include /tmp/tmp04ldk09c.opty_ufuncify_compile/ufuncify_matrix_0_c.c' in /tmp/tmp04ldk09c.opty_ufuncify_compile (exited status 1):
E            /tmp/tmp04ldk09c.opty_ufuncify_compile/ufuncify_matrix_0_c.c: In function ‘eval_matrix’:
E           /tmp/tmp04ldk09c.opty_ufuncify_compile/ufuncify_matrix_0_c.c:11:30: error: ‘M_PI’ undeclared (first use in this function)
E              11 |     matrix[0] = z_0_*pow(cos(M_PI*b_), if__);
E                 |                              ^~~~
E           /tmp/tmp04ldk09c.opty_ufuncify_compile/ufuncify_matrix_0_c.c:11:30: note: each undeclared identifier is reported only once for each function it appears in

@moorepants
Copy link
Member Author

On mac intel:

Fatal Python error: Segmentation fault

@moorepants
Copy link
Member Author

On mac arm:

Fatal Python error: Segmentation fault

@moorepants
Copy link
Member Author

On windows many compile errors:

>           raise CompileError(msg)
E           sympy.utilities._compilation.util.CompileError: Error executing 'C:\mingw64\bin\gcc.EXE -fPIC -c -std=c99 -o .\ufuncify_matrix_0_c.obj -IC:\Users\runneradmin\miniconda3\envs\test\Lib\site-packages\numpy\_core\include C:\Users\RUNNER~1\AppData\Local\Temp\tmpae_469o4.opty_ufuncify_compile\ufuncify_matrix_0_c.c' in C:\Users\RUNNER~1\AppData\Local\Temp\tmpae_469o4.opty_ufuncify_compile (exited status 1):

C:\Users\runneradmin\miniconda3\envs\test\Lib\site-packages\sympy\utilities\_compilation\runners.py:209: CompileError

@moorepants
Copy link
Member Author

Windows fails with:

E           sympy.utilities._compilation.util.CompileError: Error executing 'C:\mingw64\bin\gcc.EXE -fPIC -c -std=gnu99 -o .\ufuncify_matrix_0_c.obj -IC:\Users\runneradmin\miniconda3\envs\test\Lib\site-packages\numpy\_core\include C:\Users\RUNNER~1\AppData\Local\Temp\tmpqwti7lz2.opty_ufuncify_compile\ufuncify_matrix_0_c.c' in C:\Users\RUNNER~1\AppData\Local\Temp\tmpqwti7lz2.opty_ufuncify_compile (exited status 1):

it is trying to run gcc via mingw

@moorepants
Copy link
Member Author

On mac with clang the -c flag is added but clang says you can't use c++11 with -c. In sympy it seems this -c is always added:

        if self.run_linker:
            # both gnu and intel compilers use '-c' for disabling linker
            self.flags = list(filter(lambda x: x != '-c', self.flags))
        else:
            if '-c' not in self.flags:
                self.flags.append('-c')

@moorepants
Copy link
Member Author

The preferred_vendor is picked up from env var SYMPY_COMPILER_VENDOR or set to gnu. The options are intel, llvm, gnu.

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

Successfully merging this pull request may close these issues.

1 participant