Aluriak / webclingo-example

Example of clingo usage on website as a client-side JS program
https://aluriak.github.io/webclingo-example/
12 stars 3 forks source link

Add python to web clingo #24

Open flavioeverardo opened 5 years ago

flavioeverardo commented 5 years ago

Hi Lucas, just wondering have you tried to compile it with python support? In my attempts (apparently) I have compiled with python but is not working just like that. I guess I have to do more things, right?

Aluriak commented 5 years ago

Hi Flavio !

I never tried it, sorry… Did you try to compile python first, and then use compile_web.sh with something like those parameters modified:

    -DCLINGO_BUILD_WITH_PYTHON=Off \
    -DLUA_INCLUDE_DIR="$(pwd)/../../../lua/install/include" \
    -DLUA_LIBRARIES="$(pwd)/../../../lua/install/lib/liblua.a" \

I have very little time for that, but if you come up with a solution, please share it with us, because that would be awesome !

flavioeverardo commented 5 years ago

Hi Lucas,

Yes I did it that way and according to the installer, the python libs are found and it should be working. The bad news is that I do not figure a way to test it if it is working. I only receive a message in the browser (and in the JS console) that there was an error.

Of course I'm by far no expert in JS to know what could be the way. If you come with an idea let me know and I can see if I can implement it.

You can try it at flavioeverardo.com/clingo there is a propagator for Python. How did you came with the Lua integration?

Regards Flavio

On Apr 13, 2019, at 12:31 PM, Lucas Bourneuf notifications@github.com wrote:

Hi Flavio !

I never tried it, sorry… Did you try to compile python first, and then use compile_web.sh with something like those parameters modified:

-DCLINGO_BUILD_WITH_PYTHON=Off \
-DLUA_INCLUDE_DIR="$(pwd)/../../../lua/install/include" \
-DLUA_LIBRARIES="$(pwd)/../../../lua/install/lib/liblua.a" \

I have very little time for that, but if you come up with a solution, please share it with us, because that would be awesome !

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

flavioeverardo commented 5 years ago

Sorry. Is just a simple Python file with no propagator (yet) but I have an error on the clingo.js file line 8.

Flavio

On Apr 13, 2019, at 1:09 PM, Flavio Everardo flavio.everardo@cs.uni-potsdam.de wrote:

Hi Lucas,

Yes I did it that way and according to the installer, the python libs are found and it should be working. The bad news is that I do not figure a way to test it if it is working. I only receive a message in the browser (and in the JS console) that there was an error.

Of course I'm by far no expert in JS to know what could be the way. If you come with an idea let me know and I can see if I can implement it.

You can try it at flavioeverardo.com/clingo there is a propagator for Python. How did you came with the Lua integration?

Regards Flavio

On Apr 13, 2019, at 12:31 PM, Lucas Bourneuf notifications@github.com wrote:

Hi Flavio !

I never tried it, sorry… Did you try to compile python first, and then use compile_web.sh with something like those parameters modified:

-DCLINGO_BUILD_WITH_PYTHON=Off \
-DLUA_INCLUDE_DIR="$(pwd)/../../../lua/install/include" \
-DLUA_LIBRARIES="$(pwd)/../../../lua/install/lib/liblua.a" \

I have very little time for that, but if you come up with a solution, please share it with us, because that would be awesome !

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Aluriak commented 5 years ago

The lua integration is made using the arguments i showed you ; i'm therefore not able to explain why it would'nt work with python.

I'm not a JS coder either, so i can't really help you for that part.

I only receive a message in the browser (and in the JS console) that there was an error.

You have to provide a flag somewhere to activate proper logging. You find that in the error description :

Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch. 

I guess the flags are for emscripten.

flavioeverardo commented 5 years ago

Hi Lucas,

Thanks for your reply. I realized that I compiled python as usual and i have the guess that i should compile it with emscripten as with Lua and use the Cmake arguments for python. Also I’m not a JS coder but I will give it a shot hopefully during the weekend.

Thanks for the flag tip.

I will keep you noticed. Flavio

On Apr 16, 2019, at 9:02 AM, Lucas Bourneuf notifications@github.com wrote:

The lua integration is made using the arguments i showed you ; i'm therefore not able to explain why it would'nt work with python.

I'm not a JS coder either, so i can't really help you for that part.

I only receive a message in the browser (and in the JS console) that there was an error.

You have to provide a flag somewhere to activate proper logging. You find that in the error description :

Exception catching is disabled, this exception cannot be caught. Compile with -s DISABLE_EXCEPTION_CATCHING=0 or DISABLE_EXCEPTION_CATCHING=2 to catch. I guess the flags are for emscripten.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Aluriak commented 5 years ago

I compiled python as usual and i have the guess that i should compile it with emscripten

Oh, yes, obviously. I forgot that obvious detail too.

Unless emscriptem find trouble into compiling CPython, It should be quite straightforward to make this work.

i wait eagerly for your PR.

domoritz commented 5 years ago

Maybe you can link against https://github.com/iodide-project/pyodide, which is python (and numpy etc) in wasm.

flavioeverardo commented 5 years ago

Sure, thanks a lot Dominik, this might be the last piece of the puzzle ;-)

Best regards, Flavio

On Wed, 14 Aug 2019 05:05:52 -0700 Dominik Moritz notifications@github.com wrote:

Maybe you can link against https://github.com/iodide-project/pyodide, which is python (and numpy etc) in wasm.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/Aluriak/webclingo-example/issues/24#issuecomment-521218575

flavioeverardo commented 5 years ago

Hi all,

I did some tries this last week. I believe I'm close but still... If you have any ideas or any suggestions how to continue this, let me know. The long story short, I tried two web python projects: 1) Pyodide which uses Python3.7 https://github.com/iodide-project/pyodide/ 2) EmCPython which uses Python2.7 https://github.com/PeachPy/EmCPython

For both attempts, I had to modify the CMakeLists.txt from clingo to "disable" cmake to find automatically pre-installed python versions, so it can take the paths given by -DPYTHON_INCLUDE_DIR and -DPYTHON_LIBRARY

For Pyodide, I used Docker as they recommend it to build it. For my old 4GB MacBookPro it took around 20 hours to finish. I was starting to get desperate, but in the end, you get your libpython3.7m.a file.

For EmCPython I followed the instructions, and you get the libpython2.7.a file.

Then, in both cases, the script runs as intended and the progress stops at 96% when Building CXX object libpyclingo/CMakeFiles/libpyclingo.dir/pyclingo.cc.o

Here both failed with two different reasons. Pyodide approach failed

pyodide/cpython/build/3.7.0/host/include/python3.7m/pyport.h:699:2: error: "LONG_BIT definition appears wrong for platform
      (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."

The EmCPython failed because

clingo/libpyclingo/pyclingo.cc:9619:14: error: use of undeclared identifier 'PyEval_ThreadsInitialized'
        if (!PyEval_ThreadsInitialized()) { PyEval_InitThreads(); }
             ^
/Users/flavioeverardo/Documents/PhD/PhDProjects/web-clingo-python/clingo/libpyclingo/pyclingo.cc:9619:45: error: use of undeclared identifier 'PyEval_InitThreads'; did you mean
      'PyEval_SaveThread'?
        if (!PyEval_ThreadsInitialized()) { PyEval_InitThreads(); }

I'm not sure which one would be "easier" to fix. Let me know your thoughts. Any suggestion is highly welcome.