-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python interface #48
Comments
cc #17 |
I am interested in a Python way to use SerAPI. At what stage is this? I have 4 questions/ideas:
|
I have thought a lot about ways to do it well, however not having a Python expert close meant that I moved it down on my priority list. But I am personally very interested in making it happen so I'd be glad to help. First the questions:
Unfortunately not.
Sure, I'd be able to help a lot too!
I see a huge value in having a small Python library that exposes the methods of the protocol; the thing is, what'd be the best way to do it. Interfacing Python with SerAPI directly could prove costly. One key goal of SerAPI is to have easy maintenance and some parts of the serialization are heavy. Despite that, I think that a good solution is doable, the two main challenges are:
|
Sounds good! I'm happy to get together to help and chat about the interface/API/design etc. (if thats helpful/useful). As a selfish comment, I am interesting to keeping in mind some of the functionality of TCoq in mind (#109), specially exposing compund tactics and their intermediate proof states. Just leaving this comment here so I don't forget (could be low priority etc). Yes, I do think having Python objects will be useful for the useful. |
That's great!
I'd suggest we start with an example then; please write a small proof script and what you would expect from it. Then, we can first see if the generic protocol can handle it; and if yes, we could see what the most convenient Python interface would be. |
this theorem might be more advance than my knowledge of coq but I had in mind something like this (example from http://geocoq.github.io/GeoCoq/html/GeoCoq.Highschool.midpoint_thales.html):
steps like: |
This is one of the difference with TCoq (that I am aware of). TCoq records the intermediate proof states encountered as opposed to being an API for machine-machine or human-machine interaction (as far as I know). |
Here we'd need a more concrete specification of what you mean by intermediate states. I see that TCoq instruments LTAC in a particular way, however it doesn't instrument proofview so the kind of traces you get would seem to be a bit arbitrary. [I didn't look at tcoq in depth tho] Note that the notion of state is a bit trickier than expected due to the "multi-goal" model of the 8.5+ proof engine. I suggest we start with a very simple example with tactics As for now, SerAPI does allow to get the state before and after |
One idea I had in mind was to try to reimplement something similar to TCoq but with a better-maintained library like SerAPI. Though I think you guys are right. I should think clearly what I want first and then we can discuss. Yes, I will check something simple first and make sure I understand multi-goal tactic systems by reading what you posted. Thanks! Hope to chat soon in the WG. :) |
This PR adds a python interface to the SerAPI protocol using `pythonlib`, which allows to call OCaml functions from Python. Current setup is based on https://github.com/jonathan-laurent/pyml_example , thanks a lot! But a lot more work is needed in order for this to be useful and to adhere to Python conventions. Requires pinning `ppx_python` to commit janestreet/ppx_python@86db99c Closes: #48
This PR adds a python interface to the SerAPI protocol using `pythonlib`, which allows to call OCaml functions from Python. Current setup is based on https://github.com/jonathan-laurent/pyml_example , thanks a lot! But a lot more work is needed in order for this to be useful and to adhere to Python conventions. Requires pinning `ppx_python` to commit janestreet/ppx_python@86db99c Closes: #48
This took some time, but it is currently "solved" by https://github.com/ejgallego/pycoq However, due to toolchain issues, python support has not yet landed in the main branches, so we will keep this issue open until indeed python support is part of an official release. |
We add Python serialization for the complete protocol, modulo the existing issues the current setup seems to work well! Main hiccup was the lack of variants support janestreet/ppx_python#4 , but fortunately it was easy to work around. Thanks to the `ppx_python` team for their quick resolution of issue janestreet/ppx_python#1 which was essential to get this commit working. This PR just takes care of the serialization, main Python support is done now in https://github.com/ejgallego/pycoq Thus, this PR closes #48
@ejgallego how is that different from this version of pycoq? https://github.com/IBM/pycoq |
Hey @brando90 ; oh, I totally missed that project when doing some search ; maybe I saw it back in March when I started PyCoq' :S would be helpful if people would add their tools to https://github.com/ejgallego/coq-serapi#clients-and-users so we keep track of them and can coordinate. From a technical point of view, the projects are very different, IBM's PyCoq relies on serapi to access Coq, and this involves RPC and is not very flexible. Our own PyCoq does instead create a Python |
Thanks for the reply Emilio! A few questions I am curious about (+some comments):
Agreed! Perhaps a better advertisement in the readme would be useful?
I am curious, why are RPCs not flexible? In what ways are they not flexible? Can't they do everything the server (serapi) does? So if it's not flexible would it be because Coq or serapi aren't flexible? Curious to understand (and hopefully these convs help us build a better tool for all of us)
What do you mean by idiomatic here? Like that it looks like "the idioms of python" - pythonic?
This makes sense. I guess the main reason is likely because we are skipping serapi alltogether and talking to coq directly? But perhaps some benchmarking would be nice and perhaps with things like asynchronous code (e.g. python 's asyncio's
Thanks in advance! Hope to try them soon and hopefully provide good feedback. |
You are limited by the RPC interface, in this sense you have several limits: for example, depend on the chosen serialization format; usually, you must serialize full calls to in the RPC, which is very costly, or implement complex call back mechanism, which bring their own gargabe-collection issues. Also, you depend on the public RPC interface, so if the API doesn't suit you, bad luck.
Maybe! If you have any suggestion please submit a PR!
See for example issue ejgallego/pycoq#4 Indeed, it would be nice if we could generate a better object interface than the current, low level one.
We are replacing printing and parsing for direct object serialization, you can bench, but it is for sure faster. Looking forward to feedback! |
I am curious, why is it faster? I guess I am still struggling to form a model of how this is different from RPCs. Both have to eventually or somehow parse Coq - no?
:) |
We don't parse the protocol when using the non-RPC model, we build a Python object in direct style, using https://github.com/thierry-martinez/pyml , so that's faster and way more flexible in terms of sharing and delaying serialization. Some people is really sending huge objects, and they reported parsing / printing as an slowdown. |
as a side comment, my understanding is that ibm pycoq uses serapi as a backend but it's possible to change ithe backend to this pycoq too, so perhaps they aren't competing tools but rather complementary. The name clashing is rather unfortunate though. |
SerAPI is now replaced by |
We should provide a Python binding for SerAPI as this is what many people actually use.
In principle, we should have a
doc
object, withadd
andcancel
methods, as well as acoqObject
one with the proper subclasses.I am not sure what is the best way to proceed here, I guess some help from Python experts would be welcome.
The text was updated successfully, but these errors were encountered: