Skip to content

Commit

Permalink
Updates in debugging toolkit (#557)
Browse files Browse the repository at this point in the history
* update interfaces

* update percy

* add nauty

* fix percy (should be ported back)

* restructure fuzzer and generator

* composed

* update examples

* Update fuzz_abc.cpp

* return counter

* improve minimizer

* fix includes and test

* fix docs

* add timeout

* updates

* only compile nauty-dependent part when enabled

* update examples

* remove WIP

* fix naming error

* generators can't be const bc they have states

* naming inconsistency

* fix windows error
  • Loading branch information
lee30sonia authored Jul 9, 2022
1 parent bc24b33 commit 6546a1d
Show file tree
Hide file tree
Showing 150 changed files with 291,767 additions and 624 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option(MOCKTURTLE_EXPERIMENTS "Build experiments" OFF)
option(BILL_Z3 "Enable Z3 interface for bill library" OFF)
option(ENABLE_COVERAGE "Enable coverage reporting for gcc/clang" OFF)
option(ENABLE_MATPLOTLIB "Enable matplotlib library in experiments" OFF)
option(ENABLE_NAUTY "Enable the Nauty library for percy" OFF)

if(UNIX)
# show quite some warnings (but remove some intentionally)
Expand All @@ -30,10 +31,17 @@ endif()
if(MSVC)
add_compile_options(/EHsc /bigobj)
endif()
if (WIN32)
set(ENABLE_NAUTY OFF)
endif()

add_subdirectory(include)
add_subdirectory(lib)

if(ENABLE_NAUTY)
add_definitions(-DENABLE_NAUTY)
endif()

if(MOCKTURTLE_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down
43 changes: 34 additions & 9 deletions examples/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,56 @@

#include <mockturtle/networks/aig.hpp>
#include <mockturtle/io/aiger_reader.hpp>
#include <mockturtle/io/verilog_reader.hpp>
#include <mockturtle/io/write_dot.hpp>
#include <lorina/aiger.hpp>
#include <lorina/verilog.hpp>
#include <fmt/format.h>

using namespace mockturtle;

int main( int argc, char* argv[] )
{
if( argc != 2 )
{
std::cout << "Please give exactly one argument, which is the AIG file to be visualized\n";
std::cout << "For example: ./draw test.aig\n";
std::cout << "[e] Please give exactly one argument, which is the AIGER or Verilog file to be visualized\n";
std::cout << " For example: ./draw test.aig\n";
return -1;
}

aig_network aig;
if ( lorina::read_aiger( argv[1], aiger_reader( aig ) ) != lorina::return_code::success )
std::string filename( argv[1] );
std::string filename_trimed;
aig_network ntk;

if ( filename.size() > 2 && filename.substr( filename.size() - 2, 2 ) == ".v" )
{
filename_trimed = filename.substr( 0, filename.size() - 2 );
if ( lorina::read_verilog( filename, verilog_reader( ntk ) ) != lorina::return_code::success )
{
fmt::print( "[e] Could not read input file `{}`\n", filename );
return -1;
}
}
else if ( filename.size() > 4 && filename.substr( filename.size() - 4, 4 ) == ".aig" )
{
filename_trimed = filename.substr( 0, filename.size() - 4 );
if ( lorina::read_aiger( filename, aiger_reader( ntk ) ) != lorina::return_code::success )
{
fmt::print( "[e] Could not read input file `{}`\n", filename );
return -1;
}
}
else
{
std::cout << "[e] couldn't read input file\n";
std::cout << "[e] Argument does not end with `.aig` or `.v`\n";
std::cout << "[i] Usage: ./draw [AIGER or Verilog filename]\n";
return -1;
}

write_dot( aig, std::string( argv[1] ) + ".dot" );
std::system( std::string( "dot -Tpng -O " + std::string( argv[1] ) + ".dot" ).c_str() );
std::system( std::string( "rm " + std::string( argv[1] ) + ".dot" ).c_str() );
std::system( std::string( "open " + std::string( argv[1] ) + ".dot.png" ).c_str() );
write_dot( ntk, filename_trimed + ".dot" );
std::system( fmt::format( "dot -Tpng -o {}.png {}.dot", filename_trimed, filename_trimed ).c_str() );
std::system( fmt::format( "rm {}.dot", filename_trimed ).c_str() );
std::system( fmt::format( "open {}.png", filename_trimed ).c_str() );

return 0;
}
59 changes: 32 additions & 27 deletions examples/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
#include <mockturtle/algorithms/cleanup.hpp>
#include <mockturtle/networks/aig.hpp>
#include <mockturtle/views/color_view.hpp>
#include <mockturtle/utils/debugging_utils.hpp>

// algorithm under test
#include <mockturtle/algorithms/cut_rewriting.hpp>
#include <mockturtle/algorithms/node_resynthesis/xag_npn.hpp>
#include <mockturtle/algorithms/aig_resub.hpp>
#include <mockturtle/algorithms/resubstitution.hpp>

// fuzzer
#include <mockturtle/utils/debugging_utils.hpp>
#include <mockturtle/algorithms/network_fuzz_tester.hpp>
#include <mockturtle/generators/random_logic_generator.hpp>
#include <lorina/lorina.hpp>
#include <mockturtle/generators/random_network.hpp>

// cec
#include <mockturtle/algorithms/equivalence_checking.hpp>
Expand All @@ -24,31 +23,37 @@ using namespace mockturtle;

int main()
{
xag_npn_resynthesis<aig_network> resyn;
auto opt = [&]( aig_network aig ) -> bool {
aig_network const aig_copy = cleanup_dangling( aig );

cut_rewriting_params ps;
ps.cut_enumeration_ps.cut_size = 4;
aig = cut_rewriting( aig, resyn, ps );

color_view caig{aig};
if ( !network_is_acyclic( caig ) )
return false;

return *equivalence_checking( *miter<aig_network>( aig_copy, aig ) );
aig_network const aig_copy = aig.clone();

resubstitution_params ps;
ps.max_pis = 8u;
ps.max_inserts = 5u;
aig_resubstitution( aig, ps );
aig = cleanup_dangling( aig );

bool const cec = *equivalence_checking( *miter<aig_network>( aig_copy, aig ) );
if ( !cec )
std::cout << "Optimized network is not equivalent to the original one!\n";
return cec;
};

fuzz_tester_params ps;
ps.num_iterations_step = 1000;
ps.num_pis_max = 100;
ps.num_gates_max = 1000;
ps.file_format = fuzz_tester_params::aiger;
ps.filename = "fuzz.aig";

auto gen = default_random_aig_generator();
network_fuzz_tester<aig_network, decltype(gen)> fuzzer( gen, ps );
fuzzer.run_incremental( opt );
#ifdef ENABLE_NAUTY
random_network_generator_params_composed ps_gen;
std::cout << "[i] fuzzer: using the \"composed topologies\" generator\n";
#else
random_network_generator_params_size ps_gen;
ps_gen.num_gates = 30;
std::cout << "[i] fuzzer: using the default (random) generator\n";
#endif
auto gen = random_aig_generator( ps_gen );

fuzz_tester_params ps_fuzz;
ps_fuzz.file_format = fuzz_tester_params::aiger;
ps_fuzz.filename = "fuzz.aig";

network_fuzz_tester<aig_network, decltype(gen)> fuzzer( gen, ps_fuzz );
fuzzer.run( opt );

return 0;
}
28 changes: 18 additions & 10 deletions examples/fuzz_abc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <mockturtle/networks/aig.hpp>
#include <mockturtle/algorithms/network_fuzz_tester.hpp>
#include <mockturtle/generators/random_logic_generator.hpp>
#include <mockturtle/generators/random_network.hpp>

using namespace mockturtle;

Expand All @@ -20,19 +20,27 @@ int main( int argc, char* argv[] )
return -1;
}

std::string commands( argv[1] );
auto fn = [&]( std::string const& filename ) -> std::string {
return "abc -c \"read " + filename + "; " + std::string( argv[1] ) + "; write fuzz_opt.aig\"";
return "abc -c \"read " + filename + "; " + commands + "; write fuzz_opt.aig\"";
};

fuzz_tester_params ps;
ps.num_gates_max = 500;
ps.file_format = fuzz_tester_params::aiger;
ps.filename = "fuzz.aig";
ps.outputfile = "fuzz_opt.aig";
#ifdef ENABLE_NAUTY
random_network_generator_params_composed ps_gen;
std::cout << "[i] fuzzer: using the \"composed topologies\" generator\n";
#else
random_network_generator_params_size ps_gen;
std::cout << "[i] fuzzer: using the default (random) generator\n";
#endif
auto gen = random_aig_generator( ps_gen );

fuzz_tester_params ps_fuzz;
ps_fuzz.file_format = fuzz_tester_params::aiger;
ps_fuzz.filename = "fuzz.aig";
ps_fuzz.outputfile = "fuzz_opt.aig";

auto gen = default_random_aig_generator();
network_fuzz_tester<aig_network, decltype(gen)> fuzzer( gen, ps );
fuzzer.run_incremental( fn );
network_fuzz_tester<aig_network, decltype(gen)> fuzzer( gen, ps_fuzz );
fuzzer.run( fn );
#endif

return 0;
Expand Down
25 changes: 17 additions & 8 deletions examples/minimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
*/

#include <mockturtle/networks/aig.hpp>
#include <mockturtle/algorithms/sim_resub.hpp>
#include <mockturtle/algorithms/testcase_minimizer.hpp>
#include <mockturtle/utils/debugging_utils.hpp>
#include <mockturtle/views/color_view.hpp>
#include <mockturtle/algorithms/equivalence_checking.hpp>
#include <mockturtle/algorithms/miter.hpp>

// algorithm under test
#include <mockturtle/algorithms/aig_resub.hpp>
#include <mockturtle/algorithms/resubstitution.hpp>

// minimizer
#include <mockturtle/algorithms/testcase_minimizer.hpp>

using namespace mockturtle;

Expand All @@ -20,13 +27,16 @@ int main( int argc, char* argv[] )
}

/* Use this lambda function for debugging mockturtle algorithms */
auto opt = []( aig_network aig ) -> bool {
auto opt = [&]( aig_network aig ) -> bool {
aig_network const aig_copy = aig.clone();

resubstitution_params ps;
ps.max_pis = 100;
ps.max_inserts = 20u;
ps.max_pis = 8u;
ps.max_inserts = 5u;
aig_resubstitution( aig, ps );
aig = cleanup_dangling( aig );

sim_resubstitution( aig, ps );
return !network_is_acyclic( color_view{aig} ); // return true if buggy
return *equivalence_checking( *miter<aig_network>( aig_copy, aig ) ); // true: normal (or not the expected bug); false: buggy
};

/* Use this lambda function for debugging external tools or algorithms that segfaults */
Expand All @@ -40,7 +50,6 @@ int main( int argc, char* argv[] )
ps.path = "."; // current directory
ps.init_case = std::string( argv[1] );
ps.minimized_case = ps.init_case + "_minimized";
ps.max_size = 0;
ps.verbose = true;
testcase_minimizer<aig_network> minimizer( ps );
minimizer.run( opt );
Expand Down
6 changes: 3 additions & 3 deletions include/mockturtle/algorithms/balancing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ struct balancing_impl
const auto aig = ...;
sop_balancing<aig_network> balance_fn;
balance_params ps;
sop_rebalancing<aig_network> balance_fn;
balancing_params ps;
ps.cut_enumeration_ps.cut_size = 6u;
const auto balanced_aig = balance( aig, {balance_fn}, ps );
const auto balanced_aig = balancing( aig, {balance_fn}, ps );
\endverbatim
*/
template<class Ntk, class CostFn = unit_cost<Ntk>>
Expand Down
Loading

0 comments on commit 6546a1d

Please sign in to comment.