A pytorch implementation of NeuraSAT(github, paper)
In this implementation, we use SR(U(10, 40)) for training and SR(40) for testing, achieving the same accuracy 85% as in the original paper. The model was trained on a single K40 gpu for ~3 days following the parameters in the original paper.
Before running any experiment scripts, you need to generate the SAT problem instances using the src/data_maker.py script:
python src/data_maker.py <out_dir> <gen_log> <n_pairs> <max_nodes_per_batch> [other options]For example, to generate the SR(40) dataset for testing, you could run something like:
python src/data_maker.py data/val/sr40.pkl data/val/sr40.log 1000 50000 --min_n 40 --max_n 40To generate the SR(U(10, 40)) dataset for training:
python src/data_maker.py data/train/sr10-40.pkl data/train/sr10-40.log 10000 50000 --min_n 10 --max_n 40<out_dir>: Output path for the generated pickle file containing the SAT problems<gen_log>: Path for the generation log file<n_pairs>: Number of SAT problem pairs to generate<max_nodes_per_batch>: Maximum number of nodes per batch--min_nand--max_n: Range of variables in the SAT problems (SR(40) means min_n=max_n=40)--p_k_2and--p_geo: Distribution parameters for clause generation (defaults: 0.3 and 0.4)
You'll also need to generate validation datasets for training scripts. For example:
# Generate validation dataset for SR(40)
python src/data_maker.py data/val/sr40.pkl data/val/sr40.log 1000 50000 --min_n 40 --max_n 40The repository includes several shell scripts for training and evaluating models on different dataset configurations:
run_sr3to10.sh: Trains on SR(3-10) datasetrun_sr10to40.sh: Trains on SR(10-40) datasetrun_sr40to100.sh: Trains on SR(40-100) datasetrun_sr200to500.sh: Trains on SR(200-500) dataset
Each training script performs three steps:
- Generates the required training dataset using
data_maker.py - Generates a validation dataset if it doesn't exist yet
- Runs the training using
src/train.py
The scripts have been configured to automatically create all necessary directories and datasets.
To run a training script (example):
./run_sr10to40.shTo evaluate a trained model on SR(40) dataset, use the run_eval.sh script:
./run_eval.shThis script will first generate an SR(40) dataset specifically for evaluation and then run the evaluation using src/eval.py.