Git Product home page Git Product logo

pygus's Introduction

PyGuS

Simple interpreter for SyGuS-based program synthesis in Python

Motivation

SyGuS is a popular standard for formulating and solving constraints in the SMT language, and there are many state-of-art open source SMT solvers, such as CVC5. Although many solvers do provide APIs to facilitate specifying constraints in popular programming langauges, including C++, Java, Python, they do not provide a way to translate the SyGuS synthesized programs from the SMT language back into directly executable code.

PyGuS is a simple tool that makes use of CVC5's python API to specify and solve SMT queries, and contains an SMT interpreter that translates the resulting SMT function back into directly exectuable python code. This allows users to write constraints for their functions in Python, and get the desired functions back in Python, using the state-of-art solvers for end-to-end program synthesis without leaving Python land.

How to use

The test files in /tests directory provides an example usage of PyGuS. The constraint specification and solving use CVC5's APIs. The interpret_smt function translates a SyGuS-synthesized function into a Python function definition. Lastly, the resulting SyGuS functions are written to the smt_output directory, and the Python functions are written to the py_output output directory.

To see PyGuS at play, first make sure the Python path is set properly:

export PYTHONPATH="${PYTHONPATH}:path-to-local-pygus-directory"

Then, temporarily remove the output files:

rm tests/smt_output/*.smt
rm tests/py_output/*.py

Now, run the tests and see that they properly re-populate the output files:

python tests/test1.py
python tests/test2.py
python tests/test3.py

pygus's People

Stargazers

 avatar  avatar

Watchers

 avatar

pygus's Issues

ValueError: Token('LP', '(')

I'm trying a simple example with PyGuS and Python 3.11.4. This script:

from interpret.smt_interpreter import interpret_smt

syg = '''(
(define-fun f ((color Int) (sortAsc Int) (sortDesc Int)) Int (ite (<= 1 sortAsc) (ite (<= 1 sortDesc) 0 2) 3))
)'''

print(interpret_smt(syg))

produces this error:

  File "/home/paul/cvc5/PyGuS/main.py", line 7, in <module>
    print(interpret_smt(syg))
          ^^^^^^^^^^^^^^^^^^
  File "/home/paul/cvc5/PyGuS/interpret/smt_interpreter.py", line 12, in interpret_smt
    python_prog = parser.parse(tokens).eval()
                  ^^^^^^^^^^^^^^^^^^^^
  File "/home/paul/cvc5/PyGuS/.venv/lib/python3.11/site-packages/rply/parser.py", line 60, in parse
    self.error_handler(lookahead)
  File "/home/paul/cvc5/PyGuS/interpret/smt_parser.py", line 65, in error_handle
    raise ValueError(tks)
ValueError: Token('LP', '(')

The SyGuS string I'm using was produced by CLI version of cvc5.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.