The Boolean circuit simplification problem involves finding a smaller circuit that computes the same function as a given Boolean circuit. This problem is closely related to several key areas with both theoretical and practical applications, such as logic synthesis, satisfiability, and verification.
In the paper, we introduce a new tool for simplifying Boolean circuits. The tool optimizes subcircuits with three inputs and at most three outputs, seeking to improve each one. It is designed as a low-effort method that runs in just a few seconds for circuits of reasonable size. This efficiency is achieved by combining two key strategies. First, the tool utilizes a precomputed database of optimized circuits, generated with SAT solvers after carefully clustering Boolean functions with three inputs and up to three outputs. Second, we demonstrate that it is sufficient to check a linear number of subcircuits, relative to the size of the original circuit. This allows a single iteration of the tool to be executed in linear time.
This artifact contains the paper and the tool together with detailed instructions on how to run the tool and reproduce the results from the paper.
The tool was evaluated on a wide range of Boolean circuits, including both industrial and hand-crafted examples, in two popular bases: AIG and BENCH. For AIG circuits, after applying the state-of-the-art ABC framework, the tool achieved an additional 4% average reduction in size. For BENCH circuits, the tool reduced their size by an average of 30%.
We pretend to achieve Functional, Reusable, and Available badges.
The Simplify tool is available both at GitHub repository https://github.com/SPbSAT/circuitsat_tool, and at Zenodo:
The Simplify tool is ready to be used on the TACAS 2023 Artifact Evaluation Virtual Machine https://zenodo.org/records/7113223 (for more details see sections Environment configuration and Technical info). It requires no additional proprietary software, or specific hardware (any moderately modern computer should do).
The rest of this README contains following sections:
- Early light review section provides a guideline on performing a light review of a tool.
- Environment configuration section contains instructions on installation of requirements.
- Usage instruction section contains instructions on how Simplify tool can be used.
- Main results reproduction provides guidelines on how experiment results presented in the paper can be reproduced.
- Technical info provides some specific technical details, irrelevant for the paper, but still giving additional information on the tool itself.
Each guideline section provides two paths: "all-in-one" command to complete section and "step-by-step" guide to allow one to evaluate process in details. Note that instructions in this README are given for the default Ubuntu shell and may not work in other environment.
Partial results suitable for light review can be produced in following steps:
-
Configure environment using "all-in-one" command (note that C++ sources may take quite a long time to compile):
# ABC tool (cd third_party/abc/ && make ABC_USE_NO_READLINE=1) # The simplify tool cmake -B build/ -DCMAKE_BUILD_TYPE=RELEASE cmake --build build/ --config RELEASE # Install python dependencies globally pip3 install tools/dependencies/*
-
The Table 3 is quite easily reproducible, so if there is a need to check that tool works at all, one can execute following command (which is a copy of command in relevant section below):
mkdir experiment_table_3 tar -xvf ./benchmark/representative_benchmarks.tar.xz -C ./experiment_table_3/ python3.10 tools/cli abc-resyn2 -i experiment_table_3/benchmarks/ -o experiment_table_3/benchmarks_r/ -a third_party/abc/abc -n 1 -s experiment_table_3/r_results.csv ./build/simplify -i experiment_table_3/benchmarks_r/resyn2_1/ -o experiment_table_3/benchmarks_rs/ -s experiment_table_3/rs_result.csv --basis AIG --databases databases/ python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks -s experiment_table_3/benchmark_sizes.csv python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_r/resyn2_1 -s experiment_table_3/benchmark_r_sizes.csv python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_rs -s experiment_table_3/benchmark_rs_sizes.csv python3.10 tools/cli table-3-finalizer -e experiment_table_3/
-
The Table 4 allows one to select an arbitrary subset of classes to reproduce results, for example following commands should give results in appropriate time:
mkdir light_review_table_4 tar -xvf ./benchmark/bench_for_stat.tar.xz -C ./light_review_table_4/ ./build/simplify -i light_review_table_4/benchmarks/php/ -o light_review_table_4/benchmarks_s/php/ -s light_review_table_4/php_result.csv --basis BENCH --databases databases/ ./build/simplify -i light_review_table_4/benchmarks/mult_miter/ -o light_review_table_4/benchmarks_s/mult_miter/ -s light_review_table_4/mult_miter_result.csv --basis BENCH --databases databases/ python3.10 tools/cli table-4-finalizer -e light_review_table_4/
Before conducting any executions of the tool, it is necessary to perform a mandatory environment configuration. The tool itself requires only to be compiled, whilst experiments framework requires access to the ABC tool executable and python environment for the utility scripts.
As a result of configuration steps of this section one should have:
- Installed additional Ubuntu dependencies;
- Installed
python
packages. - Compiled
simplify
executable located atbuild/simplify
; - Compiled
ABC
executable located atthird_party/abc/abc
;
In the other sections of this README it will be assumed, that all shell commands are executed
in the environment with python dependencies, with abc
and simplify
executables available at
the paths specified above.
# ABC tool
(cd third_party/abc/ && make ABC_USE_NO_READLINE=1)
# The simplify tool
cmake -B build/ -DCMAKE_BUILD_TYPE=RELEASE
cmake --build build/ --config RELEASE
# Install python dependencies globally
pip3 install tools/dependencies/*
Simplify tool can be compiled using cmake
tool and a standard C++
compiler
(gcc
should do). To build simplify
binary execute following steps:
- Compile
cmake
project using command:cmake -B build/ -DCMAKE_BUILD_TYPE=RELEASE
- Build
simplify
tool executable using command:cmake --build build/ --config RELEASE
(Note that in Release
build wast amount of logs is disabled.
If one need more logs, DEBUG
compilation type may be useful.)
As a result simplify
binary will be built. To get info on how simplify
should be used
execute resulting binary with following command:
build/simplify --help
ABC synthesis tool (and patricullary its resyn2
command) is a state-of-art framework for circuit
synthesis. It is used in the paper as a baseline solution for a circuit simplification, which allows
one to access contribution and novelty of the Simplify tool.
For convenience and reproducibility, specific revision of the ABC synthesis tool is vendored
in the third_party/
directory. To compile it, one need to execute following command:
(cd third_party/abc/ && make ABC_USE_NO_READLINE=1)
(see. original repository for details https://github.com/berkeley-abc/abc).
Python 3.10 is available in the provided virtual machine and is used
for the scripts located in the tools/
directory.
To install additional python dependencies globally execute:
pip3 install tools/dependencies/*
Now you should be able to run CLI of tools. Try to use python3.10 tools/cli --help
to get more info on the available CLI commands.
The Simplify tool provides simplification of boolean circuits provided in
one of two bases: AIG
or BENCH
. To run simplification one should provide
an --input-path
and --output
parameters: first is a path to the directory
with boolean circuits, and second is a path where simplified circuits are to
be stored. Both input and output paths should be directories. Program will
take attempt to read all files in input directory as .bench
circuits. Each
circuit then will be processed by the tool distinctly.
Required basis of input circuits should be specified manually using a --basis
parameter. It will serve as a hint for the tool, which will help it to choose
suitable algorithm.
One also should provide a path to the directory with databases containing
(nearly) optimal circuits with three inputs and three outputs by providing
a --databases
parameter. Note that databases are available at databases/
project's root directory, which is a default value for --databases
.
To store statistics of the simplification process one may additionally specify
a --statistics
parameter, which is a path to location where a *.csv
file
with gathered statistics is to be stored. Note that resulting csv file will use
a ,
character as a delimiter, whilst ;
character may be a valid item value.
Example usage command:
./build/simplify -i input_circuit/ -o result_circuits/ -s statistics.csv
Experiments reproduction guidelines in this section provide following set of information:
- Name of a subsection represents a name of the corresponding table in the paper;
- Both "all-in-one" command to run, and a "step-by-step" guide on how results are computed;
- Description of resulting artifacts and their mappings to results in the paper.
All instructions presented below carry results of main intermediate steps. To validate
correctness any stage of simplification, one may use utility CLI command check-equiv
:
python3.10 tools/cli check-equiv --help
Statistics is written in .csv
files with ,
delimiter. Note that in some data ;
is used in a value part.
Circuit sizes for AIG
based tables are given as number of AND
gates, while for the
BENCH
based tables size is represented by total number of gates excluding INPUT
gates.
Final steps of main results reproduction guidelines print main results to the stdout
and save results a file which name pattern is final_results*.csv
Table 1 humbly represents a distribution of circuit sizes, contained in the database of (nearly) optimal circuits. This database contains all possible circuits on three inputs and three outputs, and their particular counts can be reproduced by executing a specialized tool and are not part of the main statistical result of the paper.
Table 2. Comparison of several runs of resyn2 against several runs of resyn2 followed by a run of simplify.
Note: we are aware that first to columns of sub-table 2 of the Table 2 in the paper are interchanged, and we apologize for that. We have observed it only after paper deadline passed, and we are intended to fix it when paper is accepted for publication.
mkdir experiment_table_2
tar -xvf ./benchmark/all_sets_under_50000_for_stat.tar.xz -C ./experiment_table_2/
python3.10 tools/cli abc-resyn2 -i experiment_table_2/benchmarks/ -o experiment_table_2/benchmarks_r/ -a third_party/abc/abc -n 2 -n 3 -n 6 -s experiment_table_2/r_results.csv
./build/simplify -i experiment_table_2/benchmarks_r/resyn2_2/ -o experiment_table_2/benchmarks_r2_s/ -s experiment_table_2/r2_s_result.csv --basis AIG --databases databases/
./build/simplify -i experiment_table_2/benchmarks_r/resyn2_6/ -o experiment_table_2/benchmarks_r6_s/ -s experiment_table_2/r6_s_result.csv --basis AIG --databases databases/
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks -s experiment_table_2/benchmark_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r/resyn2_3 -s experiment_table_2/benchmark_r3_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r/resyn2_6 -s experiment_table_2/benchmark_r6_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r2_s -s experiment_table_2/benchmark_r2_s_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r6_s -s experiment_table_2/benchmark_r6_s_sizes.csv
python3.10 tools/cli table-2-finalizer -e experiment_table_2/
- Make clean experiment directory:
mkdir experiment_table_2
- Extract
benchmark/all_sets_under_50000_for_stat.tar.xz
to the created directory:
tar -xvf ./benchmark/all_sets_under_50000_for_stat.tar.xz -C ./experiment_table_2/
- Run
ABC
resyn2
on the extracted benchmarks using provided CLI command:
python3.10 tools/cli abc-resyn2 -i experiment_table_2/benchmarks/ -o experiment_table_2/benchmarks_r/ -a third_party/abc/abc -n 2 -n 3 -n 6 -s experiment_table_2/r_results.csv
- Run
simplify
tool on several configurations of resulting circuits:
./build/simplify -i experiment_table_2/benchmarks_r/resyn2_2/ -o experiment_table_2/benchmarks_r2_s/ -s experiment_table_2/r2_s_result.csv --basis AIG --databases databases/
./build/simplify -i experiment_table_2/benchmarks_r/resyn2_6/ -o experiment_table_2/benchmarks_r6_s/ -s experiment_table_2/r6_s_result.csv --basis AIG --databases databases/
- Collect statistics
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks -s experiment_table_2/benchmark_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r/resyn2_3 -s experiment_table_2/benchmark_r3_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r/resyn2_6 -s experiment_table_2/benchmark_r6_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r2_s -s experiment_table_2/benchmark_r2_s_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_2/benchmarks_r6_s -s experiment_table_2/benchmark_r6_s_sizes.csv
- Build final paper-ready statistics
python3.10 tools/cli table-2-finalizer -e experiment_table_2/
After all commands completed, results are located as follows:
final_results_1.csv
andfinal_results_2.csv
which contains final results as it is presented in the paper, in first part and a second part of a table respectfully.r_results.csv
contains statistics onresyn2
running.rX_s_result.csv
contains results ofsimplify
evaluation on the relevant scenarioX
(note that sizes in it are calculated as for BENCH basis).benchmark_*_sizes.csv
contains sizes (measured as number of AND gates) of circuits on different simplification stages.
mkdir experiment_table_3
tar -xvf ./benchmark/representative_benchmarks.tar.xz -C ./experiment_table_3/
python3.10 tools/cli abc-resyn2 -i experiment_table_3/benchmarks/ -o experiment_table_3/benchmarks_r/ -a third_party/abc/abc -n 1 -s experiment_table_3/r_results.csv
./build/simplify -i experiment_table_3/benchmarks_r/resyn2_1/ -o experiment_table_3/benchmarks_rs/ -s experiment_table_3/rs_result.csv --basis AIG --databases databases/
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks -s experiment_table_3/benchmark_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_r/resyn2_1 -s experiment_table_3/benchmark_r_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_rs -s experiment_table_3/benchmark_rs_sizes.csv
python3.10 tools/cli table-3-finalizer -e experiment_table_3/
- Make clean experiment directory:
mkdir experiment_table_3
- Extract
benchmark/representative_benchmarks.tar.xz
to the created directory:
tar -xvf ./benchmark/representative_benchmarks.tar.xz -C ./experiment_table_3/
- Run
ABC
resyn2
on the extracted benchmarks using provided CLI command:
python3.10 tools/cli abc-resyn2 -i experiment_table_3/benchmarks/ -o experiment_table_3/benchmarks_r/ -a third_party/abc/abc -n 1 -s experiment_table_3/r_results.csv
- Run
simplify
tool on resulting circuits:
./build/simplify -i experiment_table_3/benchmarks_r/resyn2_1/ -o experiment_table_3/benchmarks_rs/ -s experiment_table_3/rs_result.csv --basis AIG --databases databases/
- Collect benchmark sizes
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks -s experiment_table_3/benchmark_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_r/resyn2_1 -s experiment_table_3/benchmark_r_sizes.csv
python3.10 tools/cli collect-sizes-aig -i experiment_table_3/benchmarks_rs -s experiment_table_3/benchmark_rs_sizes.csv
- Build final paper-ready statistics
python3.10 tools/cli table-3-finalizer -e experiment_table_3/
After all commands completed, results are located as follows:
final_results.csv
contains final result as it is presented in the paper.r_results.csv
contains statistics onresyn2
execution.rs_result.csv
contains results ofsimplify
evaluation (note that sizes in it are calculated as for BENCH basis).benchmark_sizes.csv
contains information about original circuit sizes.benchmark_r_sizes.csv
contains information about circuit afterresyn2
.benchmark_rs_sizes.csv
contains information about circuit aftersimplify
.
Warning: this command may take extremely long time (several hours on modern computer) to be
executed sequentially, so simplify
executions are parallelized by default. If hardware is
unsuitable for such bends of fate, one can either endure and run the sequential test, or run
benchmarking on only a part of classes, picked randomly and unbiased. Yet, some classes may
take up to nearly two hours to be simplified, so proceed with awareness of it.
mkdir experiment_table_4
tar -xvf ./benchmark/bench_for_stat.tar.xz -C ./experiment_table_4/
./build/simplify -i experiment_table_4/benchmarks/factorization/ -o experiment_table_4/benchmarks_s/factorization/ -s experiment_table_4/factorization_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/ecp/ -o experiment_table_4/benchmarks_s/ecp/ -s experiment_table_4/ecp_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/clique/ -o experiment_table_4/benchmarks_s/clique/ -s experiment_table_4/clique_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/php/ -o experiment_table_4/benchmarks_s/php/ -s experiment_table_4/php_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/I99T/ -o experiment_table_4/benchmarks_s/I99T/ -s experiment_table_4/I99T_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/BristolFashion/ -o experiment_table_4/benchmarks_s/BristolFashion/ -s experiment_table_4/BristolFashion_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_sum/ -o experiment_table_4/benchmarks_s/miter_sum/ -s experiment_table_4/miter_sum_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_thr2/ -o experiment_table_4/benchmarks_s/miter_thr2/ -s experiment_table_4/miter_thr2_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_transalg_sort/ -o experiment_table_4/benchmarks_s/miter_transalg_sort/ -s experiment_table_4/miter_transalg_sort_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/mult_miter/ -o experiment_table_4/benchmarks_s/mult_miter/ -s experiment_table_4/mult_miter_result.csv --basis BENCH --databases databases/ &
wait
python3.10 tools/cli table-4-finalizer -e experiment_table_4/
- Make clean experiment directory:
mkdir experiment_table_4
- Extract
benchmark/bench_for_stat.tar.xz
to the created directory:
tar -xvf ./benchmark/bench_for_stat.tar.xz -C ./experiment_table_4/
- Run
simplify
tool on resulting circuits:
Warning: this command may take extremely long time (several hours on modern computer) to be
executed sequentially, so simplify
executions are parallelized by default. If hardware is
unsuitable for such bends of fate, one can either endure and run the sequential test, or run
benchmarking on only a part of classes, picked randomly and unbiased. Yet, some classes may
take up to nearly two hours to be simplified, so proceed with awareness of it.
./build/simplify -i experiment_table_4/benchmarks/factorization/ -o experiment_table_4/benchmarks_s/factorization/ -s experiment_table_4/factorization_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/ecp/ -o experiment_table_4/benchmarks_s/ecp/ -s experiment_table_4/ecp_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/clique/ -o experiment_table_4/benchmarks_s/clique/ -s experiment_table_4/clique_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/php/ -o experiment_table_4/benchmarks_s/php/ -s experiment_table_4/php_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/I99T/ -o experiment_table_4/benchmarks_s/I99T/ -s experiment_table_4/I99T_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/BristolFashion/ -o experiment_table_4/benchmarks_s/BristolFashion/ -s experiment_table_4/BristolFashion_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_sum/ -o experiment_table_4/benchmarks_s/miter_sum/ -s experiment_table_4/miter_sum_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_thr2/ -o experiment_table_4/benchmarks_s/miter_thr2/ -s experiment_table_4/miter_thr2_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/miter_transalg_sort/ -o experiment_table_4/benchmarks_s/miter_transalg_sort/ -s experiment_table_4/miter_transalg_sort_result.csv --basis BENCH --databases databases/ &
./build/simplify -i experiment_table_4/benchmarks/mult_miter/ -o experiment_table_4/benchmarks_s/mult_miter/ -s experiment_table_4/mult_miter_result.csv --basis BENCH --databases databases/ &
wait
- Build final paper-ready statistics
python3.10 tools/cli table-4-finalizer -e experiment_table_4/
After all commands completed, results are located as follows:
final_results.csv
contains final result as it is presented in the paper.<class>_result.csv
contains results ofsimplify
evaluation to the circuits ofclass
(note that sizes in it are calculated as for BENCH basis).
Main simplify
directory contains following directories:
app/
directory contains compilablesimplify.cpp
file, which contains an entry-point (main
).benchmarks/
directory containstar
archives with boolean circuit benchmarks used for experiments.databases/
directory contains databases of the (nearly) optimal small circuits for BENCH and AIG bases.src/
directory implements main tool functionalities, and organized as a header-only library.tests/
directory implements unit tests for the main functionalities of the tool.third_party/
directory contains third-party libraries, used either for the tool itself (argparse
), code quality checks (GTest
), or for the experiments conduction (ABC
). Those libraries are vendored with the artifact for the completeness and reproducibility.tools/
directory contains CLI utilities useful for experiments and are to be run within rightpython 3.10
environment.
Simplify is written using C++20
, was developed and tested on the Ubuntu OS
equipped with gcc x86-64
compiler, but should not cause any problems on other
common Linux distributions.
Experiment environment of a tool includes additional dependencies such as
ABC tool
and python 3.10
environment.
Simplify tool utilizes external library argparse to ease CLI arguments parsing and usage. Also test framework GoogleTest is used to run unit tests which cover main functionalities of the tool.
To make this artifact whole, argparse
and gtest
repository snapshots are vendored
alongside it and are presented in the third_party/
directory.
Core parts of a code are covered with tests, located at tests/
directory.
Test are written using GTest
framework.
In addition to unit tests, main capabilities of the tool were tested one the wide range of Boolean circuits, both industrial and hand-crafter. Results of simplification were tested for equivalence to the original circuits.
clang-format
and clang-tidy
are used for maintaining code quality.
Note that both of them are used as a part of CI
flow in the linked
GitHub repository, and their execution may be checked there.