Skip to content

Commit 6cd6db8

Browse files
committed
Added generalization for code2inv
1 parent 637225c commit 6cd6db8

File tree

1,311 files changed

+74163
-30821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,311 files changed

+74163
-30821
lines changed

README.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
# Environment Setup
33

44
## Basic Setup
5-
- python-2.7
5+
The following are needed for running the basic setup
6+
- python-3.7
67
- PyTorch 0.4.0
78
- python library: numpy, tqdm, pyparsing
89
- gcc/g++ 5.4.0 (or higher)
10+
- clang-7
911
- make, cmake
1012

1113
## Z3 Setup
1214
code2inv uses the Z3 theorem prover to verify the correctness of generated loop invariants. Follow these steps to build Z3:
13-
1415
1. Clone the source code of Z3 from https://github.com/Z3Prover/z3
15-
2. Run ```python scripts/mk_make.py --prefix /usr/local/; cd build; make -j16; make install ```
16+
2. Run ```git checkout tags/z3-4.8.7; python scripts/mk_make.py --prefix=<installation_prefix> --python --pypkgdir=<python_site_package_directory>; cd build; make; make install```
1617

17-
Remember to set environment variables DYLD_LIBRARY_PATH and PYTHONPATH to contain paths for Z3 shared libraries and Z3Py, respectively. These paths will be indicated upon successful installation of Z3.
18+
Remember to set environment variables LD_LIBRARY_PATH and PYTHONPATH to contain paths for Z3 shared libraries and Z3Py, respectively. These paths will be indicated upon successful installation of Z3.
1819

1920
## Frontend Setup (Optional)
20-
The frontend is used to extract program graphs and verification conditions (VCs) from the input C programs. The program graphs and VCs for our benchmarks are already included in the `benchmarks` directory. To build the frontend, follow the instructions in README in `clang-fe`.
21+
There are two frontends, one each for the C and CHC instances. The C frontend is called clang-fe and can be found in the `clang-fe/` directory. The CHC frontend is called chc-fe and is located in the `chc-fe/` directory.
22+
23+
The `clang-fe` frontend is used to extract program graphs and verification conditions (VCs) from the input C programs. The program graphs and VCs for our benchmarks are already included in the `benchmarks/C_instances` directory and the same for the Non Linear benchmarks are included in the `benchmarks/nl-bench/` directory. To build the frontend, follow the instructions in README in `clang-fe`.
2124

25+
The `chc-fe` frontend is used to extract program graphs from the input CHC programs (the CHC constraints themselves serve as the verification conditions (VCs)). The graphs and the VCs are already included in the `benchmarks/CHC_instances` directory. To run the CHC frontend, follow the instructions in README in `chc-fe`.
2226

2327
# Experiments
2428

@@ -30,41 +34,48 @@ Install the dev version of this package:
3034

3135
## Running as an out-of-the-box solver
3236

33-
```cd code2inv/prog_generator```, then directly run the script ```./run_solver.sh```
37+
```cd code2inv/prog_generator```, then directly run the script ```./run_solver_file.sh <graph_file.json> <vc_file> <specification_file>```.
38+
39+
Eg- `./run_solver_file.sh ../../benchmarks/C_instances/c_graph/101.c.json ../../benchmarks/C_instances/c_smt2/101.c.smt specs/c_spec`
3440

35-
To modify the script ```run_solver.sh```:
41+
Eg- `./run_solver_file.sh ../../benchmarks/CHC_instances/sygus-constraints-graphs/sygus-bench-101.c.smt.json ../../benchmarks/CHC_instances/sygus-constraints/sygus-bench-101.c.smt specs/chc_spec`
3642

37-
1. Set the ```data_folder``` option to the code folder that contains folders ```graph/``` and ```smt2/``` which are created by the front-end pre-processor
38-
2. Set the ```file_list``` option to the file that contains a list of code names. See ```code2inv/benchmarks/names.txt``` as an example.
39-
3. Set the ```single_sample``` option to be the index of code where you want to find the loopinv for.
40-
4. Adjust other parameters if necessary. Make sure to change parameters like ```max_and, max_or, max_depth, list_op``` to make sure the loopinv space is large enough (but not too large).
43+
The specification file is a file as such:
44+
45+
```
46+
name_of_inv_grammar
47+
name_of_solver_script (in the format of a python package)
48+
var_format (ssa if graph has variables in the ssa format, leave blank if not)
49+
```
50+
51+
Refer to the spec files in `spec/` directory as an example
4152

4253
## Running with pretraining and fine-tuning
4354

4455
### Pretraining:
4556

4657
```cd code2inv/prog_generator```
4758
Then run:
48-
```./pretraining.sh ${dataset} ${prog_idx} ${agg_check}```
59+
```./pretraining.sh ${dataset} ${prog_idx} ${agg_check} ${grammar_file}```
4960
where ```dataset``` is the data name, ```prog_idx``` stands for the set of random perturbed programs, and ```agg_check``` can be 0 or 1, denoting whether more aggressive checker should be used.
5061

5162
### Fine-tuning:
5263
```cd code2inv/prog_generator```
5364
Then run:
54-
```./fine_tuning.sh ${dataset} ${prog_idx} ${agg_check} ${init_epoch}```
55-
where the last argument ```init_epoch``` stands for the model dump of corresponding epoch.
65+
```./fine_tuning.sh ${dataset} ${prog_idx} ${agg_check} ${init_epoch} ${grammar_file}```
66+
where the penultimate argument ```init_epoch``` stands for the model dump of corresponding epoch (`latest` for the latest epoch dumped).
5667

5768

5869

5970

60-
# Reference
71+
<!-- # Reference
6172
6273
@inproceedings{si2018nips,
6374
author = {Si, Xujie and Dai, Hanjun and Raghothaman, Mukund and Naik, Mayur and Song, Le},
6475
title = {Learning Loop Invariants for Program Verification.},
6576
year = {2018},
6677
booktitle = {Advances in Neural Information Processing Systems (NeurIPS)},
6778
}
68-
79+
-->
6980

7081

0 commit comments

Comments
 (0)