-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0 parents
commit de20d3e
Showing
2,647 changed files
with
704,042 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
|
||
# Distribution / packaging | ||
.Python | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
.idea/ | ||
|
||
.vscode/ | ||
**/tree_sitter_lib/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "src/tree_sitter_lib/vendor/tree-sitter-c"] | ||
path = src/tree_sitter_lib/vendor/tree-sitter-c | ||
url = https://github.com/tree-sitter/tree-sitter-c |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Copyright (c) Microsoft Corporation. | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
# Loopy | ||
|
||
## Setup | ||
|
||
### Clone the repository | ||
|
||
```bash | ||
git clone --recursive git@github.com:microsoft/loop-invariant-gen-experiments | ||
``` | ||
|
||
### Without Docker | ||
|
||
#### Install Frama-C | ||
|
||
```bash | ||
# Install opam (OCaml package manager) | ||
sudo apt install opam # or dnf, pacman, etc. | ||
|
||
# Or you can download an opam binary, put it in the PATH | ||
# and run it directly (no sudo required) | ||
|
||
# Initialize opam (install an OCaml compiler) | ||
opam init --compiler 4.14.1 # may take a while | ||
eval $(opam env) | ||
|
||
# Install Frama-C (including dependencies) | ||
opam install frama-c | ||
``` | ||
|
||
#### Install CVC4 | ||
|
||
```bash | ||
# ARCH is one of {x86_64-linux, win64} | ||
wget http://cvc4.cs.stanford.edu/downloads/builds/{ARCH}-opt/cvc4-1.6-{ARCH}-opt | ||
mv cvc4-1.6-{ARCH}-opt cvc4 | ||
# Add cvc4 to your PATH | ||
``` | ||
|
||
#### Install Alt-Ergo | ||
|
||
```bash | ||
opam install alt-ergo | ||
``` | ||
|
||
#### Install Z3 | ||
|
||
```bash | ||
wget wget https://github.com/Z3Prover/z3/releases/download/z3-4.12.2/z3-4.12.2-x64-glibc-2.31.zip | ||
unzip z3-4.12.2-x64-glibc-2.31.zip | ||
ln -s z3-4.12.2-x64-glibc-2.31/bin/z3 | ||
``` | ||
|
||
#### Configure Why3 | ||
|
||
```bash | ||
rm -f ~/.why3.conf | ||
why3 config detect | ||
``` | ||
|
||
#### Install python dependencies | ||
|
||
```bash | ||
# Ensure python version >= 3.11 | ||
# From src/ | ||
pip install -r requirements.txt | ||
``` | ||
|
||
#### Build the tree-sitter-c library | ||
|
||
```bash | ||
cd src/ | ||
python3 build_parser.py | ||
``` | ||
|
||
Depending on how you access the LLM, you can follow the steps in the LLM access section [below](#llm-access). | ||
|
||
### With Docker | ||
|
||
You can use `Dockerfile` in `src` to build a docker image and run it. | ||
|
||
You can build the docker image by running the following commands starting **from the root of this repository**: | ||
(If you get a permission error, you may need to run the following command with `sudo`) | ||
|
||
```bash | ||
cd src/ | ||
docker build -t loopy --build-arg USER_ID=$(id -u) --build-arg GROUP_ID=$(id -g) . | ||
``` | ||
|
||
Once the image is built, you can run it using the following command **from the root of this repository**: | ||
(If you get a permission error, you may need to run the following command with `sudo`) | ||
|
||
```bash | ||
docker run -it --rm \ | ||
--mount type=bind,source="$(pwd)"/data,target=/home/user/data/ \ | ||
--mount type=bind,source="$(pwd)"/config,target=/home/user/config/ \ | ||
--mount type=bind,source="$(pwd)"/experiments,target=/home/user/experiments/ \ | ||
--mount type=bind,source="$(pwd)"/templates,target=/home/user/templates/ \ | ||
--mount type=bind,source="$(pwd)"/logs,target=/home/user/logs/ \ | ||
--user "$(id -u):$(id -g)" \ | ||
-e OPENAI_API_KEY=<API_KEY> \ | ||
-e OPENAI_API_BASE=<API_ENDPOINT> \ | ||
-e OPENAI_API_VERSION=<API_VERSION> \ | ||
loopy /bin/bash | ||
# If you don't need to interact with the Azure OpenAI API, skip the -e CLI options | ||
``` | ||
|
||
### LLM access | ||
|
||
If you are using an Azure OpenAI endpoint, you need to set the following environment variables before running the toolchain: | ||
|
||
```bash | ||
export OPENAI_API_KEY=<your key> | ||
export OPENAI_API_BASE=<your API endpoint> | ||
export OPENAI_API_VERSION=<your API version> | ||
``` | ||
|
||
You should now be able to run the toolchain using the following command: | ||
|
||
```bash | ||
python3 main.py --config-file <YAML_config_file> --max-benchmarks <max_benchmarks> [options] | ||
``` | ||
|
||
If you are using a different endpoint, you will have to implement a wrapper class that inherits `Provider` in `llm_api_client.py`. | ||
See the `AzureOpenAI` class for an example. | ||
|
||
If you are hosting a model locally, you can use a local model inference/serving engine and make HTTP requests to it. You will have to set the `OPENAI_API_BASE` environment variable to the appropriate URL. | ||
|
||
## Usage | ||
|
||
You can run the toolchain using the following command: | ||
|
||
```bash | ||
python3 main.py --config-file <YAML_config_file> --max-benchmarks <max_benchmarks> [options] | ||
``` | ||
|
||
Use `python3 main.py --help` to see the list of available options. | ||
|
||
The YAML configuration file contains the following fields: | ||
|
||
```yaml | ||
checker: <checker_name> # only frama-c is supported for now | ||
checker_timeout: <checker_options> # timeout argument for the checker, in seconds | ||
model: <model_name> # the LLM to use (gpt-4, gpt-4-32k, gpt-3.5-turbo, etc.) | ||
benchmarks: <path_to_benchmarks_file> # this file must contain the list of benchmarks to run, one file path per line | ||
benchmark_features: <features_of_the_benchmarks> # this string should indicate the features of the benchmarks under consideration. | ||
# For e.g., "one_loop_one_method" describes benchmarks with a single loop and a single method. | ||
# Other possible values are "multiple_methods_no_loops", "arrays_pointers_multiple_loops", "termination_one_loop_one_method". | ||
# (If "termination" is specified, variants will be inferred. If "multiple_methods" is specified, pre-post conditions will be inferred). | ||
debug: <debug_mode> # if true, the toolchain will print debug information | ||
``` | ||
See [config/sample_config.yaml](config/sample_config.yaml) for an example of a configuration file. | ||
## Dataset | ||
The dataset of pre-processed benchmarks used in our experiments is available [here](dataset.zip). | ||
Pre-processing involves removing comments, and converting the assertions to ACSL assertions (for Frama-C). | ||
The ZIP file contains the following subdirectories with pre-processed benchmarks: | ||
- `loop_invariants`: Contains numerical benchmarks with one loop and one method. Loop invariants are to be inferred for the loop in each benchmark to prove the assertion(s) in the benchmark. | ||
- `arrays`: Contains benchmarks with arrays, one method and at least one loop. Loop invariants are to be inferred for the loop(s) in each benchmark to prove the assertion(s) in the benchmark. | ||
- `termination`: Contains numerical benchmarks with one loop, one method. A ranking function (and supporting loop invariants if necessary) are to be inferred to prove termination of the loop. | ||
- `recursive_functions`: Contains benchmarks with recursive functions, for which pre-post conditions are to be inferred, to prove the assertion(s) in each benchmark. | ||
|
||
The loop invariants generated by Loopy can be found in the excel sheet [here](GeneratedInvariants.xlsx). This sheet includes the benchmarks that were successfully verified by Loopy. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Configurations | ||
|
||
This folder contains the configuration files to run the experiments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
checker: frama-c | ||
model: gpt-4 | ||
benchmarks: experiments/arrays.txt | ||
benchmark_features: arrays_pointers_multiple_loops | ||
debug: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
checker: frama-c | ||
model: gpt-4-32k | ||
benchmarks: experiments/loop_invariants.txt | ||
benchmark_features: one_loop_one_method | ||
debug: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
checker: frama-c | ||
model: gpt-4 | ||
benchmarks: experiments/recursive_functions.txt | ||
benchmark_features: multiple_methods_no_loops | ||
debug: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
checker: frama-c # only frama-c is supported for now, there is a boogie PoC | ||
checker_timeout: 3 # in seconds | ||
model: gpt-4-32k # gpt-4, gpt-3.5-turbo, codellama-34b-python | ||
benchmarks: experiments/loop_invariants.txt # list of benchmark files | ||
benchmark_features: one_loop_one_method # features of the benchmark. Possible values: {one_loop_one_method, multiple_methods_no_loops, arrays_pointers_multiple_loops, termination_one_loop_one_method} | ||
debug: True # if True, prints debug information |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
checker: frama-c | ||
model: gpt-4-32k | ||
benchmarks: experiments/termination.txt | ||
benchmark_features: termination_one_loop_one_method | ||
debug: True |
Oops, something went wrong.