From 788664099e6c460f4d3299e393fdd62bbc806926 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 09:27:26 +0100 Subject: [PATCH 01/40] random traces: set random initial state Instead of relying on the user to initialize the state, we use random constraints. --- .../ebmc/random-traces/initial_state1.desc | 10 ++ .../ebmc/random-traces/initial_state1.v | 12 ++ src/ebmc/random_traces.cpp | 163 ++++++++++++++++-- 3 files changed, 166 insertions(+), 19 deletions(-) create mode 100644 regression/ebmc/random-traces/initial_state1.desc create mode 100644 regression/ebmc/random-traces/initial_state1.v diff --git a/regression/ebmc/random-traces/initial_state1.desc b/regression/ebmc/random-traces/initial_state1.desc new file mode 100644 index 000000000..4491baa03 --- /dev/null +++ b/regression/ebmc/random-traces/initial_state1.desc @@ -0,0 +1,10 @@ +CORE +initial_state1.v +--random-trace --trace-steps 1 --numbered-trace +^m\.x@0 = 'hBF9059EA$ +^m\.y@0 = 123$ +^m\.x@1 = 'hBF9059EB$ +^m\.y@1 = 124$ +^EXIT=0$ +^SIGNAL=0$ +-- diff --git a/regression/ebmc/random-traces/initial_state1.v b/regression/ebmc/random-traces/initial_state1.v new file mode 100644 index 000000000..08d0c69b5 --- /dev/null +++ b/regression/ebmc/random-traces/initial_state1.v @@ -0,0 +1,12 @@ +module m(input clk); + + // x is unconstrained + reg [31:0] x; + always @(posedge clk) x = x + 1; + + // y is constrained + reg [31:0] y; + always @(posedge clk) y = y + 1; + initial y = 123; + +endmodule diff --git a/src/ebmc/random_traces.cpp b/src/ebmc/random_traces.cpp index 3516c3a4e..328aad220 100644 --- a/src/ebmc/random_traces.cpp +++ b/src/ebmc/random_traces.cpp @@ -12,6 +12,7 @@ Author: Daniel Kroening, kroening@kroening.com #include #include #include +#include #include #include @@ -59,21 +60,35 @@ class random_tracest const namespacet ns; messaget message; - using inputst = std::vector; + using symbolst = std::vector; std::vector random_input_constraints( decision_proceduret &, - const inputst &, + const symbolst &inputs, size_t number_of_timeframes); + std::vector random_initial_state_constraints( + decision_proceduret &, + const symbolst &state_variables); + + static std::vector + merge_constraints(const std::vector &a, const std::vector &b) + { + std::vector result; + result.reserve(a.size() + b.size()); + result.insert(result.end(), a.begin(), a.end()); + result.insert(result.end(), b.begin(), b.end()); + return result; + } + constant_exprt random_value(const typet &); - inputst inputs() const; + symbolst inputs() const; + symbolst state_variables() const; + symbolst remove_constrained(const symbolst &) const; - void freeze_inputs( - const inputst &, - std::size_t number_of_timeframes, - boolbvt &) const; + void + freeze(const symbolst &, std::size_t number_of_timeframes, boolbvt &) const; // Random number generator. These are fully specified in // the C++ standard, and produce the same values on compliant @@ -261,10 +276,15 @@ int random_trace(const cmdlinet &cmdline, message_handlert &message_handler) auto consumer = [&](trans_tracet trace) -> void { namespacet ns(transition_system.symbol_table); - if(cmdline.isset("random-waveform")) + if(cmdline.isset("random-waveform") || cmdline.isset("waveform")) { show_waveform(trace, ns); } + else if(cmdline.isset("numbered-trace")) + { + messaget message(message_handler); + show_trans_trace_numbered(trace, message, ns, consolet::out()); + } else // default { messaget message(message_handler); @@ -406,9 +426,9 @@ Function: random_tracest::inputs \*******************************************************************/ -random_tracest::inputst random_tracest::inputs() const +random_tracest::symbolst random_tracest::inputs() const { - inputst inputs; + symbolst inputs; const auto &module_symbol = *transition_system.main_symbol; @@ -435,7 +455,7 @@ random_tracest::inputst random_tracest::inputs() const /*******************************************************************\ -Function: random_tracest::freeze_inputs +Function: random_tracest::state_variables Inputs: @@ -445,17 +465,81 @@ Function: random_tracest::freeze_inputs \*******************************************************************/ -void random_tracest::freeze_inputs( - const inputst &inputs, +random_tracest::symbolst random_tracest::state_variables() const +{ + symbolst state_variables; + + const auto &module_symbol = *transition_system.main_symbol; + const namespacet ns(transition_system.symbol_table); + + const auto &symbol_module_map = + transition_system.symbol_table.symbol_module_map; + auto lower = symbol_module_map.lower_bound(module_symbol.name); + auto upper = symbol_module_map.upper_bound(module_symbol.name); + + for(auto it = lower; it != upper; it++) + { + const symbolt &symbol = ns.lookup(it->second); + + if(symbol.is_state_var) + state_variables.push_back(symbol.symbol_expr()); + } + + return state_variables; +} + +/*******************************************************************\ + +Function: random_tracest::remove_constrained + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + +random_tracest::symbolst +random_tracest::remove_constrained(const symbolst &symbols) const +{ + auto constrained_symbols = find_symbols(transition_system.trans_expr.init()); + + symbolst result; + result.reserve(symbols.size()); + + // this is symbols setminus constrained_symbols + for(auto &symbol : symbols) + if(constrained_symbols.find(symbol) == constrained_symbols.end()) + result.push_back(symbol); + + return result; +} + +/*******************************************************************\ + +Function: random_tracest::freeze + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + +void random_tracest::freeze( + const symbolst &symbols, std::size_t number_of_timeframes, boolbvt &boolbv) const { for(std::size_t i = 0; i < number_of_timeframes; i++) { - for(auto &input : inputs) + for(auto &symbol : symbols) { - auto input_in_timeframe = instantiate(input, i, number_of_timeframes, ns); - boolbv.set_frozen(boolbv.convert_bv(input_in_timeframe)); + auto symbol_in_timeframe = + instantiate(symbol, i, number_of_timeframes, ns); + boolbv.set_frozen(boolbv.convert_bv(symbol_in_timeframe)); } } } @@ -495,6 +579,35 @@ std::vector random_tracest::random_input_constraints( /*******************************************************************\ +Function: random_tracest::random_initial_state_constraints + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + +std::vector random_tracest::random_initial_state_constraints( + decision_proceduret &solver, + const symbolst &state_variables) +{ + std::vector result; + + for(auto &symbol : state_variables) + { + auto symbol_in_timeframe = instantiate(symbol, 0, 1, ns); + auto constraint = + equal_exprt(symbol_in_timeframe, random_value(symbol.type())); + result.push_back(constraint); + } + + return result; +} + +/*******************************************************************\ + Function: random_tracest::operator()() Inputs: @@ -533,10 +646,16 @@ void random_tracest::operator()( if(inputs.empty()) throw ebmc_errort() << "module does not have inputs"; - message.statistics() << "Found " << inputs.size() << " input(s)" + auto state_variables = this->state_variables(); + + message.statistics() << "Found " << inputs.size() << " input(s) and " + << state_variables.size() << " state variable(s)" << messaget::eom; - freeze_inputs(inputs, number_of_timeframes, solver); + auto unconstrained_state_variables = remove_constrained(state_variables); + + freeze(inputs, number_of_timeframes, solver); + freeze(unconstrained_state_variables, 1, solver); message.status() << "Solving with " << solver.decision_procedure_text() << messaget::eom; @@ -546,7 +665,13 @@ void random_tracest::operator()( auto input_constraints = random_input_constraints(solver, inputs, number_of_timeframes); - solver.push(input_constraints); + auto initial_state_constraints = + random_initial_state_constraints(solver, unconstrained_state_variables); + + auto merged = + merge_constraints(input_constraints, initial_state_constraints); + + solver.push(merged); auto dec_result = solver(); solver.pop(); From c3a6eeb1ba55e8006980b1bae2ba74c5234fa638 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 15:29:28 +0100 Subject: [PATCH 02/40] BMC: include macros in trace This adds the values of macro symbols (parameter, localparam, etc.) to the BMC trace. --- regression/ebmc/traces/verilog1.desc | 15 +++++++ regression/ebmc/traces/verilog1.v | 14 +++++++ .../trans_trace_word_level.cpp | 41 ++++++++++++------- 3 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 regression/ebmc/traces/verilog1.desc create mode 100644 regression/ebmc/traces/verilog1.v diff --git a/regression/ebmc/traces/verilog1.desc b/regression/ebmc/traces/verilog1.desc new file mode 100644 index 000000000..1e6ff0ae8 --- /dev/null +++ b/regression/ebmc/traces/verilog1.desc @@ -0,0 +1,15 @@ +CORE +verilog1.v +--bound 9 --numbered-trace +^\[.*\] .* REFUTED$ +^Counterexample with 10 states:$ +^main\.P@0 = 123$ +^main\.Q@0 = 124$ +^main\.data@0 = 1$ +^main\.P@9 = 123$ +^main\.Q@9 = 124$ +^main\.data@9 = 10$ +^EXIT=10$ +^SIGNAL=0$ +-- +^warning: ignoring diff --git a/regression/ebmc/traces/verilog1.v b/regression/ebmc/traces/verilog1.v new file mode 100644 index 000000000..64ed02c58 --- /dev/null +++ b/regression/ebmc/traces/verilog1.v @@ -0,0 +1,14 @@ +module main(input clk); + + parameter P = 123; + parameter Q = P + 1; + + reg [31:0] data; + initial data = 1; + + always @(posedge clk) + data = data + 1; + + always assert p1: data != 10; + +endmodule diff --git a/src/trans-word-level/trans_trace_word_level.cpp b/src/trans-word-level/trans_trace_word_level.cpp index 2fbfbd065..62a8614ad 100644 --- a/src/trans-word-level/trans_trace_word_level.cpp +++ b/src/trans-word-level/trans_trace_word_level.cpp @@ -58,20 +58,33 @@ trans_tracet compute_trans_trace( symbol.type.id()!=ID_module && symbol.type.id()!=ID_module_instance) { - exprt indexed_symbol_expr(ID_symbol, symbol.type); - - indexed_symbol_expr.set(ID_identifier, - timeframe_identifier(t, symbol.name)); - - exprt value_expr=decision_procedure.get(indexed_symbol_expr); - if(value_expr==indexed_symbol_expr) - value_expr=nil_exprt(); - - trans_tracet::statet::assignmentt assignment; - assignment.rhs.swap(value_expr); - assignment.lhs=symbol.symbol_expr(); - - state.assignments.push_back(assignment); + if(symbol.is_macro) + { + if(symbol.value.is_constant()) + { + trans_tracet::statet::assignmentt assignment; + assignment.rhs = symbol.value; + assignment.lhs = symbol.symbol_expr(); + state.assignments.push_back(assignment); + } + } + else + { + exprt indexed_symbol_expr(ID_symbol, symbol.type); + + indexed_symbol_expr.set( + ID_identifier, timeframe_identifier(t, symbol.name)); + + exprt value_expr = decision_procedure.get(indexed_symbol_expr); + if(value_expr == indexed_symbol_expr) + value_expr = nil_exprt(); + + trans_tracet::statet::assignmentt assignment; + assignment.rhs.swap(value_expr); + assignment.lhs = symbol.symbol_expr(); + + state.assignments.push_back(assignment); + } } } } From 7572f83f6e2ce1a5db729b8d93f796358e59acf2 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Wed, 3 Jan 2024 16:14:55 +0000 Subject: [PATCH 03/40] nuterm using libtorch --- .github/workflows/pull-request-checks.yaml | 49 +++ regression/nuterm/Makefile | 7 + regression/nuterm/counters/counter1.desc | 9 + regression/nuterm/counters/counter1.v | 9 + regression/nuterm/counters/counter1/trace.1 | 37 ++ regression/nuterm/counters/counter1/trace.10 | 40 ++ regression/nuterm/counters/counter1/trace.2 | 39 ++ regression/nuterm/counters/counter1/trace.3 | 40 ++ regression/nuterm/counters/counter1/trace.4 | 41 ++ regression/nuterm/counters/counter1/trace.5 | 38 ++ regression/nuterm/counters/counter1/trace.6 | 42 ++ regression/nuterm/counters/counter1/trace.7 | 37 ++ regression/nuterm/counters/counter1/trace.8 | 39 ++ regression/nuterm/counters/counter1/trace.9 | 40 ++ src/nuterm/CMakeLists.txt | 13 + src/nuterm/README | 7 + src/nuterm/nuterm_main.cpp | 258 +++++++++++ src/nuterm/pytorch_tests.cpp | 439 +++++++++++++++++++ src/nuterm/training.cpp | 78 ++++ src/nuterm/training.h | 40 ++ src/nuterm/vcd_parser.cpp | 123 ++++++ src/nuterm/vcd_parser.h | 48 ++ 22 files changed, 1473 insertions(+) create mode 100644 regression/nuterm/Makefile create mode 100644 regression/nuterm/counters/counter1.desc create mode 100644 regression/nuterm/counters/counter1.v create mode 100644 regression/nuterm/counters/counter1/trace.1 create mode 100644 regression/nuterm/counters/counter1/trace.10 create mode 100644 regression/nuterm/counters/counter1/trace.2 create mode 100644 regression/nuterm/counters/counter1/trace.3 create mode 100644 regression/nuterm/counters/counter1/trace.4 create mode 100644 regression/nuterm/counters/counter1/trace.5 create mode 100644 regression/nuterm/counters/counter1/trace.6 create mode 100644 regression/nuterm/counters/counter1/trace.7 create mode 100644 regression/nuterm/counters/counter1/trace.8 create mode 100644 regression/nuterm/counters/counter1/trace.9 create mode 100644 src/nuterm/CMakeLists.txt create mode 100644 src/nuterm/README create mode 100644 src/nuterm/nuterm_main.cpp create mode 100644 src/nuterm/pytorch_tests.cpp create mode 100644 src/nuterm/training.cpp create mode 100644 src/nuterm/training.h create mode 100644 src/nuterm/vcd_parser.cpp create mode 100644 src/nuterm/vcd_parser.h diff --git a/.github/workflows/pull-request-checks.yaml b/.github/workflows/pull-request-checks.yaml index ede4dc76e..60c99d903 100644 --- a/.github/workflows/pull-request-checks.yaml +++ b/.github/workflows/pull-request-checks.yaml @@ -191,3 +191,52 @@ jobs: run: make -C regression/verilog test-z3 - name: Print ccache stats run: ccache -s + + # This job takes approximately 1 minute + check-ubuntu-22_04-nuterm: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + - name: Fetch dependencies + env: + # This is needed in addition to -yq to prevent apt-get from asking for + # user input + DEBIAN_FRONTEND: noninteractive + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -yq gcc g++ ccache cmake + - name: Prepare ccache + uses: actions/cache@v3 + with: + path: .ccache + key: ${{ runner.os }}-22.04-nuterm-${{ github.ref }}-${{ github.sha }}-PR + restore-keys: | + ${{ runner.os }}-22.04-nuterm-${{ github.ref }} + ${{ runner.os }}-22.04-nuterm + - name: ccache environment + run: | + echo "CCACHE_BASEDIR=$PWD" >> $GITHUB_ENV + echo "CCACHE_DIR=$PWD/.ccache" >> $GITHUB_ENV + - name: Zero ccache stats and limit in size + run: ccache -z --max-size=500M + - name: Get pytorch + run: | + cd src/nuterm + wget -q https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.1.2%2Bcpu.zip + unzip -q *.zip + - name: Build with cmake + run: | + cd src/nuterm + LIBTORCH=`pwd`/libtorch + mkdir build + cd build + cmake -DCMAKE_PREFIX_PATH=$LIBTORCH -DCMAKE_CXX_COMPILER_LAUNCHER=ccache .. + cmake --build . --config Release + - name: Run the unit tests + run: src/nuterm/build/pytorch_tests + - name: Run the system tests + run: make -C regression/nuterm + - name: Print ccache stats + run: ccache -s diff --git a/regression/nuterm/Makefile b/regression/nuterm/Makefile new file mode 100644 index 000000000..e71292299 --- /dev/null +++ b/regression/nuterm/Makefile @@ -0,0 +1,7 @@ +default: test + +TEST_PL = ../../lib/cbmc/regression/test.pl + +test: + @$(TEST_PL) -c ../../../src/nuterm/build/nuterm + diff --git a/regression/nuterm/counters/counter1.desc b/regression/nuterm/counters/counter1.desc new file mode 100644 index 000000000..fb18fddcf --- /dev/null +++ b/regression/nuterm/counters/counter1.desc @@ -0,0 +1,9 @@ +CORE +counter1 + +^weight main.clk = 0 .*$ +^weight main.counter = 1 .*$ +^RESULT: main.counter-1$ +^bias: -1 .*$ +^EXIT=0$ +^SIGNAL=0$ diff --git a/regression/nuterm/counters/counter1.v b/regression/nuterm/counters/counter1.v new file mode 100644 index 000000000..8602870e3 --- /dev/null +++ b/regression/nuterm/counters/counter1.v @@ -0,0 +1,9 @@ +module main(input clk); + + reg [31:0] counter; + + always @(posedge clk) + if(counter != 0) + counter = counter - 1; + +endmodule diff --git a/regression/nuterm/counters/counter1/trace.1 b/regression/nuterm/counters/counter1/trace.1 new file mode 100644 index 000000000..bf4d73ec5 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.1 @@ -0,0 +1,37 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +1main.clk +#2 +b00001111111111111111111111111110 main.counter +#3 +b00001111111111111111111111111101 main.counter +0main.clk +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +#9 +b00001111111111111111111111110111 main.counter +#10 +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.10 b/regression/nuterm/counters/counter1/trace.10 new file mode 100644 index 000000000..01b330e53 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.10 @@ -0,0 +1,40 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +1main.clk +#2 +b00001111111111111111111111111110 main.counter +0main.clk +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +0main.clk +#6 +b00001111111111111111111111111010 main.counter +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +1main.clk +#9 +b00001111111111111111111111110111 main.counter +#10 +b00001111111111111111111111110110 main.counter +0main.clk diff --git a/regression/nuterm/counters/counter1/trace.2 b/regression/nuterm/counters/counter1/trace.2 new file mode 100644 index 000000000..cdbc97ec8 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.2 @@ -0,0 +1,39 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +#2 +b00001111111111111111111111111110 main.counter +1main.clk +#3 +b00001111111111111111111111111101 main.counter +0main.clk +#4 +b00001111111111111111111111111100 main.counter +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +1main.clk +#9 +b00001111111111111111111111110111 main.counter +0main.clk +#10 +b00001111111111111111111111110110 main.counter +1main.clk diff --git a/regression/nuterm/counters/counter1/trace.3 b/regression/nuterm/counters/counter1/trace.3 new file mode 100644 index 000000000..bb73ef9f3 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.3 @@ -0,0 +1,40 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +1main.clk +#1 +b00001111111111111111111111111111 main.counter +0main.clk +#2 +b00001111111111111111111111111110 main.counter +#3 +b00001111111111111111111111111101 main.counter +1main.clk +#4 +b00001111111111111111111111111100 main.counter +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +#7 +b00001111111111111111111111111001 main.counter +0main.clk +#8 +b00001111111111111111111111111000 main.counter +1main.clk +#9 +b00001111111111111111111111110111 main.counter +0main.clk +#10 +b00001111111111111111111111110110 main.counter +1main.clk diff --git a/regression/nuterm/counters/counter1/trace.4 b/regression/nuterm/counters/counter1/trace.4 new file mode 100644 index 000000000..a73e1f436 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.4 @@ -0,0 +1,41 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +1main.clk +#2 +b00001111111111111111111111111110 main.counter +#3 +b00001111111111111111111111111101 main.counter +0main.clk +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +0main.clk +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +1main.clk +#9 +b00001111111111111111111111110111 main.counter +0main.clk +#10 +b00001111111111111111111111110110 main.counter +1main.clk diff --git a/regression/nuterm/counters/counter1/trace.5 b/regression/nuterm/counters/counter1/trace.5 new file mode 100644 index 000000000..328a71c54 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.5 @@ -0,0 +1,38 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +1main.clk +#1 +b00001111111111111111111111111111 main.counter +#2 +b00001111111111111111111111111110 main.counter +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +0main.clk +#5 +b00001111111111111111111111111011 main.counter +1main.clk +#6 +b00001111111111111111111111111010 main.counter +0main.clk +#7 +b00001111111111111111111111111001 main.counter +1main.clk +#8 +b00001111111111111111111111111000 main.counter +#9 +b00001111111111111111111111110111 main.counter +#10 +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.6 b/regression/nuterm/counters/counter1/trace.6 new file mode 100644 index 000000000..b5b0e6b6e --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.6 @@ -0,0 +1,42 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +1main.clk +#2 +b00001111111111111111111111111110 main.counter +0main.clk +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +0main.clk +#7 +b00001111111111111111111111111001 main.counter +1main.clk +#8 +b00001111111111111111111111111000 main.counter +0main.clk +#9 +b00001111111111111111111111110111 main.counter +1main.clk +#10 +b00001111111111111111111111110110 main.counter +0main.clk diff --git a/regression/nuterm/counters/counter1/trace.7 b/regression/nuterm/counters/counter1/trace.7 new file mode 100644 index 000000000..51912c314 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.7 @@ -0,0 +1,37 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +#2 +b00001111111111111111111111111110 main.counter +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +0main.clk +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +#9 +b00001111111111111111111111110111 main.counter +1main.clk +#10 +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.8 b/regression/nuterm/counters/counter1/trace.8 new file mode 100644 index 000000000..fbcfcfe64 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.8 @@ -0,0 +1,39 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +0main.clk +#1 +b00001111111111111111111111111111 main.counter +1main.clk +#2 +b00001111111111111111111111111110 main.counter +0main.clk +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +1main.clk +#5 +b00001111111111111111111111111011 main.counter +0main.clk +#6 +b00001111111111111111111111111010 main.counter +1main.clk +#7 +b00001111111111111111111111111001 main.counter +#8 +b00001111111111111111111111111000 main.counter +#9 +b00001111111111111111111111110111 main.counter +#10 +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.9 b/regression/nuterm/counters/counter1/trace.9 new file mode 100644 index 000000000..b4d53fb22 --- /dev/null +++ b/regression/nuterm/counters/counter1/trace.9 @@ -0,0 +1,40 @@ +$date + Sun Jan 7 16:33:39 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.clk main.clk $end +$upscope $end +$enddefinitions $end +#0 +b00010000000000000000000000000000 main.counter +1main.clk +#1 +b00001111111111111111111111111111 main.counter +0main.clk +#2 +b00001111111111111111111111111110 main.counter +1main.clk +#3 +b00001111111111111111111111111101 main.counter +#4 +b00001111111111111111111111111100 main.counter +0main.clk +#5 +b00001111111111111111111111111011 main.counter +#6 +b00001111111111111111111111111010 main.counter +1main.clk +#7 +b00001111111111111111111111111001 main.counter +0main.clk +#8 +b00001111111111111111111111111000 main.counter +#9 +b00001111111111111111111111110111 main.counter +1main.clk +#10 +b00001111111111111111111111110110 main.counter diff --git a/src/nuterm/CMakeLists.txt b/src/nuterm/CMakeLists.txt new file mode 100644 index 000000000..fa2383654 --- /dev/null +++ b/src/nuterm/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.18 FATAL_ERROR) +project(nuterm) + +find_package(Torch REQUIRED) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}") + +add_executable(pytorch_tests pytorch_tests.cpp) +target_link_libraries(pytorch_tests "${TORCH_LIBRARIES}") +set_property(TARGET pytorch_tests PROPERTY CXX_STANDARD 17) + +add_executable(nuterm nuterm_main.cpp vcd_parser.cpp training.cpp) +target_link_libraries(nuterm "${TORCH_LIBRARIES}") +set_property(TARGET nuterm PROPERTY CXX_STANDARD 17) diff --git a/src/nuterm/README b/src/nuterm/README new file mode 100644 index 000000000..d509a7131 --- /dev/null +++ b/src/nuterm/README @@ -0,0 +1,7 @@ +wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-2.1.2.zip + +mkdir build +cd build +cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_PREFIX_PATH=/Users/kroening/progr/2hw-cbmc/src/nuterm/libtorch .. +cmake --build . --config Release + diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp new file mode 100644 index 000000000..e5db7f5d7 --- /dev/null +++ b/src/nuterm/nuterm_main.cpp @@ -0,0 +1,258 @@ +/*******************************************************************\ + +Module: nuterm main + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include "training.h" +#include "vcd_parser.h" + +#include +#include +#include +#include +#include +#include + +using tracest = std::list; + +tracest read_traces(const std::string &path) +{ + std::vector file_names; + + for(const auto &entry : std::filesystem::directory_iterator(path)) + file_names.push_back(entry.path()); + + // sort to get a fixed ordering + std::sort(file_names.begin(), file_names.end()); + + tracest traces; + + for(const auto &entry : file_names) + { + std::cout << "Reading " << entry << '\n'; + std::ifstream in(entry); + traces.push_back(vcd_parser(in)); + } + + return traces; +} + +std::size_t number_of_transitions(const tracest &traces) +{ + std::size_t result = 0; + + for(auto &trace : traces) + result += trace.states.empty() ? 0 : trace.states.size() - 1; + + return result; +} + +using state_variablest = std::map; + +state_variablest state_variables(const tracest &traces) +{ + // number all identifiers + state_variablest identifiers; + for(auto &trace : traces) + for(auto &state : trace.states) + for(auto &value_change : state.changes) + identifiers.emplace(value_change.first, identifiers.size()); + + return identifiers; +} + +#include + +double vcd_to_value(const std::string &src) +{ + // VCD gives binary values + auto integer = std::stoull(src, nullptr, 2); + //std::cout << "VALUE " << src << " -> " << double(integer) << "\n"; + return integer; +} + +torch::Tensor state_to_tensor( + const state_variablest &state_variables, + const vcdt::statet &state) +{ + std::vector data; + data.resize(state_variables.size(), 0); + for(auto &var : state_variables) + { + auto v_it = state.changes.find(var.first); + if(v_it != state.changes.end()) + data[var.second] = vcd_to_value(v_it->second); + } + + return torch::tensor(data, torch::kFloat64); +} + +torch::Tensor state_pair_to_tensor( + const state_variablest &state_variables, + const vcdt::statet ¤t, + const vcdt::statet &next) +{ + // We make a tensor that has dimensions 2 x |V|. + // The '2' allows for current and next state. + auto tensor_current = state_to_tensor(state_variables, current); + auto tensor_next = state_to_tensor(state_variables, next); + auto tensor_pair = torch::stack({tensor_current, tensor_next}, 0); + // std::cout << "P: " << tensor_pair << "\n" << std::flush; + return std::move(tensor_pair); +} + +std::vector traces_to_tensors( + const state_variablest &state_variables, + const tracest &traces) +{ + auto t = number_of_transitions(traces); + + std::vector result; + result.reserve(t); + + for(auto &trace : traces) + { + const auto full_trace = trace.full_trace(); + for(std::size_t t = 1; t < full_trace.size(); t++) + { + auto ¤t = full_trace[t - 1]; + auto &next = full_trace[t]; + auto tensor = state_pair_to_tensor(state_variables, current, next); + result.push_back(std::move(tensor)); + } + } + + return result; +} + +std::string sum(const std::vector &terms) +{ + std::string result; + for(auto &term : terms) + { + if(result.empty()) + result = term; + else if(term != "" && term[0] == '-') + result += term; + else + result += "+" + term; + } + return result; +} + +std::string ranking_net_to_string( + const state_variablest &state_variables, + const std::shared_ptr net) +{ + std::vector terms; + + auto weight = net->named_parameters()["fc1.weight"]; + auto bias = net->named_parameters()["fc1.bias"]; + + for(auto &var : state_variables) + { + assert(var.second < state_variables.size()); + long long weight_int = round(weight[0][var.second].item()); + if(weight_int == 0) + { + } + else if(weight_int == 1) + { + terms.push_back(var.first); + } + else if(weight_int == -1) + { + terms.push_back("-" + var.first); + } + else + { + terms.push_back(std::to_string(weight_int) + "*" + var.first); + } + } + + long long bias_int = round(bias.item()); + terms.push_back(std::to_string(bias_int)); + + return sum(terms); +} + +int main(int argc, const char *argv[]) +{ + // The first argument is the directory with the VCD files. + if(argc != 2) + { + std::cout << "Usage: nuterm trace_directory\n"; + return 1; + } + + const auto traces = read_traces(argv[1]); + + auto state_variables = ::state_variables(traces); + + if(state_variables.empty()) + { + std::cout << "no state variables\n"; + return 1; + } + + for(auto &v : state_variables) + std::cout << "V" << v.second << "=" << v.first << '\n'; + + torch::manual_seed(0); + + const auto tensors = traces_to_tensors(state_variables, traces); + + std::cout << "Got " << tensors.size() << " transitions\n"; + + const auto net = std::make_shared(state_variables.size()); + +#if 0 + for(auto &p : net->named_parameters()) + { + std::cout << p.key() << ": " << p.value() << "\n"; + } +#endif + + { + auto weight = net->named_parameters()["fc1.weight"]; + auto bias = net->named_parameters()["fc1.bias"]; + assert(weight.dim() == 2); + assert(bias.dim() == 1); + std::cout << "#weights: " << weight.size(1) << "\n"; + assert(weight.size(1) == state_variables.size()); + +#if 0 + for(auto &var : state_variables) + { + assert(var.second < state_variables.size()); + std::cout << "weight " << var.first << " = " << weight[0][var.second].item() << '\n'; + } + + std::cout << "bias: " << bias.item() << "\n"; +#endif + } + + std::cout << "TRAINING\n"; + ranking_function_training(net, tensors); + + { + auto weight = net->named_parameters()["fc1.weight"]; + auto bias = net->named_parameters()["fc1.bias"]; + for(auto &var : state_variables) + { + assert(var.second < state_variables.size()); + std::cout << "weight " << var.first << " = " + << (long long)round(weight[0][var.second].item()) << ' ' + << weight[0][var.second].item() << '\n'; + } + + std::cout << "bias: " << (long long)(round(bias.item())) << ' ' + << bias.item() << "\n"; + } + + std::cout << "RESULT: " << ranking_net_to_string(state_variables, net) + << '\n'; +} diff --git a/src/nuterm/pytorch_tests.cpp b/src/nuterm/pytorch_tests.cpp new file mode 100644 index 000000000..04e5dd0c1 --- /dev/null +++ b/src/nuterm/pytorch_tests.cpp @@ -0,0 +1,439 @@ +#include + +#include +#include + +struct test_net : torch::nn::Module +{ + test_net() + { + fc1 = register_module("fc1", torch::nn::Linear(1, 1)); + fc1->to(torch::kFloat64); + } + + torch::Tensor forward(torch::Tensor x) + { + return fc1->forward(x); + } + + torch::nn::Linear fc1{nullptr}; +}; + +struct test_batcht +{ + torch::Tensor data; + torch::Tensor target; +}; + +void train( + std::shared_ptr net, + const std::vector &batches) +{ + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 30; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : batches) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction = net->forward(batch.data); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = torch::mse_loss(prediction, batch.target); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + } + } +} + +void pytorch_test1() +{ + torch::manual_seed(0); + + auto net = std::make_shared(); + + std::vector batches = { + {.data = torch::full({1}, /*value*/ 0, torch::kFloat64), + .target = torch::full({1}, /*value*/ 10, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 1, torch::kFloat64), + .target = torch::full({1}, /*value*/ 11, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 2, torch::kFloat64), + .target = torch::full({1}, /*value*/ 12, torch::kFloat64)}}; + + train(net, batches); + + assert(round(net->parameters()[0].item()) == 1); // coefficient + assert(round(net->parameters()[1].item()) == 10); // bias +} + +void pytorch_test2() +{ + torch::manual_seed(0); + + auto net = std::make_shared(); + + std::vector batches = { + {.data = torch::full({1}, /*value*/ 0, torch::kFloat64), + .target = torch::full({1}, /*value*/ 0, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 1, torch::kFloat64), + .target = torch::full({1}, /*value*/ -1, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 2, torch::kFloat64), + .target = torch::full({1}, /*value*/ -2, torch::kFloat64)}}; + + train(net, batches); + + assert(round(net->parameters()[0].item()) == -1); // coefficient + assert(round(net->parameters()[1].item()) == 0); // bias +} + +void pytorch_test3() +{ + torch::manual_seed(0); + + auto net = std::make_shared(); + + std::vector batches = { + {.data = torch::full({1}, /*value*/ 0, torch::kFloat64), + .target = torch::full({1}, /*value*/ 10, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 1, torch::kFloat64), + .target = torch::full({1}, /*value*/ 9, torch::kFloat64)}, + {.data = torch::full({1}, /*value*/ 2, torch::kFloat64), + .target = torch::full({1}, /*value*/ 8, torch::kFloat64)}}; + + train(net, batches); + + assert(round(net->parameters()[0].item()) == -1); // coefficient + assert(round(net->parameters()[1].item()) == 10); // bias +} + +void pytorch_test4() +{ + torch::manual_seed(0); + + auto net = std::make_shared(); + + std::vector data = { + torch::full({1}, /*value*/ 0, torch::kFloat64), + torch::full({1}, /*value*/ 1, torch::kFloat64), + torch::full({1}, /*value*/ 2, torch::kFloat64), + torch::full({1}, /*value*/ 3, torch::kFloat64), + torch::full({1}, /*value*/ 4, torch::kFloat64), + torch::full({1}, /*value*/ 5, torch::kFloat64)}; + + auto my_loss = [](const torch::Tensor &input) -> torch::Tensor { + return input.abs(); + }; + + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 10; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction = net->forward(batch); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = my_loss(prediction); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + } + } + + assert(round(net->parameters()[0].item()) == 0); // coefficient + assert(round(net->parameters()[1].item()) == 0); // bias +} + +struct test_net2 : torch::nn::Module +{ + explicit test_net2(std::size_t number_of_inputs) + { + fc1 = register_module("fc1", torch::nn::Linear(number_of_inputs, 1)); + fc1->to(torch::kFloat64); + } + + torch::Tensor forward(torch::Tensor x) + { + x = fc1->forward(x); + // the relu ensures x is bounded from below + x = torch::relu(x); + return x; + } + + torch::nn::Linear fc1{nullptr}; +}; + +void pytorch_test5() +{ + torch::manual_seed(0); + + auto net = std::make_shared(2); + + std::vector data = { + torch::tensor({0, 0}, torch::kFloat64), + torch::tensor({1, 0}, torch::kFloat64), + torch::tensor({2, 0}, torch::kFloat64), + torch::tensor({3, 0}, torch::kFloat64), + torch::tensor({4, 0}, torch::kFloat64), + torch::tensor({5, 0}, torch::kFloat64)}; + + auto my_loss = [](const torch::Tensor &input) -> torch::Tensor { + return input.abs(); + }; + + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 10; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction = net->forward(batch); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = my_loss(prediction); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + } + } + + assert(round(net->parameters()[0][0][0].item()) == 0); // coefficient + assert(round(net->parameters()[0][0][1].item()) == 0); // coefficient + assert(round(net->parameters()[1].item()) == -1); // bias +} + +void pytorch_test6() +{ + torch::manual_seed(0); + + auto net = std::make_shared(1); + + // one state variable, pairs are transitions + std::vector data = { + torch::stack( + {torch::tensor({5}, torch::kFloat64), + torch::tensor({4}, torch::kFloat64)}), + torch::stack( + {torch::tensor({4}, torch::kFloat64), + torch::tensor({3}, torch::kFloat64)}), + torch::stack( + {torch::tensor({3}, torch::kFloat64), + torch::tensor({2}, torch::kFloat64)}), + torch::stack( + {torch::tensor({2}, torch::kFloat64), + torch::tensor({1}, torch::kFloat64)}), + torch::stack( + {torch::tensor({1}, torch::kFloat64), + torch::tensor({0}, torch::kFloat64)})}; + + auto my_loss = + [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { + return torch::relu(next - curr + 1.0); + }; + + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 3; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction_curr = net->forward(batch[0]); + torch::Tensor prediction_next = net->forward(batch[1]); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = my_loss(prediction_curr, prediction_next); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + } + } + + assert(round(net->parameters()[0].item()) == 1); // coefficient + assert(round(net->parameters()[1].item()) == 1); // bias +} + +void pytorch_test7() +{ + torch::manual_seed(0); + + auto net = std::make_shared(2); + + // two state variables, pairs are transitions + std::vector data = { + torch::stack( + {torch::tensor({0, 5}, torch::kFloat64), + torch::tensor({0, 4}, torch::kFloat64)}), + torch::stack( + {torch::tensor({0, 4}, torch::kFloat64), + torch::tensor({0, 3}, torch::kFloat64)}), + torch::stack( + {torch::tensor({0, 3}, torch::kFloat64), + torch::tensor({0, 2}, torch::kFloat64)}), + torch::stack( + {torch::tensor({0, 2}, torch::kFloat64), + torch::tensor({0, 1}, torch::kFloat64)}), + torch::stack( + {torch::tensor({0, 1}, torch::kFloat64), + torch::tensor({0, 0}, torch::kFloat64)})}; + + auto my_loss = + [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { + return torch::relu(next - curr + 1.0); + }; + + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 3; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction_curr = net->forward(batch[0]); + torch::Tensor prediction_next = net->forward(batch[1]); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = my_loss(prediction_curr, prediction_next); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + //std::cout << "L " << loss.item() << "\n"; + + // Update the parameters based on the calculated gradients. + optimizer.step(); + } + } + + //std::cout << "XX: " << net->parameters() << "\n"; + //std::cout << "C: " << net->parameters()[0][0][0].item() << "\n"; + //std::cout << "C: " << net->parameters()[0][0][1].item() << "\n"; + //std::cout << "B: " << net->parameters()[1].item() << "\n"; + assert(round(net->parameters()[0][0][0].item()) == 0); // coefficient + assert(round(net->parameters()[0][0][1].item()) == 1); // coefficient + assert(round(net->parameters()[1].item()) == 0); // bias +} + +void pytorch_test8() +{ + torch::manual_seed(0); + + auto net = std::make_shared(1); + + // one state variable, pairs are transitions + std::vector data = { + torch::stack( + {torch::tensor({1}, torch::kFloat64), + torch::tensor({2}, torch::kFloat64)}), + torch::stack( + {torch::tensor({2}, torch::kFloat64), + torch::tensor({3}, torch::kFloat64)}), + torch::stack( + {torch::tensor({3}, torch::kFloat64), + torch::tensor({4}, torch::kFloat64)}), + torch::stack( + {torch::tensor({4}, torch::kFloat64), + torch::tensor({5}, torch::kFloat64)}), + torch::stack( + {torch::tensor({5}, torch::kFloat64), + torch::tensor({6}, torch::kFloat64)})}; + + auto my_loss = + [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { + // std::cout << "LL " << from.item() << " -> " << to.item() << "\n"; + return torch::relu(next - curr + 1.0); + }; + + //torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.1); + + for(size_t epoch = 1; epoch <= 30; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + torch::Tensor prediction_curr = net->forward(batch[0]); + torch::Tensor prediction_next = net->forward(batch[1]); + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = my_loss(prediction_curr, prediction_next); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + + // std::cout << "L " << loss.item() << "\n"; + } + } + + //std::cout << "C: " << net->parameters()[0].item() << "\n"; + //std::cout << "B: " << net->parameters()[1].item() << "\n"; + assert(round(net->parameters()[0].item()) == -1); // coefficient + assert(round(net->parameters()[1].item()) == 6); // bias +} + +int main() +{ + std::cout << "Running tests\n"; + + pytorch_test1(); + pytorch_test2(); + pytorch_test3(); + pytorch_test4(); + pytorch_test5(); + pytorch_test6(); + pytorch_test7(); + pytorch_test8(); +} diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp new file mode 100644 index 000000000..60a74850f --- /dev/null +++ b/src/nuterm/training.cpp @@ -0,0 +1,78 @@ +/*******************************************************************\ + +Module: Ranking Function Training + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include "training.h" + +#include + +const double delta = 1; + +#include + +void ranking_function_training( + std::shared_ptr net, + const std::vector &data) +{ + auto ranking_function_loss = + [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor + { + assert(curr.dim() == 1 && next.dim() == 1); + // The ranking needs to decrease from 'curr' to 'next' + // by at least 'delta'. Anything less than that is loss. + return torch::relu(next - curr + delta); + }; + + torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + torch::Tensor last_loss = {}; + + for(size_t epoch = 1; epoch <= 10; ++epoch) + { + size_t batch_index = 0; + + // Iterate the data loader to yield batches from the dataset. + for(auto &batch : data) + { + // Reset gradients. + optimizer.zero_grad(); + + // Execute the model on the input data. + assert(batch.size(1) == 2); + torch::Tensor prediction_curr = net->forward(batch[0]); + torch::Tensor prediction_next = net->forward(batch[1]); + // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; + // std::cout << "R: " << std::fixed << prediction_curr.item() << " -> " << prediction_next.item() << "\n"; + + // Compute a loss value to judge the prediction of our model. + torch::Tensor loss = + ranking_function_loss(prediction_curr, prediction_next); + + // Compute gradients of the loss w.r.t. the parameters of our model. + loss.backward(); + + // Update the parameters based on the calculated gradients. + optimizer.step(); + +#if 0 + if(1) + { + std::cout << "Epoch: " << epoch << " | Batch: " << batch_index + << " | Loss: " << std::fixed << std::setprecision(3) + << loss.item() << '\n'; + //torch::save(net, "net.pt"); + } +#endif + + batch_index++; + + last_loss = loss; + } + } + + std::cout << "Final loss: " << std::fixed << std::setprecision(3) + << last_loss.item() << '\n'; +} diff --git a/src/nuterm/training.h b/src/nuterm/training.h new file mode 100644 index 000000000..fd782c450 --- /dev/null +++ b/src/nuterm/training.h @@ -0,0 +1,40 @@ +/*******************************************************************\ + +Module: Training + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include + +//#include + +struct RankingNet : torch::nn::Module +{ + explicit RankingNet(std::size_t number_of_state_variables) + { + fc1 = + register_module("fc1", torch::nn::Linear(number_of_state_variables, 1)); + fc1->to(torch::kFloat64); +#if 0 + // The default values for nn::Linear are kaiming_uniform(sqrt(5)). + // Use zeros instead. + fc1->named_parameters()["weight"].fill_(0, torch::requires_grad()); + fc1->named_parameters()["bias"] = torch::zeros({1}); // .fill_(0, torch::requires_grad()); + std::cout << "CON: " << fc1->named_parameters()["bias"].item() << "\n"; +#endif + } + + torch::Tensor forward(torch::Tensor x) + { + // the relu ensures that the function is bounded from below by 0 + return torch::relu(fc1->forward(x)); + } + + torch::nn::Linear fc1{nullptr}; +}; + +void ranking_function_training( + const std::shared_ptr net, + const std::vector &); diff --git a/src/nuterm/vcd_parser.cpp b/src/nuterm/vcd_parser.cpp new file mode 100644 index 000000000..1c2cfae0e --- /dev/null +++ b/src/nuterm/vcd_parser.cpp @@ -0,0 +1,123 @@ +/*******************************************************************\ + +Module: VCD Parser + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include "vcd_parser.h" + +#include + +static bool is_whitespace(char ch) +{ + return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'; +} + +static std::string vcd_token(std::istream &in) +{ + std::string token; + char ch; + while(!in.eof()) + { + ch = in.get(); + if(is_whitespace(ch)) + { + if(!token.empty()) + return token; + } + else + token += ch; + } + + return token; +} + +void vcd_command(vcdt &, const std::string &token, std::istream &in) +{ + // look for $end + while(true) + { + auto t = vcd_token(in); + if(t.empty() || t == "$end") + return; + } +} + +vcdt vcd_parser(std::istream &in) +{ + vcdt vcd; + + while(true) + { + auto token = vcd_token(in); + if(token.empty()) + break; + switch(token[0]) + { + case '$': + vcd_command(vcd, token, in); + break; + case '#': + // #decimal + vcd.simulation_time(token.substr(1, std::string::npos)); + break; + case '0': + case '1': + case 'x': + case 'X': + case 'z': + case 'Z': + // (0 | 1 | x | X | z | Z) identifier + // one token, no space + vcd.value_change(token.substr(0, 1), token.substr(1)); + break; + case 'b': + case 'B': + // (b | B) value identifier + // two tokens, space between value and identifier + vcd.value_change(token.substr(1), vcd_token(in)); + break; + case 'r': + case 'R': + // (r | R) value identifier + // two tokens, space between value and identifier + vcd.value_change(token.substr(1), vcd_token(in)); + break; + default: + break; + } + } + + return vcd; +} + +std::vector vcdt::full_trace() const +{ + std::vector result; + result.reserve(states.size()); + + for(auto &state : states) + { + if(result.empty()) + { + result.push_back(state); + } + else + { + statet full_state(state.simulation_time); + + // copy the previous map + full_state.changes = result.back().changes; + + // apply the changes + for(auto &change : state.changes) + full_state.changes[change.first] = change.second; + + result.push_back(std::move(state)); + } + } + + return result; +} diff --git a/src/nuterm/vcd_parser.h b/src/nuterm/vcd_parser.h new file mode 100644 index 000000000..5c08bae83 --- /dev/null +++ b/src/nuterm/vcd_parser.h @@ -0,0 +1,48 @@ +/*******************************************************************\ + +Module: VCD Parser + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include +#include +#include +#include + +class vcdt +{ +public: + using value_mapt = std::map; + + struct statet + { + explicit statet(std::string t) : simulation_time(std::move(t)) + { + } + + std::string simulation_time; + value_mapt changes; + }; + + std::vector states; + + void simulation_time(const std::string &t) + { + states.push_back(statet(t)); + } + + void value_change(std::string value, const std::string &identifier) + { + if(states.empty()) + simulation_time(""); + states.back().changes[identifier] = std::move(value); + } + + // Expand the differential trace into a trace of full states, + // including all unchanged values. + std::vector full_trace() const; +}; + +vcdt vcd_parser(std::istream &); From a0887038ff48cacbe3f5a7be7f2a79bf30c09f38 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 16:09:12 +0100 Subject: [PATCH 04/40] fx --- src/nuterm/nuterm_main.cpp | 2 ++ src/nuterm/training.cpp | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index e5db7f5d7..3d3238e78 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -121,6 +121,8 @@ std::vector traces_to_tensors( auto ¤t = full_trace[t - 1]; auto &next = full_trace[t]; auto tensor = state_pair_to_tensor(state_variables, current, next); + assert(tensor.size(0) == 2); + assert(tensor.size(1) == state_variables.size()); result.push_back(std::move(tensor)); } } diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 60a74850f..db0d8b140 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -18,6 +18,11 @@ void ranking_function_training( std::shared_ptr net, const std::vector &data) { + assert(net != nullptr); + + for(auto &batch : data) + assert(batch.size(0) == 2); + auto ranking_function_loss = [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { @@ -41,7 +46,7 @@ void ranking_function_training( optimizer.zero_grad(); // Execute the model on the input data. - assert(batch.size(1) == 2); + assert(batch.size(0) == 2); torch::Tensor prediction_curr = net->forward(batch[0]); torch::Tensor prediction_next = net->forward(batch[1]); // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; From e072f57d67070fd0d8b4ac9a4636f265a3b203e8 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 16:15:16 +0100 Subject: [PATCH 05/40] fx --- regression/nuterm/counters/counter2.desc | 9 +++++ regression/nuterm/counters/counter2.v | 11 +++++ regression/nuterm/counters/counter2/trace.1 | 37 +++++++++++++++++ regression/nuterm/counters/counter2/trace.10 | 40 +++++++++++++++++++ regression/nuterm/counters/counter2/trace.2 | 39 ++++++++++++++++++ regression/nuterm/counters/counter2/trace.3 | 40 +++++++++++++++++++ regression/nuterm/counters/counter2/trace.4 | 41 +++++++++++++++++++ regression/nuterm/counters/counter2/trace.5 | 38 ++++++++++++++++++ regression/nuterm/counters/counter2/trace.6 | 42 ++++++++++++++++++++ regression/nuterm/counters/counter2/trace.7 | 37 +++++++++++++++++ regression/nuterm/counters/counter2/trace.8 | 39 ++++++++++++++++++ regression/nuterm/counters/counter2/trace.9 | 40 +++++++++++++++++++ 12 files changed, 413 insertions(+) create mode 100644 regression/nuterm/counters/counter2.desc create mode 100644 regression/nuterm/counters/counter2.v create mode 100644 regression/nuterm/counters/counter2/trace.1 create mode 100644 regression/nuterm/counters/counter2/trace.10 create mode 100644 regression/nuterm/counters/counter2/trace.2 create mode 100644 regression/nuterm/counters/counter2/trace.3 create mode 100644 regression/nuterm/counters/counter2/trace.4 create mode 100644 regression/nuterm/counters/counter2/trace.5 create mode 100644 regression/nuterm/counters/counter2/trace.6 create mode 100644 regression/nuterm/counters/counter2/trace.7 create mode 100644 regression/nuterm/counters/counter2/trace.8 create mode 100644 regression/nuterm/counters/counter2/trace.9 diff --git a/regression/nuterm/counters/counter2.desc b/regression/nuterm/counters/counter2.desc new file mode 100644 index 000000000..c52f96ca9 --- /dev/null +++ b/regression/nuterm/counters/counter2.desc @@ -0,0 +1,9 @@ +CORE +counter2 + +^weight main.clk = 0 .*$ +^weight main.counter = 1 .*$ +^RESULT: main.counter-1$ +^bias: -1 .*$ +^EXIT=0$ +^SIGNAL=0$ diff --git a/regression/nuterm/counters/counter2.v b/regression/nuterm/counters/counter2.v new file mode 100644 index 000000000..23783dd70 --- /dev/null +++ b/regression/nuterm/counters/counter2.v @@ -0,0 +1,11 @@ +module main(input clk); + + reg [31:0] counter; + + always @(posedge clk) + if(counter < 100) + counter = counter + 1; + else + counter = 0; + +endmodule diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 new file mode 100644 index 000000000..ffd02dbfe --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.1 @@ -0,0 +1,37 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +1main.clk +b00000000000000000000000001011011 main.counter +#2 +b00000000000000000000000001011100 main.counter +#3 +0main.clk +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +b00000000000000000000000001100010 main.counter +#9 +b00000000000000000000000001100011 main.counter +#10 +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 new file mode 100644 index 000000000..ca6a77889 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.10 @@ -0,0 +1,40 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +1main.clk +b00000000000000000000000001011011 main.counter +#2 +0main.clk +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +0main.clk +b00000000000000000000000001011111 main.counter +#6 +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +1main.clk +b00000000000000000000000001100010 main.counter +#9 +b00000000000000000000000001100011 main.counter +#10 +0main.clk +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 new file mode 100644 index 000000000..23f9e7e4a --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.2 @@ -0,0 +1,39 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +b00000000000000000000000001011011 main.counter +#2 +1main.clk +b00000000000000000000000001011100 main.counter +#3 +0main.clk +b00000000000000000000000001011101 main.counter +#4 +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +1main.clk +b00000000000000000000000001100010 main.counter +#9 +0main.clk +b00000000000000000000000001100011 main.counter +#10 +1main.clk +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 new file mode 100644 index 000000000..9ff5b192a --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.3 @@ -0,0 +1,40 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +1main.clk +b00000000000000000000000001011010 main.counter +#1 +0main.clk +b00000000000000000000000001011011 main.counter +#2 +b00000000000000000000000001011100 main.counter +#3 +1main.clk +b00000000000000000000000001011101 main.counter +#4 +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +b00000000000000000000000001100000 main.counter +#7 +0main.clk +b00000000000000000000000001100001 main.counter +#8 +1main.clk +b00000000000000000000000001100010 main.counter +#9 +0main.clk +b00000000000000000000000001100011 main.counter +#10 +1main.clk +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 new file mode 100644 index 000000000..401cad9ba --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.4 @@ -0,0 +1,41 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +1main.clk +b00000000000000000000000001011011 main.counter +#2 +b00000000000000000000000001011100 main.counter +#3 +0main.clk +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +0main.clk +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +1main.clk +b00000000000000000000000001100010 main.counter +#9 +0main.clk +b00000000000000000000000001100011 main.counter +#10 +1main.clk +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 new file mode 100644 index 000000000..c816ec596 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.5 @@ -0,0 +1,38 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +1main.clk +b00000000000000000000000001011010 main.counter +#1 +b00000000000000000000000001011011 main.counter +#2 +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +0main.clk +b00000000000000000000000001011110 main.counter +#5 +1main.clk +b00000000000000000000000001011111 main.counter +#6 +0main.clk +b00000000000000000000000001100000 main.counter +#7 +1main.clk +b00000000000000000000000001100001 main.counter +#8 +b00000000000000000000000001100010 main.counter +#9 +b00000000000000000000000001100011 main.counter +#10 +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 new file mode 100644 index 000000000..9b3cea490 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.6 @@ -0,0 +1,42 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +1main.clk +b00000000000000000000000001011011 main.counter +#2 +0main.clk +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +0main.clk +b00000000000000000000000001100000 main.counter +#7 +1main.clk +b00000000000000000000000001100001 main.counter +#8 +0main.clk +b00000000000000000000000001100010 main.counter +#9 +1main.clk +b00000000000000000000000001100011 main.counter +#10 +0main.clk +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 new file mode 100644 index 000000000..65a5bb3f8 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.7 @@ -0,0 +1,37 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +b00000000000000000000000001011011 main.counter +#2 +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +0main.clk +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +b00000000000000000000000001100010 main.counter +#9 +1main.clk +b00000000000000000000000001100011 main.counter +#10 +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 new file mode 100644 index 000000000..4109ece07 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.8 @@ -0,0 +1,39 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +0main.clk +b00000000000000000000000001011010 main.counter +#1 +1main.clk +b00000000000000000000000001011011 main.counter +#2 +0main.clk +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +1main.clk +b00000000000000000000000001011110 main.counter +#5 +0main.clk +b00000000000000000000000001011111 main.counter +#6 +1main.clk +b00000000000000000000000001100000 main.counter +#7 +b00000000000000000000000001100001 main.counter +#8 +b00000000000000000000000001100010 main.counter +#9 +b00000000000000000000000001100011 main.counter +#10 +b00000000000000000000000001100100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 new file mode 100644 index 000000000..c55727b45 --- /dev/null +++ b/regression/nuterm/counters/counter2/trace.9 @@ -0,0 +1,40 @@ +$date + Sun May 19 16:14:00 2024 +$end +$timescale + 1ns +$end +$scope module main $end + $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end +$upscope $end +$enddefinitions $end +#0 +1main.clk +b00000000000000000000000001011010 main.counter +#1 +0main.clk +b00000000000000000000000001011011 main.counter +#2 +1main.clk +b00000000000000000000000001011100 main.counter +#3 +b00000000000000000000000001011101 main.counter +#4 +0main.clk +b00000000000000000000000001011110 main.counter +#5 +b00000000000000000000000001011111 main.counter +#6 +1main.clk +b00000000000000000000000001100000 main.counter +#7 +0main.clk +b00000000000000000000000001100001 main.counter +#8 +b00000000000000000000000001100010 main.counter +#9 +1main.clk +b00000000000000000000000001100011 main.counter +#10 +b00000000000000000000000001100100 main.counter From 553a5df8dbeacd56ccf50a276deb67ec9f8221cf Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 16:35:36 +0100 Subject: [PATCH 06/40] fx --- regression/nuterm/counters/README | 3 +++ regression/nuterm/counters/counter1.v | 2 ++ regression/nuterm/counters/counter1/trace.1 | 14 +++++----- regression/nuterm/counters/counter1/trace.10 | 20 +++++++------- regression/nuterm/counters/counter1/trace.2 | 18 +++++++------ regression/nuterm/counters/counter1/trace.3 | 20 +++++++------- regression/nuterm/counters/counter1/trace.4 | 22 ++++++++------- regression/nuterm/counters/counter1/trace.5 | 16 ++++++----- regression/nuterm/counters/counter1/trace.6 | 24 +++++++++-------- regression/nuterm/counters/counter1/trace.7 | 14 +++++----- regression/nuterm/counters/counter1/trace.8 | 18 +++++++------ regression/nuterm/counters/counter1/trace.9 | 20 +++++++------- regression/nuterm/counters/counter2.v | 2 ++ regression/nuterm/counters/counter2/trace.1 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.10 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.2 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.3 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.4 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.5 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.6 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.7 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.8 | 28 +++++++++++--------- regression/nuterm/counters/counter2/trace.9 | 28 +++++++++++--------- 23 files changed, 270 insertions(+), 203 deletions(-) create mode 100644 regression/nuterm/counters/README diff --git a/regression/nuterm/counters/README b/regression/nuterm/counters/README new file mode 100644 index 000000000..204b5d3f1 --- /dev/null +++ b/regression/nuterm/counters/README @@ -0,0 +1,3 @@ +Sample as follows: + +ebmc FILE.v --random-traces --vcd FILE/trace diff --git a/regression/nuterm/counters/counter1.v b/regression/nuterm/counters/counter1.v index 8602870e3..9164ef2b3 100644 --- a/regression/nuterm/counters/counter1.v +++ b/regression/nuterm/counters/counter1.v @@ -6,4 +6,6 @@ module main(input clk); if(counter != 0) counter = counter - 1; + wire \nuterm::live = counter == 0; + endmodule diff --git a/regression/nuterm/counters/counter1/trace.1 b/regression/nuterm/counters/counter1/trace.1 index bf4d73ec5..3a91c4202 100644 --- a/regression/nuterm/counters/counter1/trace.1 +++ b/regression/nuterm/counters/counter1/trace.1 @@ -1,28 +1,30 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 1main.clk +b00001111111111111111111111111111 main.counter #2 b00001111111111111111111111111110 main.counter #3 -b00001111111111111111111111111101 main.counter 0main.clk +b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 b00001111111111111111111111111011 main.counter #6 diff --git a/regression/nuterm/counters/counter1/trace.10 b/regression/nuterm/counters/counter1/trace.10 index 01b330e53..b5798ad99 100644 --- a/regression/nuterm/counters/counter1/trace.10 +++ b/regression/nuterm/counters/counter1/trace.10 @@ -1,40 +1,42 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 1main.clk +b00001111111111111111111111111111 main.counter #2 -b00001111111111111111111111111110 main.counter 0main.clk +b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 -b00001111111111111111111111111011 main.counter 0main.clk +b00001111111111111111111111111011 main.counter #6 b00001111111111111111111111111010 main.counter #7 b00001111111111111111111111111001 main.counter #8 -b00001111111111111111111111111000 main.counter 1main.clk +b00001111111111111111111111111000 main.counter #9 b00001111111111111111111111110111 main.counter #10 -b00001111111111111111111111110110 main.counter 0main.clk +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.2 b/regression/nuterm/counters/counter1/trace.2 index cdbc97ec8..3a099d3e4 100644 --- a/regression/nuterm/counters/counter1/trace.2 +++ b/regression/nuterm/counters/counter1/trace.2 @@ -1,25 +1,27 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 b00001111111111111111111111111111 main.counter #2 -b00001111111111111111111111111110 main.counter 1main.clk +b00001111111111111111111111111110 main.counter #3 -b00001111111111111111111111111101 main.counter 0main.clk +b00001111111111111111111111111101 main.counter #4 b00001111111111111111111111111100 main.counter #5 @@ -29,11 +31,11 @@ b00001111111111111111111111111010 main.counter #7 b00001111111111111111111111111001 main.counter #8 -b00001111111111111111111111111000 main.counter 1main.clk +b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 0main.clk +b00001111111111111111111111110111 main.counter #10 -b00001111111111111111111111110110 main.counter 1main.clk +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.3 b/regression/nuterm/counters/counter1/trace.3 index bb73ef9f3..59212a28c 100644 --- a/regression/nuterm/counters/counter1/trace.3 +++ b/regression/nuterm/counters/counter1/trace.3 @@ -1,25 +1,27 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 1main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 0main.clk +b00001111111111111111111111111111 main.counter #2 b00001111111111111111111111111110 main.counter #3 -b00001111111111111111111111111101 main.counter 1main.clk +b00001111111111111111111111111101 main.counter #4 b00001111111111111111111111111100 main.counter #5 @@ -27,14 +29,14 @@ b00001111111111111111111111111011 main.counter #6 b00001111111111111111111111111010 main.counter #7 -b00001111111111111111111111111001 main.counter 0main.clk +b00001111111111111111111111111001 main.counter #8 -b00001111111111111111111111111000 main.counter 1main.clk +b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 0main.clk +b00001111111111111111111111110111 main.counter #10 -b00001111111111111111111111110110 main.counter 1main.clk +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.4 b/regression/nuterm/counters/counter1/trace.4 index a73e1f436..cbd274970 100644 --- a/regression/nuterm/counters/counter1/trace.4 +++ b/regression/nuterm/counters/counter1/trace.4 @@ -1,41 +1,43 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 1main.clk +b00001111111111111111111111111111 main.counter #2 b00001111111111111111111111111110 main.counter #3 -b00001111111111111111111111111101 main.counter 0main.clk +b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 0main.clk +b00001111111111111111111111111010 main.counter #7 b00001111111111111111111111111001 main.counter #8 -b00001111111111111111111111111000 main.counter 1main.clk +b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 0main.clk +b00001111111111111111111111110111 main.counter #10 -b00001111111111111111111111110110 main.counter 1main.clk +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.5 b/regression/nuterm/counters/counter1/trace.5 index 328a71c54..5002aad3d 100644 --- a/regression/nuterm/counters/counter1/trace.5 +++ b/regression/nuterm/counters/counter1/trace.5 @@ -1,17 +1,19 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 1main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 b00001111111111111111111111111111 main.counter #2 @@ -19,17 +21,17 @@ b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 0main.clk +b00001111111111111111111111111100 main.counter #5 -b00001111111111111111111111111011 main.counter 1main.clk +b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 0main.clk +b00001111111111111111111111111010 main.counter #7 -b00001111111111111111111111111001 main.counter 1main.clk +b00001111111111111111111111111001 main.counter #8 b00001111111111111111111111111000 main.counter #9 diff --git a/regression/nuterm/counters/counter1/trace.6 b/regression/nuterm/counters/counter1/trace.6 index b5b0e6b6e..f440f9faa 100644 --- a/regression/nuterm/counters/counter1/trace.6 +++ b/regression/nuterm/counters/counter1/trace.6 @@ -1,42 +1,44 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 1main.clk +b00001111111111111111111111111111 main.counter #2 -b00001111111111111111111111111110 main.counter 0main.clk +b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 0main.clk +b00001111111111111111111111111010 main.counter #7 -b00001111111111111111111111111001 main.counter 1main.clk +b00001111111111111111111111111001 main.counter #8 -b00001111111111111111111111111000 main.counter 0main.clk +b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 1main.clk +b00001111111111111111111111110111 main.counter #10 -b00001111111111111111111111110110 main.counter 0main.clk +b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.7 b/regression/nuterm/counters/counter1/trace.7 index 51912c314..4e6400954 100644 --- a/regression/nuterm/counters/counter1/trace.7 +++ b/regression/nuterm/counters/counter1/trace.7 @@ -1,17 +1,19 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 b00001111111111111111111111111111 main.counter #2 @@ -19,19 +21,19 @@ b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 0main.clk +b00001111111111111111111111111010 main.counter #7 b00001111111111111111111111111001 main.counter #8 b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 1main.clk +b00001111111111111111111111110111 main.counter #10 b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.8 b/regression/nuterm/counters/counter1/trace.8 index fbcfcfe64..a8aab3951 100644 --- a/regression/nuterm/counters/counter1/trace.8 +++ b/regression/nuterm/counters/counter1/trace.8 @@ -1,34 +1,36 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 0main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 1main.clk +b00001111111111111111111111111111 main.counter #2 -b00001111111111111111111111111110 main.counter 0main.clk +b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 1main.clk +b00001111111111111111111111111100 main.counter #5 -b00001111111111111111111111111011 main.counter 0main.clk +b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 1main.clk +b00001111111111111111111111111010 main.counter #7 b00001111111111111111111111111001 main.counter #8 diff --git a/regression/nuterm/counters/counter1/trace.9 b/regression/nuterm/counters/counter1/trace.9 index b4d53fb22..e8ec4d445 100644 --- a/regression/nuterm/counters/counter1/trace.9 +++ b/regression/nuterm/counters/counter1/trace.9 @@ -1,40 +1,42 @@ $date - Sun Jan 7 16:33:39 2024 + Sun May 19 16:34:19 2024 $end $timescale 1ns $end $scope module main $end - $var reg 32 main.counter main.counter [31:0] $end $var wire 1 main.clk main.clk $end + $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 -b00010000000000000000000000000000 main.counter 1main.clk +b00010000000000000000000000000000 main.counter +0main.nuterm::live #1 -b00001111111111111111111111111111 main.counter 0main.clk +b00001111111111111111111111111111 main.counter #2 -b00001111111111111111111111111110 main.counter 1main.clk +b00001111111111111111111111111110 main.counter #3 b00001111111111111111111111111101 main.counter #4 -b00001111111111111111111111111100 main.counter 0main.clk +b00001111111111111111111111111100 main.counter #5 b00001111111111111111111111111011 main.counter #6 -b00001111111111111111111111111010 main.counter 1main.clk +b00001111111111111111111111111010 main.counter #7 -b00001111111111111111111111111001 main.counter 0main.clk +b00001111111111111111111111111001 main.counter #8 b00001111111111111111111111111000 main.counter #9 -b00001111111111111111111111110111 main.counter 1main.clk +b00001111111111111111111111110111 main.counter #10 b00001111111111111111111111110110 main.counter diff --git a/regression/nuterm/counters/counter2.v b/regression/nuterm/counters/counter2.v index 23783dd70..b9bf1c637 100644 --- a/regression/nuterm/counters/counter2.v +++ b/regression/nuterm/counters/counter2.v @@ -8,4 +8,6 @@ module main(input clk); else counter = 0; + wire \nuterm::live = counter == 0; + endmodule diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 index ffd02dbfe..9d8529d51 100644 --- a/regression/nuterm/counters/counter2/trace.1 +++ b/regression/nuterm/counters/counter2/trace.1 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,31 +7,35 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 1main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 0main.clk -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 index ca6a77889..daee05991 100644 --- a/regression/nuterm/counters/counter2/trace.10 +++ b/regression/nuterm/counters/counter2/trace.10 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,34 +7,38 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 1main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 0main.clk -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 0main.clk -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 1main.clk -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 0main.clk -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 index 23f9e7e4a..9edf9ff22 100644 --- a/regression/nuterm/counters/counter2/trace.2 +++ b/regression/nuterm/counters/counter2/trace.2 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,33 +7,37 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 1main.clk -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 0main.clk -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 1main.clk -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 0main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 1main.clk -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 index 9ff5b192a..dc4d5456e 100644 --- a/regression/nuterm/counters/counter2/trace.3 +++ b/regression/nuterm/counters/counter2/trace.3 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,34 +7,38 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 1main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 0main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 1main.clk -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 0main.clk -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 1main.clk -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 0main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 1main.clk -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 index 401cad9ba..4c092e6a4 100644 --- a/regression/nuterm/counters/counter2/trace.4 +++ b/regression/nuterm/counters/counter2/trace.4 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,35 +7,39 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 1main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 0main.clk -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 0main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 1main.clk -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 0main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 1main.clk -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 index c816ec596..889a9562c 100644 --- a/regression/nuterm/counters/counter2/trace.5 +++ b/regression/nuterm/counters/counter2/trace.5 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,32 +7,36 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 1main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 0main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 1main.clk -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 0main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 1main.clk -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 index 9b3cea490..8c95bb5af 100644 --- a/regression/nuterm/counters/counter2/trace.6 +++ b/regression/nuterm/counters/counter2/trace.6 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,36 +7,40 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 1main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 0main.clk -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 0main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 1main.clk -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 0main.clk -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 1main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 0main.clk -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 index 65a5bb3f8..1cba83a17 100644 --- a/regression/nuterm/counters/counter2/trace.7 +++ b/regression/nuterm/counters/counter2/trace.7 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,31 +7,35 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 0main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 1main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 index 4109ece07..068f580b7 100644 --- a/regression/nuterm/counters/counter2/trace.8 +++ b/regression/nuterm/counters/counter2/trace.8 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,33 +7,37 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 0main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 1main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 0main.clk -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 1main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 0main.clk -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 1main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 index c55727b45..1d8041b22 100644 --- a/regression/nuterm/counters/counter2/trace.9 +++ b/regression/nuterm/counters/counter2/trace.9 @@ -1,5 +1,5 @@ $date - Sun May 19 16:14:00 2024 + Sun May 19 16:34:14 2024 $end $timescale 1ns @@ -7,34 +7,38 @@ $end $scope module main $end $var wire 1 main.clk main.clk $end $var reg 32 main.counter main.counter [31:0] $end + $var wire 1 main.nuterm::live main.nuterm::live $end $upscope $end $enddefinitions $end #0 1main.clk -b00000000000000000000000001011010 main.counter +b10000000000000000000000000001000 main.counter +0main.nuterm::live #1 0main.clk -b00000000000000000000000001011011 main.counter +b00000000000000000000000000000000 main.counter +1main.nuterm::live #2 1main.clk -b00000000000000000000000001011100 main.counter +b00000000000000000000000000000001 main.counter +0main.nuterm::live #3 -b00000000000000000000000001011101 main.counter +b00000000000000000000000000000010 main.counter #4 0main.clk -b00000000000000000000000001011110 main.counter +b00000000000000000000000000000011 main.counter #5 -b00000000000000000000000001011111 main.counter +b00000000000000000000000000000100 main.counter #6 1main.clk -b00000000000000000000000001100000 main.counter +b00000000000000000000000000000101 main.counter #7 0main.clk -b00000000000000000000000001100001 main.counter +b00000000000000000000000000000110 main.counter #8 -b00000000000000000000000001100010 main.counter +b00000000000000000000000000000111 main.counter #9 1main.clk -b00000000000000000000000001100011 main.counter +b00000000000000000000000000001000 main.counter #10 -b00000000000000000000000001100100 main.counter +b00000000000000000000000000001001 main.counter From 8c766a9148ceea73d5a5fbd0aee23ec8550cf7a0 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 16:37:28 +0100 Subject: [PATCH 07/40] fx --- src/nuterm/training.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index db0d8b140..4f9769577 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -32,7 +32,13 @@ void ranking_function_training( return torch::relu(next - curr + delta); }; + #if 1 torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); + #endif + #if 0 + torch::optim::AdamW optimizer(net->parameters(), /*lr=*/0.1); + #endif + torch::Tensor last_loss = {}; for(size_t epoch = 1; epoch <= 10; ++epoch) From 7402333faa5f0fe34f6aeeddff634eea55553c7b Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 17:00:08 +0100 Subject: [PATCH 08/40] fx --- src/nuterm/nuterm_main.cpp | 60 ++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 3d3238e78..18835cc77 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -64,6 +64,19 @@ state_variablest state_variables(const tracest &traces) return identifiers; } +bool has_suffix(const std::string &s, const std::string &suffix) +{ + if(s.length() >= suffix.length()) + return s.compare(s.length() - suffix.length(), suffix.length(), suffix) == 0; + else + return false; +} + +bool is_live_signal(const std::string &identifier) +{ + return has_suffix(identifier, "nuterm::live"); +} + #include double vcd_to_value(const std::string &src) @@ -104,8 +117,34 @@ torch::Tensor state_pair_to_tensor( return std::move(tensor_pair); } +bool is_live_state( + const std::string &liveness_signal, + const vcdt::statet &state) +{ + auto value_it = state.changes.find(liveness_signal); + if(value_it == state.changes.end()) + { + for(auto &[id, value] : state.changes) + std::cerr << "I: " << id << " = " << value << "\n"; + std::cerr << "state without liveness signal" << '\n'; + abort(); + } + return vcd_to_value(value_it->second) != 0; +} + +std::string liveness_signal(const state_variablest &state_variables) +{ + for(auto &[name, _] : state_variables) + if(is_live_signal(name)) + return name; + + std::cerr << "failed to find liveness signal" << '\n'; + abort(); +} + std::vector traces_to_tensors( const state_variablest &state_variables, + const std::string &liveness_signal, const tracest &traces) { auto t = number_of_transitions(traces); @@ -120,10 +159,17 @@ std::vector traces_to_tensors( { auto ¤t = full_trace[t - 1]; auto &next = full_trace[t]; - auto tensor = state_pair_to_tensor(state_variables, current, next); - assert(tensor.size(0) == 2); - assert(tensor.size(1) == state_variables.size()); - result.push_back(std::move(tensor)); + + // We must discard transitions in/out of 'live' states. + // There is no need for the ranking function to decrease + // on such transitions. + if(!is_live_state(liveness_signal, current) && !is_live_state(liveness_signal, next)) + { + auto tensor = state_pair_to_tensor(state_variables, current, next); + assert(tensor.size(0) == 2); + assert(tensor.size(1) == state_variables.size()); + result.push_back(std::move(tensor)); + } } } @@ -200,12 +246,16 @@ int main(int argc, const char *argv[]) return 1; } + auto liveness_signal = ::liveness_signal(state_variables); + for(auto &v : state_variables) std::cout << "V" << v.second << "=" << v.first << '\n'; + std::cout << "Liveness signal: " << liveness_signal << '\n'; + torch::manual_seed(0); - const auto tensors = traces_to_tensors(state_variables, traces); + const auto tensors = traces_to_tensors(state_variables, liveness_signal, traces); std::cout << "Got " << tensors.size() << " transitions\n"; From e88196ba1f5f40a7b31fe00bec0a5026354f94b0 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 17:00:22 +0100 Subject: [PATCH 09/40] fx --- src/nuterm/nuterm_main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 18835cc77..9f4c5c1a7 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -67,7 +67,8 @@ state_variablest state_variables(const tracest &traces) bool has_suffix(const std::string &s, const std::string &suffix) { if(s.length() >= suffix.length()) - return s.compare(s.length() - suffix.length(), suffix.length(), suffix) == 0; + return s.compare(s.length() - suffix.length(), suffix.length(), suffix) == + 0; else return false; } @@ -163,7 +164,9 @@ std::vector traces_to_tensors( // We must discard transitions in/out of 'live' states. // There is no need for the ranking function to decrease // on such transitions. - if(!is_live_state(liveness_signal, current) && !is_live_state(liveness_signal, next)) + if( + !is_live_state(liveness_signal, current) && + !is_live_state(liveness_signal, next)) { auto tensor = state_pair_to_tensor(state_variables, current, next); assert(tensor.size(0) == 2); @@ -255,7 +258,8 @@ int main(int argc, const char *argv[]) torch::manual_seed(0); - const auto tensors = traces_to_tensors(state_variables, liveness_signal, traces); + const auto tensors = + traces_to_tensors(state_variables, liveness_signal, traces); std::cout << "Got " << tensors.size() << " transitions\n"; From 7307135ba4f8046bafd5529b6530e1a42893e112 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 19 May 2024 17:05:07 +0100 Subject: [PATCH 10/40] fx --- src/nuterm/nuterm_main.cpp | 5 ++--- src/nuterm/vcd_parser.cpp | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 9f4c5c1a7..754929125 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -125,8 +125,6 @@ bool is_live_state( auto value_it = state.changes.find(liveness_signal); if(value_it == state.changes.end()) { - for(auto &[id, value] : state.changes) - std::cerr << "I: " << id << " = " << value << "\n"; std::cerr << "state without liveness signal" << '\n'; abort(); } @@ -156,6 +154,7 @@ std::vector traces_to_tensors( for(auto &trace : traces) { const auto full_trace = trace.full_trace(); + for(std::size_t t = 1; t < full_trace.size(); t++) { auto ¤t = full_trace[t - 1]; @@ -261,7 +260,7 @@ int main(int argc, const char *argv[]) const auto tensors = traces_to_tensors(state_variables, liveness_signal, traces); - std::cout << "Got " << tensors.size() << " transitions\n"; + std::cout << "Got " << tensors.size() << " transitions to rank\n"; const auto net = std::make_shared(state_variables.size()); diff --git a/src/nuterm/vcd_parser.cpp b/src/nuterm/vcd_parser.cpp index 1c2cfae0e..d8fe3ce8b 100644 --- a/src/nuterm/vcd_parser.cpp +++ b/src/nuterm/vcd_parser.cpp @@ -102,6 +102,7 @@ std::vector vcdt::full_trace() const { if(result.empty()) { + // first state result.push_back(state); } else @@ -115,7 +116,7 @@ std::vector vcdt::full_trace() const for(auto &change : state.changes) full_state.changes[change.first] = change.second; - result.push_back(std::move(state)); + result.push_back(std::move(full_state)); } } From 6a49a64c18933485795cafc53cd6094e51300e7e Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 10:04:09 +0100 Subject: [PATCH 11/40] fx --- regression/nuterm/counters/counter2/trace.1 | 2 +- regression/nuterm/counters/counter2/trace.10 | 2 +- regression/nuterm/counters/counter2/trace.2 | 2 +- regression/nuterm/counters/counter2/trace.3 | 2 +- regression/nuterm/counters/counter2/trace.4 | 2 +- regression/nuterm/counters/counter2/trace.5 | 2 +- regression/nuterm/counters/counter2/trace.6 | 2 +- regression/nuterm/counters/counter2/trace.7 | 2 +- regression/nuterm/counters/counter2/trace.8 | 2 +- regression/nuterm/counters/counter2/trace.9 | 2 +- src/nuterm/nuterm_main.cpp | 3 +++ src/nuterm/training.cpp | 19 +++++++++++++------ src/nuterm/training.h | 5 +++-- src/nuterm/vcd_parser.cpp | 7 +++++++ src/nuterm/vcd_parser.h | 2 ++ 15 files changed, 38 insertions(+), 18 deletions(-) diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 index 9d8529d51..1c3f6598b 100644 --- a/regression/nuterm/counters/counter2/trace.1 +++ b/regression/nuterm/counters/counter2/trace.1 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 index daee05991..a8ccd20c3 100644 --- a/regression/nuterm/counters/counter2/trace.10 +++ b/regression/nuterm/counters/counter2/trace.10 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 index 9edf9ff22..3e6438e79 100644 --- a/regression/nuterm/counters/counter2/trace.2 +++ b/regression/nuterm/counters/counter2/trace.2 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 index dc4d5456e..11c5d28bd 100644 --- a/regression/nuterm/counters/counter2/trace.3 +++ b/regression/nuterm/counters/counter2/trace.3 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 index 4c092e6a4..5cd763efc 100644 --- a/regression/nuterm/counters/counter2/trace.4 +++ b/regression/nuterm/counters/counter2/trace.4 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 index 889a9562c..9a7c7151c 100644 --- a/regression/nuterm/counters/counter2/trace.5 +++ b/regression/nuterm/counters/counter2/trace.5 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 index 8c95bb5af..75c94e532 100644 --- a/regression/nuterm/counters/counter2/trace.6 +++ b/regression/nuterm/counters/counter2/trace.6 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 index 1cba83a17..a37f81b0f 100644 --- a/regression/nuterm/counters/counter2/trace.7 +++ b/regression/nuterm/counters/counter2/trace.7 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 index 068f580b7..427bf9df1 100644 --- a/regression/nuterm/counters/counter2/trace.8 +++ b/regression/nuterm/counters/counter2/trace.8 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 index 1d8041b22..3a93263a4 100644 --- a/regression/nuterm/counters/counter2/trace.9 +++ b/regression/nuterm/counters/counter2/trace.9 @@ -1,5 +1,5 @@ $date - Sun May 19 16:34:14 2024 + Sun May 19 18:03:46 2024 $end $timescale 1ns diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 754929125..c54e58bf3 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -96,6 +96,7 @@ torch::Tensor state_to_tensor( data.resize(state_variables.size(), 0); for(auto &var : state_variables) { + if(has_suffix(var.first, ".clk")) continue; auto v_it = state.changes.find(var.first); if(v_it != state.changes.end()) data[var.second] = vcd_to_value(v_it->second); @@ -167,6 +168,8 @@ std::vector traces_to_tensors( !is_live_state(liveness_signal, current) && !is_live_state(liveness_signal, next)) { + std::cout << "\n" << current << "---->\n" << next; + auto tensor = state_pair_to_tensor(state_variables, current, next); assert(tensor.size(0) == 2); assert(tensor.size(1) == state_variables.size()); diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 4f9769577..ac1744566 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -32,11 +32,11 @@ void ranking_function_training( return torch::relu(next - curr + delta); }; - #if 1 + #if 0 torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); #endif - #if 0 - torch::optim::AdamW optimizer(net->parameters(), /*lr=*/0.1); + #if 1 + torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.01); #endif torch::Tensor last_loss = {}; @@ -48,6 +48,8 @@ void ranking_function_training( // Iterate the data loader to yield batches from the dataset. for(auto &batch : data) { + //std::cout << "B: " << batch << "\n"; + // Reset gradients. optimizer.zero_grad(); @@ -55,20 +57,22 @@ void ranking_function_training( assert(batch.size(0) == 2); torch::Tensor prediction_curr = net->forward(batch[0]); torch::Tensor prediction_next = net->forward(batch[1]); - // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; - // std::cout << "R: " << std::fixed << prediction_curr.item() << " -> " << prediction_next.item() << "\n"; + // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; + // std::cout << "R: " << std::fixed << prediction_curr.item() << " -> " << prediction_next.item() << "\n"; // Compute a loss value to judge the prediction of our model. torch::Tensor loss = ranking_function_loss(prediction_curr, prediction_next); + // std::cout << "L: " << loss << "\n"; + // Compute gradients of the loss w.r.t. the parameters of our model. loss.backward(); // Update the parameters based on the calculated gradients. optimizer.step(); -#if 0 +#if 1 if(1) { std::cout << "Epoch: " << epoch << " | Batch: " << batch_index @@ -82,6 +86,9 @@ void ranking_function_training( last_loss = loss; } + + if(last_loss.item() == 0) + break; // done } std::cout << "Final loss: " << std::fixed << std::setprecision(3) diff --git a/src/nuterm/training.h b/src/nuterm/training.h index fd782c450..95b788023 100644 --- a/src/nuterm/training.h +++ b/src/nuterm/training.h @@ -8,7 +8,7 @@ Author: Daniel Kroening, dkr@amazon.com #include -//#include +#include struct RankingNet : torch::nn::Module { @@ -29,7 +29,8 @@ struct RankingNet : torch::nn::Module torch::Tensor forward(torch::Tensor x) { // the relu ensures that the function is bounded from below by 0 - return torch::relu(fc1->forward(x)); + // return torch::relu(fc1->forward(x)); + return fc1->forward(x); } torch::nn::Linear fc1{nullptr}; diff --git a/src/nuterm/vcd_parser.cpp b/src/nuterm/vcd_parser.cpp index d8fe3ce8b..80bb988ff 100644 --- a/src/nuterm/vcd_parser.cpp +++ b/src/nuterm/vcd_parser.cpp @@ -93,6 +93,13 @@ vcdt vcd_parser(std::istream &in) return vcd; } +std::ostream &operator << (std::ostream &out, const vcdt::statet &state) +{ + for(auto &[id, value] : state.changes) + out << id << " = " << std::stoull(value, nullptr, 2) << '\n'; + return out; +} + std::vector vcdt::full_trace() const { std::vector result; diff --git a/src/nuterm/vcd_parser.h b/src/nuterm/vcd_parser.h index 5c08bae83..1949e7344 100644 --- a/src/nuterm/vcd_parser.h +++ b/src/nuterm/vcd_parser.h @@ -45,4 +45,6 @@ class vcdt std::vector full_trace() const; }; +std::ostream &operator << (std::ostream &, const vcdt::statet &); + vcdt vcd_parser(std::istream &); From 3c495dba6bd97087d79234a8c47638c2e9804ded Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 10:04:22 +0100 Subject: [PATCH 12/40] fx --- src/nuterm/nuterm_main.cpp | 5 +++-- src/nuterm/training.cpp | 10 +++++----- src/nuterm/vcd_parser.cpp | 2 +- src/nuterm/vcd_parser.h | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index c54e58bf3..f414aab8a 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -96,7 +96,8 @@ torch::Tensor state_to_tensor( data.resize(state_variables.size(), 0); for(auto &var : state_variables) { - if(has_suffix(var.first, ".clk")) continue; + if(has_suffix(var.first, ".clk")) + continue; auto v_it = state.changes.find(var.first); if(v_it != state.changes.end()) data[var.second] = vcd_to_value(v_it->second); @@ -169,7 +170,7 @@ std::vector traces_to_tensors( !is_live_state(liveness_signal, next)) { std::cout << "\n" << current << "---->\n" << next; - + auto tensor = state_pair_to_tensor(state_variables, current, next); assert(tensor.size(0) == 2); assert(tensor.size(1) == state_variables.size()); diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index ac1744566..c9dbc9f72 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -32,12 +32,12 @@ void ranking_function_training( return torch::relu(next - curr + delta); }; - #if 0 +#if 0 torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); - #endif - #if 1 +#endif +#if 1 torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.01); - #endif +#endif torch::Tensor last_loss = {}; @@ -49,7 +49,7 @@ void ranking_function_training( for(auto &batch : data) { //std::cout << "B: " << batch << "\n"; - + // Reset gradients. optimizer.zero_grad(); diff --git a/src/nuterm/vcd_parser.cpp b/src/nuterm/vcd_parser.cpp index 80bb988ff..b29423481 100644 --- a/src/nuterm/vcd_parser.cpp +++ b/src/nuterm/vcd_parser.cpp @@ -93,7 +93,7 @@ vcdt vcd_parser(std::istream &in) return vcd; } -std::ostream &operator << (std::ostream &out, const vcdt::statet &state) +std::ostream &operator<<(std::ostream &out, const vcdt::statet &state) { for(auto &[id, value] : state.changes) out << id << " = " << std::stoull(value, nullptr, 2) << '\n'; diff --git a/src/nuterm/vcd_parser.h b/src/nuterm/vcd_parser.h index 1949e7344..d9c7b591b 100644 --- a/src/nuterm/vcd_parser.h +++ b/src/nuterm/vcd_parser.h @@ -45,6 +45,6 @@ class vcdt std::vector full_trace() const; }; -std::ostream &operator << (std::ostream &, const vcdt::statet &); +std::ostream &operator<<(std::ostream &, const vcdt::statet &); vcdt vcd_parser(std::istream &); From 39222caa2945ce4eea81318a5c7e6e63ae355c2f Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 10:33:50 +0100 Subject: [PATCH 13/40] fx --- src/ebmc/neural_liveness.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index 3c897a570..ed70a7ca5 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -70,9 +70,6 @@ int neural_livenesst::operator()() if(cmdline.isset("show-traces")) return show_traces(); - if(!cmdline.isset("neural-engine")) - throw ebmc_errort() << "give a neural engine"; - transition_system = get_transition_system(cmdline, message.get_message_handler()); @@ -260,7 +257,8 @@ exprt neural_livenesst::guess( { message.status() << "Fitting a ranking function" << messaget::eom; - const auto engine = cmdline.get_value("neural-engine"); + const auto engine = cmdline.isset("neural-engine") ? cmdline.get_value("neural-engine") : "nuterm"; + temporary_filet engine_output("ebmc-neural", "txt"); const auto cmd = engine + " " + temp_dir.path + " | tee " + engine_output(); From 2d2f616a770410e6b9071a0dc900bff4b38a7f7e Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 10:33:56 +0100 Subject: [PATCH 14/40] fx --- src/ebmc/neural_liveness.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index ed70a7ca5..964531bad 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -257,7 +257,9 @@ exprt neural_livenesst::guess( { message.status() << "Fitting a ranking function" << messaget::eom; - const auto engine = cmdline.isset("neural-engine") ? cmdline.get_value("neural-engine") : "nuterm"; + const auto engine = cmdline.isset("neural-engine") + ? cmdline.get_value("neural-engine") + : "nuterm"; temporary_filet engine_output("ebmc-neural", "txt"); const auto cmd = engine + " " + temp_dir.path + " | tee " + engine_output(); From 0c6dc76993fc8c08f974718da98662495648a0e5 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 14:34:10 +0100 Subject: [PATCH 15/40] fx --- src/trans-netlist/trans_trace.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index bb73e33e7..48e356c42 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -522,6 +522,33 @@ std::string vcd_identifier(const std::string &id) result.erase(0, 9); else if(has_prefix(result, "smv::")) result.erase(0, 5); + + return result; +} + +/*******************************************************************\ + +Function: vcd_reference + + Inputs: + + Outputs: + + Purpose: + +\*******************************************************************/ + +std::string vcd_reference(const std::string &id, const std::string &prefix) +{ + std::string result=id; + + if((has_prefix(result, "verilog::")) || (has_prefix(result, "Verilog::"))) + result.erase(0, 9); + else if(has_prefix(result, "smv::")) + result.erase(0, 5); + + if(!prefix.empty() && has_prefix(result, prefix)) + result.erase(0, prefix.size()); return result; } @@ -727,7 +754,7 @@ void vcd_hierarchy_rec( << "$var " << signal_class << " " << width << " " << vcd_identifier(display_name) << " " - << vcd_identifier(display_name) + << vcd_reference(display_name, prefix) << (suffix==""?"":" ") << suffix << " $end" << '\n'; } @@ -781,7 +808,7 @@ void show_trans_trace_vcd( state.assignments.front().lhs.get(ID_identifier)); std::string module_name=id2string(symbol1.module); - out << "$scope module " << vcd_identifier(module_name) << " $end\n"; + out << "$scope module " << vcd_reference(module_name, "") << " $end\n"; // get identifiers std::set ids; From 607c86c609899a2f4f0198546b27a9eb48fab342 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 14:34:21 +0100 Subject: [PATCH 16/40] fx --- src/trans-netlist/trans_trace.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index 48e356c42..ff151260a 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -540,7 +540,7 @@ Function: vcd_reference std::string vcd_reference(const std::string &id, const std::string &prefix) { - std::string result=id; + std::string result = id; if((has_prefix(result, "verilog::")) || (has_prefix(result, "Verilog::"))) result.erase(0, 9); @@ -549,7 +549,7 @@ std::string vcd_reference(const std::string &id, const std::string &prefix) if(!prefix.empty() && has_prefix(result, prefix)) result.erase(0, prefix.size()); - + return result; } @@ -750,13 +750,10 @@ void vcd_hierarchy_rec( std::string suffix=vcd_suffix(symbol.type, ns); if(width>=1) - out << std::string(depth*2, ' ') - << "$var " << signal_class << " " - << width << " " - << vcd_identifier(display_name) << " " - << vcd_reference(display_name, prefix) - << (suffix==""?"":" ") << suffix - << " $end" << '\n'; + out << std::string(depth * 2, ' ') << "$var " << signal_class << " " + << width << " " << vcd_identifier(display_name) << " " + << vcd_reference(display_name, prefix) << (suffix == "" ? "" : " ") + << suffix << " $end" << '\n'; } // now do sub modules @@ -809,7 +806,7 @@ void show_trans_trace_vcd( std::string module_name=id2string(symbol1.module); out << "$scope module " << vcd_reference(module_name, "") << " $end\n"; - + // get identifiers std::set ids; From 4ee2039236db899bd08f8f8e05e0abe96ae50cbc Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 14:40:40 +0100 Subject: [PATCH 17/40] fx --- regression/nuterm/counters/counter1/trace.1 | 10 +++++----- regression/nuterm/counters/counter1/trace.10 | 10 +++++----- regression/nuterm/counters/counter1/trace.2 | 10 +++++----- regression/nuterm/counters/counter1/trace.3 | 10 +++++----- regression/nuterm/counters/counter1/trace.4 | 10 +++++----- regression/nuterm/counters/counter1/trace.5 | 10 +++++----- regression/nuterm/counters/counter1/trace.6 | 10 +++++----- regression/nuterm/counters/counter1/trace.7 | 10 +++++----- regression/nuterm/counters/counter1/trace.8 | 10 +++++----- regression/nuterm/counters/counter1/trace.9 | 10 +++++----- regression/nuterm/counters/counter2/trace.1 | 10 +++++----- regression/nuterm/counters/counter2/trace.10 | 10 +++++----- regression/nuterm/counters/counter2/trace.2 | 10 +++++----- regression/nuterm/counters/counter2/trace.3 | 10 +++++----- regression/nuterm/counters/counter2/trace.4 | 10 +++++----- regression/nuterm/counters/counter2/trace.5 | 10 +++++----- regression/nuterm/counters/counter2/trace.6 | 10 +++++----- regression/nuterm/counters/counter2/trace.7 | 10 +++++----- regression/nuterm/counters/counter2/trace.8 | 10 +++++----- regression/nuterm/counters/counter2/trace.9 | 10 +++++----- src/ebmc/neural_liveness.cpp | 8 +++++--- src/nuterm/nuterm_main.cpp | 3 +-- src/trans-netlist/trans_trace.cpp | 18 +++++++----------- 23 files changed, 113 insertions(+), 116 deletions(-) diff --git a/regression/nuterm/counters/counter1/trace.1 b/regression/nuterm/counters/counter1/trace.1 index 3a91c4202..1af7e66c1 100644 --- a/regression/nuterm/counters/counter1/trace.1 +++ b/regression/nuterm/counters/counter1/trace.1 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.10 b/regression/nuterm/counters/counter1/trace.10 index b5798ad99..626624665 100644 --- a/regression/nuterm/counters/counter1/trace.10 +++ b/regression/nuterm/counters/counter1/trace.10 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.2 b/regression/nuterm/counters/counter1/trace.2 index 3a099d3e4..f44f92b61 100644 --- a/regression/nuterm/counters/counter1/trace.2 +++ b/regression/nuterm/counters/counter1/trace.2 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.3 b/regression/nuterm/counters/counter1/trace.3 index 59212a28c..c29ec112a 100644 --- a/regression/nuterm/counters/counter1/trace.3 +++ b/regression/nuterm/counters/counter1/trace.3 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.4 b/regression/nuterm/counters/counter1/trace.4 index cbd274970..2ac811c05 100644 --- a/regression/nuterm/counters/counter1/trace.4 +++ b/regression/nuterm/counters/counter1/trace.4 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.5 b/regression/nuterm/counters/counter1/trace.5 index 5002aad3d..8b8bd4292 100644 --- a/regression/nuterm/counters/counter1/trace.5 +++ b/regression/nuterm/counters/counter1/trace.5 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.6 b/regression/nuterm/counters/counter1/trace.6 index f440f9faa..1c738b78e 100644 --- a/regression/nuterm/counters/counter1/trace.6 +++ b/regression/nuterm/counters/counter1/trace.6 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.7 b/regression/nuterm/counters/counter1/trace.7 index 4e6400954..678aabe59 100644 --- a/regression/nuterm/counters/counter1/trace.7 +++ b/regression/nuterm/counters/counter1/trace.7 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.8 b/regression/nuterm/counters/counter1/trace.8 index a8aab3951..268e77d99 100644 --- a/regression/nuterm/counters/counter1/trace.8 +++ b/regression/nuterm/counters/counter1/trace.8 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter1/trace.9 b/regression/nuterm/counters/counter1/trace.9 index e8ec4d445..ea30cc4ac 100644 --- a/regression/nuterm/counters/counter1/trace.9 +++ b/regression/nuterm/counters/counter1/trace.9 @@ -1,13 +1,13 @@ $date - Sun May 19 16:34:19 2024 + Mon May 20 14:40:33 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 index 1c3f6598b..91026c51c 100644 --- a/regression/nuterm/counters/counter2/trace.1 +++ b/regression/nuterm/counters/counter2/trace.1 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 index a8ccd20c3..d1f37d60b 100644 --- a/regression/nuterm/counters/counter2/trace.10 +++ b/regression/nuterm/counters/counter2/trace.10 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 index 3e6438e79..24902f176 100644 --- a/regression/nuterm/counters/counter2/trace.2 +++ b/regression/nuterm/counters/counter2/trace.2 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 index 11c5d28bd..fb89bd0cb 100644 --- a/regression/nuterm/counters/counter2/trace.3 +++ b/regression/nuterm/counters/counter2/trace.3 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 index 5cd763efc..d5003953b 100644 --- a/regression/nuterm/counters/counter2/trace.4 +++ b/regression/nuterm/counters/counter2/trace.4 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 index 9a7c7151c..543a5bf79 100644 --- a/regression/nuterm/counters/counter2/trace.5 +++ b/regression/nuterm/counters/counter2/trace.5 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 index 75c94e532..f1515ab6b 100644 --- a/regression/nuterm/counters/counter2/trace.6 +++ b/regression/nuterm/counters/counter2/trace.6 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 index a37f81b0f..5c5e3cf39 100644 --- a/regression/nuterm/counters/counter2/trace.7 +++ b/regression/nuterm/counters/counter2/trace.7 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 index 427bf9df1..6b55dc0e5 100644 --- a/regression/nuterm/counters/counter2/trace.8 +++ b/regression/nuterm/counters/counter2/trace.8 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 index 3a93263a4..9f740e09f 100644 --- a/regression/nuterm/counters/counter2/trace.9 +++ b/regression/nuterm/counters/counter2/trace.9 @@ -1,13 +1,13 @@ $date - Sun May 19 18:03:46 2024 + Mon May 20 14:40:09 2024 $end $timescale 1ns $end -$scope module main $end - $var wire 1 main.clk main.clk $end - $var reg 32 main.counter main.counter [31:0] $end - $var wire 1 main.nuterm::live main.nuterm::live $end +$scope module Verilog::main $end + $var wire 1 main.clk clk $end + $var reg 32 main.counter counter [31:0] $end + $var wire 1 main.nuterm::live nuterm::live $end $upscope $end $enddefinitions $end #0 diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index 964531bad..bd3cc3ccf 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -195,7 +195,7 @@ neural_livenesst::dump_vcd_files(temp_dirt &temp_dir) return [&, trace_nr = 0ull, outfile_prefix](trans_tracet trace) mutable -> void { namespacet ns(transition_system.symbol_table); - auto filename = outfile_prefix + std::to_string(trace_nr + 1); + auto filename = outfile_prefix + std::to_string(++trace_nr); std::ofstream out(widen_if_needed(filename)); if(!out) @@ -243,12 +243,14 @@ void neural_livenesst::sample(std::function trace_consumer) message.status() << "Sampling " << number_of_traces << " traces with " << number_of_trace_steps << " steps" << messaget::eom; + null_message_handlert null_message_handler; + random_traces( transition_system, trace_consumer, number_of_traces, number_of_trace_steps, - message.get_message_handler()); + null_message_handler); } exprt neural_livenesst::guess( @@ -276,7 +278,7 @@ exprt neural_livenesst::guess( if(!in) throw ebmc_errort() << "failed to open " << engine_output(); - std::string prefix = "Candidate: "; + std::string prefix = "RESULT: "; std::string line; while(std::getline(in, line)) { diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index f414aab8a..3b35ba042 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -169,8 +169,7 @@ std::vector traces_to_tensors( !is_live_state(liveness_signal, current) && !is_live_state(liveness_signal, next)) { - std::cout << "\n" << current << "---->\n" << next; - + // std::cout << "\n" << current << "---->\n" << next; auto tensor = state_pair_to_tensor(state_variables, current, next); assert(tensor.size(0) == 2); assert(tensor.size(1) == state_variables.size()); diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index ff151260a..d3db11a97 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -538,14 +538,9 @@ Function: vcd_reference \*******************************************************************/ -std::string vcd_reference(const std::string &id, const std::string &prefix) +std::string vcd_reference(const symbolt &symbol, const std::string &prefix) { - std::string result = id; - - if((has_prefix(result, "verilog::")) || (has_prefix(result, "Verilog::"))) - result.erase(0, 9); - else if(has_prefix(result, "smv::")) - result.erase(0, 5); + std::string result = id2string(symbol.name); if(!prefix.empty() && has_prefix(result, prefix)) result.erase(0, prefix.size()); @@ -752,7 +747,7 @@ void vcd_hierarchy_rec( if(width>=1) out << std::string(depth * 2, ' ') << "$var " << signal_class << " " << width << " " << vcd_identifier(display_name) << " " - << vcd_reference(display_name, prefix) << (suffix == "" ? "" : " ") + << vcd_reference(symbol, prefix) << (suffix == "" ? "" : " ") << suffix << " $end" << '\n'; } @@ -804,8 +799,9 @@ void show_trans_trace_vcd( const symbolt &symbol1=ns.lookup( state.assignments.front().lhs.get(ID_identifier)); - std::string module_name=id2string(symbol1.module); - out << "$scope module " << vcd_reference(module_name, "") << " $end\n"; + auto &module_symbol = ns.lookup(symbol1.module); + + out << "$scope module " << vcd_reference(module_symbol, "") << " $end\n"; // get identifiers std::set ids; @@ -817,7 +813,7 @@ void show_trans_trace_vcd( } // split up into hierarchy - vcd_hierarchy_rec(ns, ids, module_name+".", out, 1); + vcd_hierarchy_rec(ns, ids, id2string(module_symbol.name)+".", out, 1); out << "$upscope $end\n"; From 70618a09c04b25d0ec912e9ea93bc16f02b76353 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 14:40:46 +0100 Subject: [PATCH 18/40] fx --- src/trans-netlist/trans_trace.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index d3db11a97..2bb2a5a09 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -813,8 +813,8 @@ void show_trans_trace_vcd( } // split up into hierarchy - vcd_hierarchy_rec(ns, ids, id2string(module_symbol.name)+".", out, 1); - + vcd_hierarchy_rec(ns, ids, id2string(module_symbol.name) + ".", out, 1); + out << "$upscope $end\n"; out << "$enddefinitions $end\n"; From f6b58e0ceed57490c4f9cd5c85dffd487e7abcba Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 15:16:11 +0100 Subject: [PATCH 19/40] fx --- src/nuterm/nuterm_main.cpp | 61 ++++++++++++++++++++++++-------------- src/nuterm/vcd_parser.cpp | 13 +++++++- src/nuterm/vcd_parser.h | 11 +++++++ 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 3b35ba042..f68e60a3f 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -50,18 +50,33 @@ std::size_t number_of_transitions(const tracest &traces) return result; } -using state_variablest = std::map; +struct state_variablet +{ + std::size_t index; + std::string reference; +}; + +using state_variablest = std::map; state_variablest state_variables(const tracest &traces) { // number all identifiers - state_variablest identifiers; + state_variablest state_variables; + for(auto &trace : traces) - for(auto &state : trace.states) - for(auto &value_change : state.changes) - identifiers.emplace(value_change.first, identifiers.size()); + { + for(auto &[id, var] : trace.var_map) + { + if(state_variables.find(id) == state_variables.end()) + { + auto &state_variable = state_variables[id]; + state_variable.index = state_variables.size()-1; + state_variable.reference = var.reference; + } + } + } - return identifiers; + return state_variables; } bool has_suffix(const std::string &s, const std::string &suffix) @@ -94,13 +109,13 @@ torch::Tensor state_to_tensor( { std::vector data; data.resize(state_variables.size(), 0); - for(auto &var : state_variables) + for(auto &[id, var] : state_variables) { - if(has_suffix(var.first, ".clk")) + if(var.reference == "clk") continue; - auto v_it = state.changes.find(var.first); + auto v_it = state.changes.find(id); if(v_it != state.changes.end()) - data[var.second] = vcd_to_value(v_it->second); + data[var.index] = vcd_to_value(v_it->second); } return torch::tensor(data, torch::kFloat64); @@ -205,24 +220,24 @@ std::string ranking_net_to_string( auto weight = net->named_parameters()["fc1.weight"]; auto bias = net->named_parameters()["fc1.bias"]; - for(auto &var : state_variables) + for(auto &[id, var] : state_variables) { - assert(var.second < state_variables.size()); - long long weight_int = round(weight[0][var.second].item()); + assert(var.index < state_variables.size()); + long long weight_int = round(weight[0][var.index].item()); if(weight_int == 0) { } else if(weight_int == 1) { - terms.push_back(var.first); + terms.push_back(var.reference); } else if(weight_int == -1) { - terms.push_back("-" + var.first); + terms.push_back("-" + var.reference); } else { - terms.push_back(std::to_string(weight_int) + "*" + var.first); + terms.push_back(std::to_string(weight_int) + "*" + var.reference); } } @@ -253,8 +268,8 @@ int main(int argc, const char *argv[]) auto liveness_signal = ::liveness_signal(state_variables); - for(auto &v : state_variables) - std::cout << "V" << v.second << "=" << v.first << '\n'; + for(auto &[_, var] : state_variables) + std::cout << "V" << var.index << "=" << var.reference << '\n'; std::cout << "Liveness signal: " << liveness_signal << '\n'; @@ -299,12 +314,12 @@ int main(int argc, const char *argv[]) { auto weight = net->named_parameters()["fc1.weight"]; auto bias = net->named_parameters()["fc1.bias"]; - for(auto &var : state_variables) + for(auto &[_, var] : state_variables) { - assert(var.second < state_variables.size()); - std::cout << "weight " << var.first << " = " - << (long long)round(weight[0][var.second].item()) << ' ' - << weight[0][var.second].item() << '\n'; + assert(var.index < state_variables.size()); + std::cout << "weight " << var.reference << " = " + << (long long)round(weight[0][var.index].item()) << ' ' + << weight[0][var.index].item() << '\n'; } std::cout << "bias: " << (long long)(round(bias.item())) << ' ' diff --git a/src/nuterm/vcd_parser.cpp b/src/nuterm/vcd_parser.cpp index b29423481..b1aae773f 100644 --- a/src/nuterm/vcd_parser.cpp +++ b/src/nuterm/vcd_parser.cpp @@ -34,12 +34,23 @@ static std::string vcd_token(std::istream &in) return token; } -void vcd_command(vcdt &, const std::string &token, std::istream &in) +void vcd_command(vcdt &vcd, const std::string &token, std::istream &in) { + if(token == "$var") + { + vcdt::vart var; + var.type = vcd_token(in); + var.size = std::stoull(vcd_token(in)); + var.id = vcd_token(in); + var.reference = vcd_token(in); + vcd.var_map[var.id] = std::move(var); + } + // look for $end while(true) { auto t = vcd_token(in); + if(t.empty() || t == "$end") return; } diff --git a/src/nuterm/vcd_parser.h b/src/nuterm/vcd_parser.h index d9c7b591b..b009278e3 100644 --- a/src/nuterm/vcd_parser.h +++ b/src/nuterm/vcd_parser.h @@ -14,6 +14,17 @@ Author: Daniel Kroening, dkr@amazon.com class vcdt { public: + struct vart + { + std::string type; + std::size_t size; + std::string id; + std::string reference; + }; + + using var_mapt = std::map; + var_mapt var_map; + using value_mapt = std::map; struct statet From a476d73d64235642c23b4677aa20623eaf2c3c98 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 15:16:21 +0100 Subject: [PATCH 20/40] fx --- src/nuterm/nuterm_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index f68e60a3f..b69e483dc 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -70,7 +70,7 @@ state_variablest state_variables(const tracest &traces) if(state_variables.find(id) == state_variables.end()) { auto &state_variable = state_variables[id]; - state_variable.index = state_variables.size()-1; + state_variable.index = state_variables.size() - 1; state_variable.reference = var.reference; } } From 6bcad1784a7aae7f9069da601974afcd1d4349f3 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 15:49:12 +0100 Subject: [PATCH 21/40] fx --- src/nuterm/nuterm_main.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index b69e483dc..551ecd3fb 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -88,11 +88,6 @@ bool has_suffix(const std::string &s, const std::string &suffix) return false; } -bool is_live_signal(const std::string &identifier) -{ - return has_suffix(identifier, "nuterm::live"); -} - #include double vcd_to_value(const std::string &src) @@ -150,11 +145,13 @@ bool is_live_state( std::string liveness_signal(const state_variablest &state_variables) { - for(auto &[name, _] : state_variables) - if(is_live_signal(name)) - return name; + for(auto &[id, var] : state_variables) + if(var.reference == "nuterm::live") + return id; + std::cout.flush(); std::cerr << "failed to find liveness signal" << '\n'; + abort(); } From 296f79d5f3a9ab868fbf1d44c5cffbc768ed6014 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 16:06:09 +0100 Subject: [PATCH 22/40] fx --- src/ebmc/live_signal.cpp | 8 ++++---- src/ebmc/live_signal.h | 4 ++-- src/ebmc/neural_liveness.cpp | 12 +++++++----- src/nuterm/nuterm_main.cpp | 6 ++++-- src/trans-netlist/trans_trace.cpp | 18 +++++++++++------- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/ebmc/live_signal.cpp b/src/ebmc/live_signal.cpp index a0f8bc029..0f739eb8d 100644 --- a/src/ebmc/live_signal.cpp +++ b/src/ebmc/live_signal.cpp @@ -1,6 +1,6 @@ /*******************************************************************\ -Module: Live Signal +Module: Liveness Signal Author: Daniel Kroening, dkr@amazon.com @@ -13,9 +13,9 @@ Author: Daniel Kroening, dkr@amazon.com #include "transition_system.h" -void set_live_signal(transition_systemt &transition_system, exprt property) +void set_liveness_signal(transition_systemt &transition_system, exprt property) { - static const irep_idt identifier = "nuterm::live"; + static const irep_idt identifier = id2string(transition_system.main_symbol->name) + ".$live"; // add symbol if needed if(!transition_system.symbol_table.has_symbol(identifier)) @@ -24,7 +24,7 @@ void set_live_signal(transition_systemt &transition_system, exprt property) identifier, bool_typet(), transition_system.main_symbol->mode}; live_symbol.module = transition_system.main_symbol->module; - live_symbol.base_name = "live"; + live_symbol.base_name = "$live"; const auto symbol_expr = live_symbol.symbol_expr(); diff --git a/src/ebmc/live_signal.h b/src/ebmc/live_signal.h index 4bc7a5246..5a8dba8c0 100644 --- a/src/ebmc/live_signal.h +++ b/src/ebmc/live_signal.h @@ -1,6 +1,6 @@ /*******************************************************************\ -Module: Live Signal +Module: Liveness Signal Author: Daniel Kroening, dkr@amazon.com @@ -13,6 +13,6 @@ Author: Daniel Kroening, dkr@amazon.com class transition_systemt; -void set_live_signal(transition_systemt &, exprt property); +void set_liveness_signal(transition_systemt &, exprt property); #endif // EBMC_LIVE_SIGNAL_H diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index bd3cc3ccf..f89fbe177 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -58,7 +58,7 @@ class neural_livenesst int show_traces(); void validate_properties(); - void set_live_signal(const ebmc_propertiest::propertyt &, const exprt &); + void set_liveness_signal(const ebmc_propertiest::propertyt &, const exprt &); void sample(std::function); std::function dump_vcd_files(temp_dirt &); exprt guess(ebmc_propertiest::propertyt &, const temp_dirt &); @@ -94,7 +94,7 @@ int neural_livenesst::operator()() continue; // Set the liveness signal for the property. - set_live_signal(property, original_trans_expr); + set_liveness_signal(property, original_trans_expr); // Now sample some traces. // Store the traces in a set of files, one per @@ -110,6 +110,8 @@ int neural_livenesst::operator()() if(verify(property, candidate).is_true()) break; + + throw ebmc_errort() << "giving up"; } } @@ -136,7 +138,7 @@ int neural_livenesst::show_traces() if(property.is_disabled()) continue; - set_live_signal(property, original_trans_expr); + set_liveness_signal(property, original_trans_expr); sample([&](trans_tracet trace) { namespacet ns(transition_system.symbol_table); @@ -177,7 +179,7 @@ void neural_livenesst::validate_properties() } } -void neural_livenesst::set_live_signal( +void neural_livenesst::set_liveness_signal( const ebmc_propertiest::propertyt &property, const exprt &original_trans_expr) { @@ -185,7 +187,7 @@ void neural_livenesst::set_live_signal( auto main_symbol_writeable = transition_system.symbol_table.get_writeable( transition_system.main_symbol->name); main_symbol_writeable->value = original_trans_expr; // copy - ::set_live_signal(transition_system, property.normalized_expr); + ::set_liveness_signal(transition_system, property.normalized_expr); } std::function diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 551ecd3fb..a723182af 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -32,11 +32,13 @@ tracest read_traces(const std::string &path) for(const auto &entry : file_names) { - std::cout << "Reading " << entry << '\n'; + //std::cout << "Reading " << entry << '\n'; std::ifstream in(entry); traces.push_back(vcd_parser(in)); } + std::cout << "Read " << traces.size() << " trace files\n"; + return traces; } @@ -146,7 +148,7 @@ bool is_live_state( std::string liveness_signal(const state_variablest &state_variables) { for(auto &[id, var] : state_variables) - if(var.reference == "nuterm::live") + if(var.reference == "$live") return id; std::cout.flush(); diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index 2bb2a5a09..f9aac3f2e 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -796,13 +796,6 @@ void show_trans_trace_vcd( assert(!state.assignments.empty()); - const symbolt &symbol1=ns.lookup( - state.assignments.front().lhs.get(ID_identifier)); - - auto &module_symbol = ns.lookup(symbol1.module); - - out << "$scope module " << vcd_reference(module_symbol, "") << " $end\n"; - // get identifiers std::set ids; @@ -811,7 +804,18 @@ void show_trans_trace_vcd( assert(a.lhs.id()==ID_symbol); ids.insert(to_symbol_expr(a.lhs).get_identifier()); } + + // determine module + + const symbolt &symbol1=ns.lookup( + state.assignments.front().lhs.get(ID_identifier)); + + auto &module_symbol = ns.lookup(symbol1.module); + + // print those in the top module + out << "$scope module " << vcd_reference(module_symbol, "") << " $end\n"; + // split up into hierarchy vcd_hierarchy_rec(ns, ids, id2string(module_symbol.name) + ".", out, 1); From 211f0bcaf9cae3a4c7f7eb19e78484f03eff037d Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 16:15:53 +0100 Subject: [PATCH 23/40] fx --- src/nuterm/nuterm_main.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index a723182af..2a984f1be 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -230,18 +230,21 @@ std::string ranking_net_to_string( { terms.push_back(var.reference); } - else if(weight_int == -1) - { - terms.push_back("-" + var.reference); - } else { - terms.push_back(std::to_string(weight_int) + "*" + var.reference); + if(weight_int >= 0) + terms.push_back(std::to_string(weight_int) + "*" + var.reference); + else + { + // make signed, but first add a bit + terms.push_back(std::to_string(weight_int) + "*$signed({1'b0," + var.reference +"})"); + } } } long long bias_int = round(bias.item()); - terms.push_back(std::to_string(bias_int)); + if(bias_int != 0) + terms.push_back(std::to_string(bias_int)); return sum(terms); } From 9a8d586da07443f64fb52c17a1f1c81fb14bb5ae Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 16:34:15 +0100 Subject: [PATCH 24/40] fx --- examples/Benchmarks/run_nuterm | 151 +++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 examples/Benchmarks/run_nuterm diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm new file mode 100755 index 000000000..17463d07e --- /dev/null +++ b/examples/Benchmarks/run_nuterm @@ -0,0 +1,151 @@ +#!/bin/sh + +set -e + +if false ; then +ebmc PWM_1.sv --neural-liveness "2**10-cntR" +ebmc PWM_2.sv --neural-liveness "2**11-cntR" +ebmc PWM_3.sv --neural-liveness "2**12-cntR" +ebmc PWM_4.sv --neural-liveness "2**13-cntR" +ebmc PWM_5.sv --neural-liveness "2**14-cntR" +ebmc PWM_6.sv --neural-liveness "2**15-cntR" +ebmc PWM_7.sv --neural-liveness "2**16-cntR" +ebmc PWM_8.sv --neural-liveness "2**17-cntR" +ebmc PWM_9.sv --neural-liveness "2**18-cntR" +fi + +if false ; then +ebmc delay_1.sv --neural-liveness "750-cnt" +ebmc delay_2.sv --neural-liveness "1250-cnt" +ebmc delay_3.sv --neural-liveness "2500-cnt" +ebmc delay_4.sv --neural-liveness "5000-cnt" +ebmc delay_5.sv --neural-liveness "7500-cnt" +ebmc delay_6.sv --neural-liveness "10000-cnt" +ebmc delay_7.sv --neural-liveness "12500-cnt" +ebmc delay_8.sv --neural-liveness "15000-cnt" +ebmc delay_9.sv --neural-liveness "17500-cnt" +ebmc delay_10.sv --neural-liveness "20000-cnt" +ebmc delay_11.sv --neural-liveness "22500-cnt" +ebmc delay_12.sv --neural-liveness "25000-cnt" +ebmc delay_13.sv --neural-liveness "50000-cnt" +ebmc delay_14.sv --neural-liveness "100000-cnt" +ebmc delay_15.sv --neural-liveness "200000-cnt" +ebmc delay_16.sv --neural-liveness "400000-cnt" +fi + +if false ; then +ebmc gray_1.sv --neural-liveness "2**8-cnt" +ebmc gray_2.sv --neural-liveness "2**9-cnt" +ebmc gray_3.sv --neural-liveness "2**10-cnt" +ebmc gray_4.sv --neural-liveness "2**11-cnt" +ebmc gray_5.sv --neural-liveness "2**12-cnt" +ebmc gray_6.sv --neural-liveness "2**13-cnt" +ebmc gray_7.sv --neural-liveness "2**14-cnt" +ebmc gray_8.sv --neural-liveness "2**15-cnt" +ebmc gray_9.sv --neural-liveness "2**16-cnt" +ebmc gray_10.sv --neural-liveness "2**17-cnt" +ebmc gray_11.sv --neural-liveness "2**18-cnt" +fi + +if false ; then +ebmc i2c_1.sv --neural-liveness "2**9-cnt" +ebmc i2c_2.sv --neural-liveness "2**10-cnt" +ebmc i2c_3.sv --neural-liveness "2**11-cnt" +ebmc i2c_4.sv --neural-liveness "2**12-cnt" +ebmc i2c_5.sv --neural-liveness "2**13-cnt" +ebmc i2c_6.sv --neural-liveness "2**14-cnt" +ebmc i2c_7.sv --neural-liveness "2**15-cnt" +ebmc i2c_8.sv --neural-liveness "2**16-cnt" +ebmc i2c_9.sv --neural-liveness "2**17-cnt" +ebmc i2c_10.sv --neural-liveness "2**18-cnt" +ebmc i2c_11.sv --neural-liveness "2**19-cnt" +ebmc i2c_12.sv --neural-liveness "2**10-cnt" +ebmc i2c_13.sv --neural-liveness "2**10-cnt" +ebmc i2c_14.sv --neural-liveness "2**10-cnt" +ebmc i2c_15.sv --neural-liveness "2**10-cnt" +ebmc i2c_16.sv --neural-liveness "2**10-cnt" +ebmc i2c_17.sv --neural-liveness "2**10-cnt" +ebmc i2c_18.sv --neural-liveness "2**10-cnt" +ebmc i2c_19.sv --neural-liveness "2**10-cnt" +ebmc i2c_20.sv --neural-liveness "2**19-cnt" +fi + +if false ; then +ebmc lcd_1.sv --neural-liveness "{3-state,500-cnt}" +ebmc lcd_2.sv --neural-liveness "{3-state,1000-cnt}" +ebmc lcd_3.sv --neural-liveness "{3-state,1500-cnt}" +ebmc lcd_4.sv --neural-liveness "{3-state,2500-cnt}" +ebmc lcd_5.sv --neural-liveness "{3-state,5000-cnt}" +ebmc lcd_6.sv --neural-liveness "{3-state,7500-cnt}" +ebmc lcd_7.sv --neural-liveness "{3-state,10000-cnt}" +ebmc lcd_8.sv --neural-liveness "{3-state,12500-cnt}" +ebmc lcd_9.sv --neural-liveness "{3-state,15000-cnt}" +ebmc lcd_10.sv --neural-liveness "{3-state,17500-cnt}" +ebmc lcd_11.sv --neural-liveness "{3-state,20000-cnt}" +ebmc lcd_12.sv --neural-liveness "{3-state,22500-cnt}" +ebmc lcd_13.sv --neural-liveness "{3-state,90000-cnt}" +ebmc lcd_14.sv --neural-liveness "{3-state,180000-cnt}" +fi + +ebmc seven_seg_1.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_2.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_3.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_4.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_5.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_6.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_7.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_8.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_9.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_10.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_11.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_12.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_16.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_17.sv --neural-liveness --property SEVEN.property.p1 +ebmc seven_seg_18.sv --neural-liveness --property SEVEN.property.p1 + +if false ; then +ebmc thermocouple_1.sv --neural-liveness "{2-state,2**5-cnt}" +ebmc thermocouple_2.sv --neural-liveness "{2-state,2**9-cnt}" +ebmc thermocouple_3.sv --neural-liveness "{2-state,2**10-cnt}" +ebmc thermocouple_4.sv --neural-liveness "{2-state,2**10-cnt}" +ebmc thermocouple_5.sv --neural-liveness "{2-state,2**11-cnt}" +ebmc thermocouple_6.sv --neural-liveness "{2-state,2**11-cnt}" +ebmc thermocouple_7.sv --neural-liveness "{2-state,2**12-cnt}" +ebmc thermocouple_8.sv --neural-liveness "{2-state,2**12-cnt}" +ebmc thermocouple_9.sv --neural-liveness "{2-state,2**13-cnt}" +ebmc thermocouple_10.sv --neural-liveness "{2-state,2**14-cnt}" +ebmc thermocouple_11.sv --neural-liveness "{2-state,2**14-cnt}" +ebmc thermocouple_12.sv --neural-liveness "{2-state,2**14-cnt}" +ebmc thermocouple_13.sv --neural-liveness "{2-state,2**15-cnt}" +ebmc thermocouple_14.sv --neural-liveness "{2-state,2**16-cnt}" +ebmc thermocouple_15.sv --neural-liveness "{2-state,2**17-cnt}" +ebmc thermocouple_16.sv --neural-liveness "{2-state,2**18-cnt}" +ebmc thermocouple_17.sv --neural-liveness "{2-state,2**19-cnt}" +fi + +if false ; then +ebmc uart_transmit_1.sv --neural-liveness "2**3-tx_cnt" +ebmc uart_transmit_2.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_3.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_4.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_5.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_6.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_7.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_8.sv --neural-liveness "2**4-tx_cnt" +ebmc uart_transmit_9.sv --neural-liveness "2**5-tx_cnt" +ebmc uart_transmit_10.sv --neural-liveness "2**5-tx_cnt" +ebmc uart_transmit_11.sv --neural-liveness "2**5-tx_cnt" +ebmc uart_transmit_12.sv --neural-liveness "2**6-tx_cnt" +fi + +if false ; then +ebmc vga_1.sv --neural-liveness "{2**5-v_cnt,2**7-h_cnt}" +ebmc vga_2.sv --neural-liveness "{2**6-v_cnt,2**8-h_cnt}" +ebmc vga_3.sv --neural-liveness "{2**6-v_cnt,2**8-h_cnt}" +ebmc vga_4.sv --neural-liveness "{2**7-v_cnt,2**9-h_cnt}" +ebmc vga_5.sv --neural-liveness "{2**8-v_cnt,2**9-h_cnt}" +ebmc vga_6.sv --neural-liveness "{2**8-v_cnt,2**9-h_cnt}" +ebmc vga_7.sv --neural-liveness "{2**8-v_cnt,2**10-h_cnt}" +ebmc vga_8.sv --neural-liveness "{2**9-v_cnt,2**10-h_cnt}" +ebmc vga_9.sv --neural-liveness "{2**9-v_cnt,2**11-h_cnt}" +fi From aaf6f83dd990c303223dcee7b21575075fe7e0a6 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 16:41:29 +0100 Subject: [PATCH 25/40] fx --- examples/Benchmarks/run_nuterm | 50 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm index 17463d07e..99b429d05 100755 --- a/examples/Benchmarks/run_nuterm +++ b/examples/Benchmarks/run_nuterm @@ -33,19 +33,17 @@ ebmc delay_15.sv --neural-liveness "200000-cnt" ebmc delay_16.sv --neural-liveness "400000-cnt" fi -if false ; then -ebmc gray_1.sv --neural-liveness "2**8-cnt" -ebmc gray_2.sv --neural-liveness "2**9-cnt" -ebmc gray_3.sv --neural-liveness "2**10-cnt" -ebmc gray_4.sv --neural-liveness "2**11-cnt" -ebmc gray_5.sv --neural-liveness "2**12-cnt" -ebmc gray_6.sv --neural-liveness "2**13-cnt" -ebmc gray_7.sv --neural-liveness "2**14-cnt" -ebmc gray_8.sv --neural-liveness "2**15-cnt" -ebmc gray_9.sv --neural-liveness "2**16-cnt" -ebmc gray_10.sv --neural-liveness "2**17-cnt" -ebmc gray_11.sv --neural-liveness "2**18-cnt" -fi +ebmc gray_1.sv --neural-liveness +ebmc gray_2.sv --neural-liveness +ebmc gray_3.sv --neural-liveness +ebmc gray_4.sv --neural-liveness +ebmc gray_5.sv --neural-liveness +ebmc gray_6.sv --neural-liveness +ebmc gray_7.sv --neural-liveness +ebmc gray_8.sv --neural-liveness +ebmc gray_9.sv --neural-liveness +ebmc gray_10.sv --neural-liveness +ebmc gray_11.sv --neural-liveness if false ; then ebmc i2c_1.sv --neural-liveness "2**9-cnt" @@ -123,20 +121,18 @@ ebmc thermocouple_16.sv --neural-liveness "{2-state,2**18-cnt}" ebmc thermocouple_17.sv --neural-liveness "{2-state,2**19-cnt}" fi -if false ; then -ebmc uart_transmit_1.sv --neural-liveness "2**3-tx_cnt" -ebmc uart_transmit_2.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_3.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_4.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_5.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_6.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_7.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_8.sv --neural-liveness "2**4-tx_cnt" -ebmc uart_transmit_9.sv --neural-liveness "2**5-tx_cnt" -ebmc uart_transmit_10.sv --neural-liveness "2**5-tx_cnt" -ebmc uart_transmit_11.sv --neural-liveness "2**5-tx_cnt" -ebmc uart_transmit_12.sv --neural-liveness "2**6-tx_cnt" -fi +ebmc uart_transmit_1.sv --neural-liveness +ebmc uart_transmit_2.sv --neural-liveness +ebmc uart_transmit_3.sv --neural-liveness +ebmc uart_transmit_4.sv --neural-liveness +ebmc uart_transmit_5.sv --neural-liveness +ebmc uart_transmit_6.sv --neural-liveness +ebmc uart_transmit_7.sv --neural-liveness +ebmc uart_transmit_8.sv --neural-liveness +ebmc uart_transmit_9.sv --neural-liveness +ebmc uart_transmit_10.sv --neural-liveness +ebmc uart_transmit_11.sv --neural-liveness +ebmc uart_transmit_12.sv --neural-liveness if false ; then ebmc vga_1.sv --neural-liveness "{2**5-v_cnt,2**7-h_cnt}" From 1ca2bdc2fc8a1d3c6164050090308bbbdd11868d Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 17:30:55 +0100 Subject: [PATCH 26/40] fx --- examples/Benchmarks/run_nuterm | 44 ++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm index 99b429d05..ba0b27400 100755 --- a/examples/Benchmarks/run_nuterm +++ b/examples/Benchmarks/run_nuterm @@ -2,17 +2,15 @@ set -e -if false ; then -ebmc PWM_1.sv --neural-liveness "2**10-cntR" -ebmc PWM_2.sv --neural-liveness "2**11-cntR" -ebmc PWM_3.sv --neural-liveness "2**12-cntR" -ebmc PWM_4.sv --neural-liveness "2**13-cntR" -ebmc PWM_5.sv --neural-liveness "2**14-cntR" -ebmc PWM_6.sv --neural-liveness "2**15-cntR" -ebmc PWM_7.sv --neural-liveness "2**16-cntR" -ebmc PWM_8.sv --neural-liveness "2**17-cntR" -ebmc PWM_9.sv --neural-liveness "2**18-cntR" -fi +ebmc PWM_1.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 +ebmc PWM_2.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 +ebmc PWM_3.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 +ebmc PWM_4.sv --neural-liveness --trace-steps 5000 --number-of-traces 1 +ebmc PWM_5.sv --neural-liveness --trace-steps 10000 --number-of-traces 1 +ebmc PWM_6.sv --neural-liveness --trace-steps 20000 --number-of-traces 1 +ebmc PWM_7.sv --neural-liveness --trace-steps 40000 --number-of-traces 1 +ebmc PWM_8.sv --neural-liveness --trace-steps 80000 --number-of-traces 1 +ebmc PWM_9.sv --neural-liveness --trace-steps 160000 --number-of-traces 1 if false ; then ebmc delay_1.sv --neural-liveness "750-cnt" @@ -121,18 +119,18 @@ ebmc thermocouple_16.sv --neural-liveness "{2-state,2**18-cnt}" ebmc thermocouple_17.sv --neural-liveness "{2-state,2**19-cnt}" fi -ebmc uart_transmit_1.sv --neural-liveness -ebmc uart_transmit_2.sv --neural-liveness -ebmc uart_transmit_3.sv --neural-liveness -ebmc uart_transmit_4.sv --neural-liveness -ebmc uart_transmit_5.sv --neural-liveness -ebmc uart_transmit_6.sv --neural-liveness -ebmc uart_transmit_7.sv --neural-liveness -ebmc uart_transmit_8.sv --neural-liveness -ebmc uart_transmit_9.sv --neural-liveness -ebmc uart_transmit_10.sv --neural-liveness -ebmc uart_transmit_11.sv --neural-liveness -ebmc uart_transmit_12.sv --neural-liveness +ebmc uart_transmit_1.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_2.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_3.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_4.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_5.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_6.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_7.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_8.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_9.sv --neural-liveness --trace-steps 100 --number-of-traces 20 +ebmc uart_transmit_10.sv --neural-liveness --trace-steps 200 --number-of-traces 20 +ebmc uart_transmit_11.sv --neural-liveness --trace-steps 200 --number-of-traces 20 +ebmc uart_transmit_12.sv --neural-liveness --trace-steps 200 --number-of-traces 20 if false ; then ebmc vga_1.sv --neural-liveness "{2**5-v_cnt,2**7-h_cnt}" From 390498223a1417636061ae708347572b19788961 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 17:35:17 +0100 Subject: [PATCH 27/40] fx --- regression/ebmc/neural-liveness/counter1.desc | 2 +- .../ebmc/neural-liveness/live_signal1.desc | 22 +++++++++---------- src/nuterm/nuterm_main.cpp | 5 +++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/regression/ebmc/neural-liveness/counter1.desc b/regression/ebmc/neural-liveness/counter1.desc index 55f0ccc5a..8e434f9d6 100644 --- a/regression/ebmc/neural-liveness/counter1.desc +++ b/regression/ebmc/neural-liveness/counter1.desc @@ -1,6 +1,6 @@ CORE counter1.sv ---number-of-traces 2 --neural-liveness --neural-engine "echo Candidate: counter\\\\n" +--number-of-traces 2 --neural-liveness --neural-engine "echo RESULT: counter\\\\n" ^\[main\.property\.p0\] always s_eventually main.counter == 0: PROVED$ ^EXIT=0$ ^SIGNAL=0$ diff --git a/regression/ebmc/neural-liveness/live_signal1.desc b/regression/ebmc/neural-liveness/live_signal1.desc index 8a3768dd8..abb70683a 100644 --- a/regression/ebmc/neural-liveness/live_signal1.desc +++ b/regression/ebmc/neural-liveness/live_signal1.desc @@ -1,17 +1,17 @@ CORE counter1.sv --number-of-traces 1 --neural-liveness --show-traces -^nuterm::live@0 = 0$ -^nuterm::live@1 = 0$ -^nuterm::live@2 = 0$ -^nuterm::live@3 = 0$ -^nuterm::live@4 = 0$ -^nuterm::live@5 = 0$ -^nuterm::live@6 = 0$ -^nuterm::live@7 = 0$ -^nuterm::live@8 = 0$ -^nuterm::live@9 = 0$ -^nuterm::live@10 = 1$ +^Verilog::main\.\$live@0 = 0$ +^Verilog::main\.\$live@1 = 0$ +^Verilog::main\.\$live@2 = 0$ +^Verilog::main\.\$live@3 = 0$ +^Verilog::main\.\$live@4 = 0$ +^Verilog::main\.\$live@5 = 0$ +^Verilog::main\.\$live@6 = 0$ +^Verilog::main\.\$live@7 = 0$ +^Verilog::main\.\$live@8 = 0$ +^Verilog::main\.\$live@9 = 0$ +^Verilog::main\.\$live@10 = 1$ ^EXIT=0$ ^SIGNAL=0$ -- diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 2a984f1be..3a8bf919b 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -282,6 +282,11 @@ int main(int argc, const char *argv[]) std::cout << "Got " << tensors.size() << " transitions to rank\n"; + if(tensors.empty()) + { + return 0; + } + const auto net = std::make_shared(state_variables.size()); #if 0 From 26d49636e3cc50a29aa4c8d8d922ed295dc15ff9 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 17:43:48 +0100 Subject: [PATCH 28/40] fx --- regression/nuterm/counters/counter1.desc | 8 ++++---- regression/nuterm/counters/counter1.v | 2 +- regression/nuterm/counters/counter1/trace.1 | 6 +++--- regression/nuterm/counters/counter1/trace.10 | 6 +++--- regression/nuterm/counters/counter1/trace.2 | 6 +++--- regression/nuterm/counters/counter1/trace.3 | 6 +++--- regression/nuterm/counters/counter1/trace.4 | 6 +++--- regression/nuterm/counters/counter1/trace.5 | 6 +++--- regression/nuterm/counters/counter1/trace.6 | 6 +++--- regression/nuterm/counters/counter1/trace.7 | 6 +++--- regression/nuterm/counters/counter1/trace.8 | 6 +++--- regression/nuterm/counters/counter1/trace.9 | 6 +++--- regression/nuterm/counters/counter2.desc | 8 ++++---- regression/nuterm/counters/counter2.v | 2 +- regression/nuterm/counters/counter2/trace.1 | 10 +++++----- regression/nuterm/counters/counter2/trace.10 | 10 +++++----- regression/nuterm/counters/counter2/trace.2 | 10 +++++----- regression/nuterm/counters/counter2/trace.3 | 10 +++++----- regression/nuterm/counters/counter2/trace.4 | 10 +++++----- regression/nuterm/counters/counter2/trace.5 | 10 +++++----- regression/nuterm/counters/counter2/trace.6 | 10 +++++----- regression/nuterm/counters/counter2/trace.7 | 10 +++++----- regression/nuterm/counters/counter2/trace.8 | 10 +++++----- regression/nuterm/counters/counter2/trace.9 | 10 +++++----- src/ebmc/live_signal.cpp | 3 ++- src/nuterm/nuterm_main.cpp | 4 +++- src/trans-netlist/trans_trace.cpp | 6 +++--- 27 files changed, 98 insertions(+), 95 deletions(-) diff --git a/regression/nuterm/counters/counter1.desc b/regression/nuterm/counters/counter1.desc index fb18fddcf..b97a3bb09 100644 --- a/regression/nuterm/counters/counter1.desc +++ b/regression/nuterm/counters/counter1.desc @@ -1,9 +1,9 @@ CORE counter1 -^weight main.clk = 0 .*$ -^weight main.counter = 1 .*$ -^RESULT: main.counter-1$ -^bias: -1 .*$ +^weight clk = 0 .*$ +^weight counter = 1 .*$ +^bias: 0 .*$ +^RESULT: counter$ ^EXIT=0$ ^SIGNAL=0$ diff --git a/regression/nuterm/counters/counter1.v b/regression/nuterm/counters/counter1.v index 9164ef2b3..ce683060c 100644 --- a/regression/nuterm/counters/counter1.v +++ b/regression/nuterm/counters/counter1.v @@ -6,6 +6,6 @@ module main(input clk); if(counter != 0) counter = counter - 1; - wire \nuterm::live = counter == 0; + wire \$live = counter == 0; endmodule diff --git a/regression/nuterm/counters/counter1/trace.1 b/regression/nuterm/counters/counter1/trace.1 index 1af7e66c1..019800113 100644 --- a/regression/nuterm/counters/counter1/trace.1 +++ b/regression/nuterm/counters/counter1/trace.1 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.10 b/regression/nuterm/counters/counter1/trace.10 index 626624665..14af98364 100644 --- a/regression/nuterm/counters/counter1/trace.10 +++ b/regression/nuterm/counters/counter1/trace.10 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.2 b/regression/nuterm/counters/counter1/trace.2 index f44f92b61..6d6433de1 100644 --- a/regression/nuterm/counters/counter1/trace.2 +++ b/regression/nuterm/counters/counter1/trace.2 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 b00001111111111111111111111111111 main.counter #2 diff --git a/regression/nuterm/counters/counter1/trace.3 b/regression/nuterm/counters/counter1/trace.3 index c29ec112a..68b813118 100644 --- a/regression/nuterm/counters/counter1/trace.3 +++ b/regression/nuterm/counters/counter1/trace.3 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 0main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.4 b/regression/nuterm/counters/counter1/trace.4 index 2ac811c05..d9b50731b 100644 --- a/regression/nuterm/counters/counter1/trace.4 +++ b/regression/nuterm/counters/counter1/trace.4 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.5 b/regression/nuterm/counters/counter1/trace.5 index 8b8bd4292..21cbd62ac 100644 --- a/regression/nuterm/counters/counter1/trace.5 +++ b/regression/nuterm/counters/counter1/trace.5 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 b00001111111111111111111111111111 main.counter #2 diff --git a/regression/nuterm/counters/counter1/trace.6 b/regression/nuterm/counters/counter1/trace.6 index 1c738b78e..936aff9d8 100644 --- a/regression/nuterm/counters/counter1/trace.6 +++ b/regression/nuterm/counters/counter1/trace.6 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.7 b/regression/nuterm/counters/counter1/trace.7 index 678aabe59..fda15d36b 100644 --- a/regression/nuterm/counters/counter1/trace.7 +++ b/regression/nuterm/counters/counter1/trace.7 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 b00001111111111111111111111111111 main.counter #2 diff --git a/regression/nuterm/counters/counter1/trace.8 b/regression/nuterm/counters/counter1/trace.8 index 268e77d99..86ee47095 100644 --- a/regression/nuterm/counters/counter1/trace.8 +++ b/regression/nuterm/counters/counter1/trace.8 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter1/trace.9 b/regression/nuterm/counters/counter1/trace.9 index ea30cc4ac..562f94619 100644 --- a/regression/nuterm/counters/counter1/trace.9 +++ b/regression/nuterm/counters/counter1/trace.9 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:33 2024 + Mon May 20 17:39:58 2024 $end $timescale 1ns @@ -7,13 +7,13 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b00010000000000000000000000000000 main.counter -0main.nuterm::live +0main.$live #1 0main.clk b00001111111111111111111111111111 main.counter diff --git a/regression/nuterm/counters/counter2.desc b/regression/nuterm/counters/counter2.desc index c52f96ca9..d62db8dfd 100644 --- a/regression/nuterm/counters/counter2.desc +++ b/regression/nuterm/counters/counter2.desc @@ -1,9 +1,9 @@ CORE counter2 -^weight main.clk = 0 .*$ -^weight main.counter = 1 .*$ -^RESULT: main.counter-1$ -^bias: -1 .*$ +^weight clk = 0 .*$ +^weight counter = -1 .*$ +^bias: 0 .*$ +^RESULT: -1\*\$signed\(\{1'b0,counter\}\)$ ^EXIT=0$ ^SIGNAL=0$ diff --git a/regression/nuterm/counters/counter2.v b/regression/nuterm/counters/counter2.v index b9bf1c637..367de8228 100644 --- a/regression/nuterm/counters/counter2.v +++ b/regression/nuterm/counters/counter2.v @@ -8,6 +8,6 @@ module main(input clk); else counter = 0; - wire \nuterm::live = counter == 0; + wire \$live = counter == 0; endmodule diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 index 91026c51c..3e2f4ea87 100644 --- a/regression/nuterm/counters/counter2/trace.1 +++ b/regression/nuterm/counters/counter2/trace.1 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,20 +7,20 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 0main.clk b00000000000000000000000000000010 main.counter diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 index d1f37d60b..0f0c351a4 100644 --- a/regression/nuterm/counters/counter2/trace.10 +++ b/regression/nuterm/counters/counter2/trace.10 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,21 +7,21 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 0main.clk b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 index 24902f176..02ca97c9f 100644 --- a/regression/nuterm/counters/counter2/trace.2 +++ b/regression/nuterm/counters/counter2/trace.2 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,20 +7,20 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 1main.clk b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 0main.clk b00000000000000000000000000000010 main.counter diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 index fb89bd0cb..72e7ab63a 100644 --- a/regression/nuterm/counters/counter2/trace.3 +++ b/regression/nuterm/counters/counter2/trace.3 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,20 +7,20 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 0main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 1main.clk b00000000000000000000000000000010 main.counter diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 index d5003953b..0518fe3ed 100644 --- a/regression/nuterm/counters/counter2/trace.4 +++ b/regression/nuterm/counters/counter2/trace.4 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,20 +7,20 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 0main.clk b00000000000000000000000000000010 main.counter diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 index 543a5bf79..60bd38a99 100644 --- a/regression/nuterm/counters/counter2/trace.5 +++ b/regression/nuterm/counters/counter2/trace.5 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,19 +7,19 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 index f1515ab6b..d015d1828 100644 --- a/regression/nuterm/counters/counter2/trace.6 +++ b/regression/nuterm/counters/counter2/trace.6 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,21 +7,21 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 0main.clk b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 index 5c5e3cf39..397fc0ff1 100644 --- a/regression/nuterm/counters/counter2/trace.7 +++ b/regression/nuterm/counters/counter2/trace.7 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,19 +7,19 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 index 6b55dc0e5..fe600de06 100644 --- a/regression/nuterm/counters/counter2/trace.8 +++ b/regression/nuterm/counters/counter2/trace.8 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,21 +7,21 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 0main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 0main.clk b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 index 9f740e09f..af98eb204 100644 --- a/regression/nuterm/counters/counter2/trace.9 +++ b/regression/nuterm/counters/counter2/trace.9 @@ -1,5 +1,5 @@ $date - Mon May 20 14:40:09 2024 + Mon May 20 17:40:02 2024 $end $timescale 1ns @@ -7,21 +7,21 @@ $end $scope module Verilog::main $end $var wire 1 main.clk clk $end $var reg 32 main.counter counter [31:0] $end - $var wire 1 main.nuterm::live nuterm::live $end + $var wire 1 main.$live $live $end $upscope $end $enddefinitions $end #0 1main.clk b10000000000000000000000000001000 main.counter -0main.nuterm::live +0main.$live #1 0main.clk b00000000000000000000000000000000 main.counter -1main.nuterm::live +1main.$live #2 1main.clk b00000000000000000000000000000001 main.counter -0main.nuterm::live +0main.$live #3 b00000000000000000000000000000010 main.counter #4 diff --git a/src/ebmc/live_signal.cpp b/src/ebmc/live_signal.cpp index 0f739eb8d..3686160a2 100644 --- a/src/ebmc/live_signal.cpp +++ b/src/ebmc/live_signal.cpp @@ -15,7 +15,8 @@ Author: Daniel Kroening, dkr@amazon.com void set_liveness_signal(transition_systemt &transition_system, exprt property) { - static const irep_idt identifier = id2string(transition_system.main_symbol->name) + ".$live"; + static const irep_idt identifier = + id2string(transition_system.main_symbol->name) + ".$live"; // add symbol if needed if(!transition_system.symbol_table.has_symbol(identifier)) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 3a8bf919b..ed57654bd 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -237,7 +237,9 @@ std::string ranking_net_to_string( else { // make signed, but first add a bit - terms.push_back(std::to_string(weight_int) + "*$signed({1'b0," + var.reference +"})"); + terms.push_back( + std::to_string(weight_int) + "*$signed({1'b0," + var.reference + + "})"); } } } diff --git a/src/trans-netlist/trans_trace.cpp b/src/trans-netlist/trans_trace.cpp index f9aac3f2e..ef63614bf 100644 --- a/src/trans-netlist/trans_trace.cpp +++ b/src/trans-netlist/trans_trace.cpp @@ -807,13 +807,13 @@ void show_trans_trace_vcd( // determine module - const symbolt &symbol1=ns.lookup( - state.assignments.front().lhs.get(ID_identifier)); + const symbolt &symbol1 = + ns.lookup(state.assignments.front().lhs.get(ID_identifier)); auto &module_symbol = ns.lookup(symbol1.module); // print those in the top module - + out << "$scope module " << vcd_reference(module_symbol, "") << " $end\n"; // split up into hierarchy From f51176fd04fded763fcb4ce144f5c78687aae584 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 17:46:11 +0100 Subject: [PATCH 29/40] fx --- src/nuterm/pytorch_tests.cpp | 4 ++-- src/nuterm/training.cpp | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/nuterm/pytorch_tests.cpp b/src/nuterm/pytorch_tests.cpp index 04e5dd0c1..82f2c1160 100644 --- a/src/nuterm/pytorch_tests.cpp +++ b/src/nuterm/pytorch_tests.cpp @@ -258,7 +258,7 @@ void pytorch_test6() auto my_loss = [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { - return torch::relu(next - curr + 1.0); + return torch::relu(next - curr + 1.0); }; torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); @@ -318,7 +318,7 @@ void pytorch_test7() auto my_loss = [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { - return torch::relu(next - curr + 1.0); + return torch::relu(next - curr + 1.0); }; torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index c9dbc9f72..bbad82829 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -24,8 +24,7 @@ void ranking_function_training( assert(batch.size(0) == 2); auto ranking_function_loss = - [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor - { + [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { assert(curr.dim() == 1 && next.dim() == 1); // The ranking needs to decrease from 'curr' to 'next' // by at least 'delta'. Anything less than that is loss. From 1f5ada060b01538125453817c8a0ee8db961278d Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Mon, 20 May 2024 22:28:13 +0100 Subject: [PATCH 30/40] fx --- examples/Benchmarks/run_nuterm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm index ba0b27400..4312d3bbb 100755 --- a/examples/Benchmarks/run_nuterm +++ b/examples/Benchmarks/run_nuterm @@ -2,9 +2,9 @@ set -e -ebmc PWM_1.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 +ebmc PWM_1.sv --neural-liveness --trace-steps 700 --number-of-traces 1 ebmc PWM_2.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 -ebmc PWM_3.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 +ebmc PWM_3.sv --neural-liveness --trace-steps 3000 --number-of-traces 1 ebmc PWM_4.sv --neural-liveness --trace-steps 5000 --number-of-traces 1 ebmc PWM_5.sv --neural-liveness --trace-steps 10000 --number-of-traces 1 ebmc PWM_6.sv --neural-liveness --trace-steps 20000 --number-of-traces 1 From 258ba49028686fc101611276a77b0a90d766d7d4 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 08:56:38 +0100 Subject: [PATCH 31/40] fx --- regression/ebmc/neural-liveness/counter1.desc | 2 +- regression/ebmc/neural-liveness/live_signal1.desc | 2 +- regression/ebmc/random-traces/boolean1.desc | 2 +- regression/ebmc/random-traces/bv1.desc | 2 +- .../ebmc/random-traces/counter_with_initial_value.desc | 2 +- regression/ebmc/random-traces/long_trace1.desc | 2 +- regression/ebmc/random-traces/with_submodule.desc | 2 +- src/ebmc/ebmc_parse_options.cpp | 2 +- src/ebmc/ebmc_parse_options.h | 2 +- src/ebmc/neural_liveness.cpp | 4 ++-- src/ebmc/random_traces.cpp | 8 ++++---- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/regression/ebmc/neural-liveness/counter1.desc b/regression/ebmc/neural-liveness/counter1.desc index 8e434f9d6..aad6e440b 100644 --- a/regression/ebmc/neural-liveness/counter1.desc +++ b/regression/ebmc/neural-liveness/counter1.desc @@ -1,6 +1,6 @@ CORE counter1.sv ---number-of-traces 2 --neural-liveness --neural-engine "echo RESULT: counter\\\\n" +--traces 2 --neural-liveness --neural-engine "echo RESULT: counter\\\\n" ^\[main\.property\.p0\] always s_eventually main.counter == 0: PROVED$ ^EXIT=0$ ^SIGNAL=0$ diff --git a/regression/ebmc/neural-liveness/live_signal1.desc b/regression/ebmc/neural-liveness/live_signal1.desc index abb70683a..2a6b37471 100644 --- a/regression/ebmc/neural-liveness/live_signal1.desc +++ b/regression/ebmc/neural-liveness/live_signal1.desc @@ -1,6 +1,6 @@ CORE counter1.sv ---number-of-traces 1 --neural-liveness --show-traces +--traces 1 --neural-liveness --show-traces ^Verilog::main\.\$live@0 = 0$ ^Verilog::main\.\$live@1 = 0$ ^Verilog::main\.\$live@2 = 0$ diff --git a/regression/ebmc/random-traces/boolean1.desc b/regression/ebmc/random-traces/boolean1.desc index b6e61f36f..ff4883e3f 100644 --- a/regression/ebmc/random-traces/boolean1.desc +++ b/regression/ebmc/random-traces/boolean1.desc @@ -1,6 +1,6 @@ CORE broken-smt-backend boolean1.v ---random-traces --trace-steps 0 --number-of-traces 2 +--random-traces --trace-steps 0 --traces 2 ^\*\*\* Trace 1$ ^ main\.some_wire = 0$ ^ main\.input1 = 0$ diff --git a/regression/ebmc/random-traces/bv1.desc b/regression/ebmc/random-traces/bv1.desc index adf3a7eab..65e2429b8 100644 --- a/regression/ebmc/random-traces/bv1.desc +++ b/regression/ebmc/random-traces/bv1.desc @@ -1,6 +1,6 @@ CORE broken-smt-backend bv1.v ---random-traces --trace-steps 1 --number-of-traces 1 +--random-traces --trace-steps 1 --traces 1 ^Transition system state 0$ ^ main\.some_reg = 0 .*$ ^ main\.input1 = 'h6FE4167A .*$ diff --git a/regression/ebmc/random-traces/counter_with_initial_value.desc b/regression/ebmc/random-traces/counter_with_initial_value.desc index 7f8b1f1fe..01fc2376a 100644 --- a/regression/ebmc/random-traces/counter_with_initial_value.desc +++ b/regression/ebmc/random-traces/counter_with_initial_value.desc @@ -1,6 +1,6 @@ CORE broken-smt-backend counter_with_initial_value.v ---random-traces --trace-steps 10 --waveform --number-of-traces 2 +--random-traces --trace-steps 10 --waveform --traces 2 ^\*\*\* Trace 1$ ^ 0 1 2 3 4 5 6 7 8 9 10$ ^ main.clk $ diff --git a/regression/ebmc/random-traces/long_trace1.desc b/regression/ebmc/random-traces/long_trace1.desc index 4fa67a635..fa5813408 100644 --- a/regression/ebmc/random-traces/long_trace1.desc +++ b/regression/ebmc/random-traces/long_trace1.desc @@ -1,6 +1,6 @@ CORE broken-smt-backend long_trace1.v ---random-traces --number-of-traces 1 --trace-steps 1000 +--random-traces --traces 1 --trace-steps 1000 ^Transition system state 0$ ^ main\.some_reg = 0 .*$ ^ main\.increment = 0$ diff --git a/regression/ebmc/random-traces/with_submodule.desc b/regression/ebmc/random-traces/with_submodule.desc index 51672d398..0a4c5fb54 100644 --- a/regression/ebmc/random-traces/with_submodule.desc +++ b/regression/ebmc/random-traces/with_submodule.desc @@ -1,6 +1,6 @@ CORE broken-smt-backend with_submodule.v ---random-traces --trace-steps 0 --number-of-traces 2 +--random-traces --trace-steps 0 --traces 2 ^\*\*\* Trace 1$ ^ main\.some_wire = 0$ ^ main\.input1 = 0$ diff --git a/src/ebmc/ebmc_parse_options.cpp b/src/ebmc/ebmc_parse_options.cpp index 40b94cc38..d1029b152 100644 --- a/src/ebmc/ebmc_parse_options.cpp +++ b/src/ebmc/ebmc_parse_options.cpp @@ -375,7 +375,7 @@ void ebmc_parse_optionst::help() " {y--new-mode} \t new mode is switched on\n" " {y--aiger} \t print out the instance in aiger format\n" " {y--random-traces} \t generate random traces\n" - " {y--number-of-traces} {unumber}\t generate the given number of traces\n" + " {y--traces} {unumber} \t generate the given number of traces\n" " {y--random-seed} {unumber} \t use the given random seed\n" " {y--trace-steps} {unumber} \t set the number of random transitions (default: 10 steps)\n" " {y--random-trace} \t generate a random trace\n" diff --git a/src/ebmc/ebmc_parse_options.h b/src/ebmc/ebmc_parse_options.h index 605fa03c8..29e45304e 100644 --- a/src/ebmc/ebmc_parse_options.h +++ b/src/ebmc/ebmc_parse_options.h @@ -43,7 +43,7 @@ class ebmc_parse_optionst:public parse_options_baset "(smt2)(bitwuzla)(boolector)(cvc3)(cvc4)(cvc5)(mathsat)(yices)(z3)" "(aig)(stop-induction)(stop-minimize)(start):(coverage)(naive)" "(compute-ct)(dot-netlist)(smv-netlist)(vcd):" - "(random-traces)(trace-steps):(random-seed):(number-of-traces):" + "(random-traces)(trace-steps):(random-seed):(traces):" "(random-trace)(random-waveform)" "(liveness-to-safety)" "I:(preprocess)(systemverilog)(vl2smv-extensions)", diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index f89fbe177..edbf851bf 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -212,10 +212,10 @@ void neural_livenesst::sample(std::function trace_consumer) { const auto number_of_traces = [this]() -> std::size_t { - if(cmdline.isset("number-of-traces")) + if(cmdline.isset("traces")) { auto number_of_traces_opt = - string2optional_size_t(cmdline.get_value("number-of-traces")); + string2optional_size_t(cmdline.get_value("traces")); if(!number_of_traces_opt.has_value()) throw ebmc_errort() << "failed to parse number of traces"; diff --git a/src/ebmc/random_traces.cpp b/src/ebmc/random_traces.cpp index 328aad220..a1f142dc6 100644 --- a/src/ebmc/random_traces.cpp +++ b/src/ebmc/random_traces.cpp @@ -113,10 +113,10 @@ int random_traces(const cmdlinet &cmdline, message_handlert &message_handler) { const auto number_of_traces = [&cmdline]() -> std::size_t { - if(cmdline.isset("number-of-traces")) + if(cmdline.isset("traces")) { auto number_of_traces_opt = - string2optional_size_t(cmdline.get_value("number-of-traces")); + string2optional_size_t(cmdline.get_value("traces")); if(!number_of_traces_opt.has_value()) throw ebmc_errort() << "failed to parse number of traces"; @@ -229,8 +229,8 @@ Function: random_trace int random_trace(const cmdlinet &cmdline, message_handlert &message_handler) { - if(cmdline.isset("number-of-traces")) - throw ebmc_errort() << "must not give number-of-traces"; + if(cmdline.isset("traces")) + throw ebmc_errort() << "must not give number of traces"; const std::size_t random_seed = [&cmdline]() -> std::size_t { if(cmdline.isset("random-seed")) From 0a6bdc5cb713d3cb3a820716efc42221dba211c4 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 08:56:58 +0100 Subject: [PATCH 32/40] fx --- examples/Benchmarks/run_nuterm | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm index 4312d3bbb..71724275a 100755 --- a/examples/Benchmarks/run_nuterm +++ b/examples/Benchmarks/run_nuterm @@ -2,15 +2,15 @@ set -e -ebmc PWM_1.sv --neural-liveness --trace-steps 700 --number-of-traces 1 -ebmc PWM_2.sv --neural-liveness --trace-steps 1000 --number-of-traces 1 -ebmc PWM_3.sv --neural-liveness --trace-steps 3000 --number-of-traces 1 -ebmc PWM_4.sv --neural-liveness --trace-steps 5000 --number-of-traces 1 -ebmc PWM_5.sv --neural-liveness --trace-steps 10000 --number-of-traces 1 -ebmc PWM_6.sv --neural-liveness --trace-steps 20000 --number-of-traces 1 -ebmc PWM_7.sv --neural-liveness --trace-steps 40000 --number-of-traces 1 -ebmc PWM_8.sv --neural-liveness --trace-steps 80000 --number-of-traces 1 -ebmc PWM_9.sv --neural-liveness --trace-steps 160000 --number-of-traces 1 +ebmc PWM_1.sv --neural-liveness --trace-steps 700 --traces 1 +ebmc PWM_2.sv --neural-liveness --trace-steps 1000 --traces 1 +ebmc PWM_3.sv --neural-liveness --trace-steps 3000 --traces 1 +ebmc PWM_4.sv --neural-liveness --trace-steps 5000 --traces 1 +ebmc PWM_5.sv --neural-liveness --trace-steps 10000 --traces 1 +ebmc PWM_6.sv --neural-liveness --trace-steps 20000 --traces 1 +ebmc PWM_7.sv --neural-liveness --trace-steps 40000 --traces 1 +ebmc PWM_8.sv --neural-liveness --trace-steps 80000 --traces 1 +ebmc PWM_9.sv --neural-liveness --trace-steps 160000 --traces 1 if false ; then ebmc delay_1.sv --neural-liveness "750-cnt" @@ -119,18 +119,18 @@ ebmc thermocouple_16.sv --neural-liveness "{2-state,2**18-cnt}" ebmc thermocouple_17.sv --neural-liveness "{2-state,2**19-cnt}" fi -ebmc uart_transmit_1.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_2.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_3.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_4.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_5.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_6.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_7.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_8.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_9.sv --neural-liveness --trace-steps 100 --number-of-traces 20 -ebmc uart_transmit_10.sv --neural-liveness --trace-steps 200 --number-of-traces 20 -ebmc uart_transmit_11.sv --neural-liveness --trace-steps 200 --number-of-traces 20 -ebmc uart_transmit_12.sv --neural-liveness --trace-steps 200 --number-of-traces 20 +ebmc uart_transmit_1.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_2.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_3.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_4.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_5.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_6.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_7.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_8.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_9.sv --neural-liveness --trace-steps 100 --traces 20 +ebmc uart_transmit_10.sv --neural-liveness --trace-steps 200 --traces 20 +ebmc uart_transmit_11.sv --neural-liveness --trace-steps 200 --traces 20 +ebmc uart_transmit_12.sv --neural-liveness --trace-steps 200 --traces 20 if false ; then ebmc vga_1.sv --neural-liveness "{2**5-v_cnt,2**7-h_cnt}" From 21f35e7ddd2a374243274ada7be3bda99aa56e28 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 11:42:58 +0100 Subject: [PATCH 33/40] fx --- src/ebmc/neural_liveness.cpp | 3 +-- src/ebmc/random_traces.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index edbf851bf..e473251f3 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -226,8 +226,7 @@ void neural_livenesst::sample(std::function trace_consumer) return 100; // default }(); - const std::size_t number_of_trace_steps = [this]() -> std::size_t - { + const std::size_t number_of_trace_steps = [this]() -> std::size_t { if(cmdline.isset("trace-steps")) { auto trace_steps_opt = diff --git a/src/ebmc/random_traces.cpp b/src/ebmc/random_traces.cpp index a1f142dc6..3236c72e9 100644 --- a/src/ebmc/random_traces.cpp +++ b/src/ebmc/random_traces.cpp @@ -111,8 +111,7 @@ Function: random_traces int random_traces(const cmdlinet &cmdline, message_handlert &message_handler) { - const auto number_of_traces = [&cmdline]() -> std::size_t - { + const auto number_of_traces = [&cmdline]() -> std::size_t { if(cmdline.isset("traces")) { auto number_of_traces_opt = From 07072a89d9517f4aef591633d3e4a0b2f430fb28 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 21 May 2024 17:16:42 +0100 Subject: [PATCH 34/40] fx --- src/ebmc/neural_liveness.cpp | 28 +++++++++++++++++++++------- src/nuterm/training.cpp | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ebmc/neural_liveness.cpp b/src/ebmc/neural_liveness.cpp index e473251f3..5567860b8 100644 --- a/src/ebmc/neural_liveness.cpp +++ b/src/ebmc/neural_liveness.cpp @@ -60,7 +60,7 @@ class neural_livenesst void validate_properties(); void set_liveness_signal(const ebmc_propertiest::propertyt &, const exprt &); void sample(std::function); - std::function dump_vcd_files(temp_dirt &); + std::function dump_vcd_files(temp_dirt &, std::size_t &vcd_index); exprt guess(ebmc_propertiest::propertyt &, const temp_dirt &); tvt verify(ebmc_propertiest::propertyt &, const exprt &candidate); }; @@ -101,17 +101,31 @@ int neural_livenesst::operator()() // trace, which are then read by the neural fitting procedure. temp_dirt temp_dir("ebmc-neural.XXXXXXXX"); const auto trace_files_prefix = temp_dir("trace."); - sample(dump_vcd_files(temp_dir)); + std::size_t vcd_index = 0; + auto vcd_dumper = dump_vcd_files(temp_dir, vcd_index); + sample(vcd_dumper); + + std::size_t iteration_number = 0; // Now do a guess-and-verify loop. while(true) { + iteration_number++; + message.status() << messaget::blue << "Iteration " << iteration_number << messaget::reset << messaget::eom; + if(iteration_number == 3) + throw ebmc_errort() << "giving up"; + const auto candidate = guess(property, temp_dir); if(verify(property, candidate).is_true()) - break; + break; // done, proven + + // add counterexample to dataset + CHECK_RETURN(property.witness_trace.has_value()); + vcd_dumper(property.witness_trace.value()); - throw ebmc_errort() << "giving up"; + const namespacet ns(transition_system.symbol_table); + show_waveform(property.witness_trace.value(), ns); } } @@ -191,13 +205,13 @@ void neural_livenesst::set_liveness_signal( } std::function -neural_livenesst::dump_vcd_files(temp_dirt &temp_dir) +neural_livenesst::dump_vcd_files(temp_dirt &temp_dir, std::size_t &vcd_index) { const auto outfile_prefix = temp_dir("trace."); return - [&, trace_nr = 0ull, outfile_prefix](trans_tracet trace) mutable -> void { + [&, outfile_prefix](trans_tracet trace) mutable -> void { namespacet ns(transition_system.symbol_table); - auto filename = outfile_prefix + std::to_string(++trace_nr); + auto filename = outfile_prefix + std::to_string(++vcd_index); std::ofstream out(widen_if_needed(filename)); if(!out) diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index bbad82829..58216370a 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -35,12 +35,12 @@ void ranking_function_training( torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); #endif #if 1 - torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.01); + torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.1); #endif torch::Tensor last_loss = {}; - for(size_t epoch = 1; epoch <= 10; ++epoch) + for(size_t epoch = 1; epoch <= 20; ++epoch) { size_t batch_index = 0; From f10e0cdf5ae8c4af0db5cfdc49bcfa111eb3775c Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 26 May 2024 19:52:58 +0100 Subject: [PATCH 35/40] fx --- src/nuterm/training.cpp | 50 +++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 58216370a..40bc65568 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -20,12 +20,43 @@ void ranking_function_training( { assert(net != nullptr); - for(auto &batch : data) - assert(batch.size(0) == 2); + for(auto &sample : data) + assert(sample.size(0) == 2); + + // Form batches. These are 2 x batch-size x state-vars. + std::vector> batches; + std::size_t batch_size = 100; + std::vector batch_current, batch_next; + batch_current.reserve(batch_size); + batch_next.reserve(batch_size); + + for(auto &sample : data) + { + if(batch_current.size() == batch_size) + { + auto tensor_current = torch::stack(batch_current, 0); + auto tensor_next = torch::stack(batch_next, 0); + auto pair = std::pair{std::move(tensor_current), std::move(tensor_next)}; + batches.push_back(std::move(pair)); + batch_current.clear(); + batch_next.clear(); + } + else + { + batch_current.push_back(sample[0]); + batch_next.push_back(sample[1]); + } + } + + std::cout << "BATCHES.size(): " << batches.size() << "\n"; + std::cout << "BATCHES[0].first.size(0): " << batches[0].first.size(0) << "\n"; + std::cout << "BATCHES[0].second.size(0): " << batches[0].second.size(0) << "\n"; + std::cout << "BATCHES[1].first.size(0): " << batches[1].first.size(0) << "\n"; auto ranking_function_loss = [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { - assert(curr.dim() == 1 && next.dim() == 1); + // these are batches + assert(curr.dim() == 2 && next.dim() == 2); // The ranking needs to decrease from 'curr' to 'next' // by at least 'delta'. Anything less than that is loss. return torch::relu(next - curr + delta); @@ -45,19 +76,20 @@ void ranking_function_training( size_t batch_index = 0; // Iterate the data loader to yield batches from the dataset. - for(auto &batch : data) + for(auto &batch : batches) { - //std::cout << "B: " << batch << "\n"; + // std::cout << "B: " << batch << "\n"; // Reset gradients. optimizer.zero_grad(); - // Execute the model on the input data. - assert(batch.size(0) == 2); - torch::Tensor prediction_curr = net->forward(batch[0]); - torch::Tensor prediction_next = net->forward(batch[1]); + // Execute the model on the input data vectors. + torch::Tensor prediction_curr = net->forward(batch.first); + torch::Tensor prediction_next = net->forward(batch.second); // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; // std::cout << "R: " << std::fixed << prediction_curr.item() << " -> " << prediction_next.item() << "\n"; + std::cout << "prediction_curr: " << prediction_curr.dim() << "\n"; + return; // Compute a loss value to judge the prediction of our model. torch::Tensor loss = From 33fc8cf900705bf04d2a2d9831a312d1de5335a8 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 26 May 2024 21:39:31 +0100 Subject: [PATCH 36/40] fx --- regression/nuterm/counters/README | 3 +- regression/nuterm/counters/counter1/trace.1 | 24 ++-- regression/nuterm/counters/counter1/trace.10 | 28 ++-- regression/nuterm/counters/counter1/trace.2 | 33 +++-- regression/nuterm/counters/counter1/trace.3 | 31 +++-- regression/nuterm/counters/counter1/trace.4 | 38 +++--- regression/nuterm/counters/counter1/trace.5 | 36 +++--- regression/nuterm/counters/counter1/trace.6 | 35 +++-- regression/nuterm/counters/counter1/trace.7 | 32 ++--- regression/nuterm/counters/counter1/trace.8 | 27 ++-- regression/nuterm/counters/counter1/trace.9 | 36 +++--- regression/nuterm/counters/counter2/trace.1 | 4 +- regression/nuterm/counters/counter2/trace.10 | 8 +- regression/nuterm/counters/counter2/trace.2 | 13 +- regression/nuterm/counters/counter2/trace.3 | 11 +- regression/nuterm/counters/counter2/trace.4 | 18 ++- regression/nuterm/counters/counter2/trace.5 | 16 ++- regression/nuterm/counters/counter2/trace.6 | 15 +-- regression/nuterm/counters/counter2/trace.7 | 12 +- regression/nuterm/counters/counter2/trace.8 | 7 +- regression/nuterm/counters/counter2/trace.9 | 16 ++- src/nuterm/CMakeLists.txt | 2 +- src/nuterm/batch.h | 20 +++ src/nuterm/nuterm_main.cpp | 127 ++----------------- src/nuterm/traces_to_tensors.cpp | 110 ++++++++++++++++ src/nuterm/traces_to_tensors.h | 29 +++++ src/nuterm/training.cpp | 51 ++------ src/nuterm/training.h | 4 +- 28 files changed, 402 insertions(+), 384 deletions(-) create mode 100644 src/nuterm/batch.h create mode 100644 src/nuterm/traces_to_tensors.cpp create mode 100644 src/nuterm/traces_to_tensors.h diff --git a/regression/nuterm/counters/README b/regression/nuterm/counters/README index 204b5d3f1..c3f80ab86 100644 --- a/regression/nuterm/counters/README +++ b/regression/nuterm/counters/README @@ -1,3 +1,4 @@ Sample as follows: -ebmc FILE.v --random-traces --vcd FILE/trace +ebmc counter1.v --random-traces --vcd counter1/trace +ebmc counter2.v --random-traces --vcd counter2/trace diff --git a/regression/nuterm/counters/counter1/trace.1 b/regression/nuterm/counters/counter1/trace.1 index 019800113..f55e2ddd8 100644 --- a/regression/nuterm/counters/counter1/trace.1 +++ b/regression/nuterm/counters/counter1/trace.1 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,28 +12,28 @@ $upscope $end $enddefinitions $end #0 0main.clk -b00010000000000000000000000000000 main.counter +b00100000101100111101010110110010 main.counter 0main.$live #1 1main.clk -b00001111111111111111111111111111 main.counter +b00100000101100111101010110110001 main.counter #2 -b00001111111111111111111111111110 main.counter +b00100000101100111101010110110000 main.counter #3 0main.clk -b00001111111111111111111111111101 main.counter +b00100000101100111101010110101111 main.counter #4 1main.clk -b00001111111111111111111111111100 main.counter +b00100000101100111101010110101110 main.counter #5 -b00001111111111111111111111111011 main.counter +b00100000101100111101010110101101 main.counter #6 -b00001111111111111111111111111010 main.counter +b00100000101100111101010110101100 main.counter #7 -b00001111111111111111111111111001 main.counter +b00100000101100111101010110101011 main.counter #8 -b00001111111111111111111111111000 main.counter +b00100000101100111101010110101010 main.counter #9 -b00001111111111111111111111110111 main.counter +b00100000101100111101010110101001 main.counter #10 -b00001111111111111111111111110110 main.counter +b00100000101100111101010110101000 main.counter diff --git a/regression/nuterm/counters/counter1/trace.10 b/regression/nuterm/counters/counter1/trace.10 index 14af98364..e11ba97aa 100644 --- a/regression/nuterm/counters/counter1/trace.10 +++ b/regression/nuterm/counters/counter1/trace.10 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,31 +12,29 @@ $upscope $end $enddefinitions $end #0 0main.clk -b00010000000000000000000000000000 main.counter +b01010011111011100110111000100000 main.counter 0main.$live #1 1main.clk -b00001111111111111111111111111111 main.counter +b01010011111011100110111000011111 main.counter #2 -0main.clk -b00001111111111111111111111111110 main.counter +b01010011111011100110111000011110 main.counter #3 -b00001111111111111111111111111101 main.counter +0main.clk +b01010011111011100110111000011101 main.counter #4 1main.clk -b00001111111111111111111111111100 main.counter +b01010011111011100110111000011100 main.counter #5 -0main.clk -b00001111111111111111111111111011 main.counter +b01010011111011100110111000011011 main.counter #6 -b00001111111111111111111111111010 main.counter +b01010011111011100110111000011010 main.counter #7 -b00001111111111111111111111111001 main.counter +b01010011111011100110111000011001 main.counter #8 -1main.clk -b00001111111111111111111111111000 main.counter +b01010011111011100110111000011000 main.counter #9 -b00001111111111111111111111110111 main.counter +b01010011111011100110111000010111 main.counter #10 0main.clk -b00001111111111111111111111110110 main.counter +b01010011111011100110111000010110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.2 b/regression/nuterm/counters/counter1/trace.2 index 6d6433de1..7c73f0bfa 100644 --- a/regression/nuterm/counters/counter1/trace.2 +++ b/regression/nuterm/counters/counter1/trace.2 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -11,31 +11,30 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -0main.clk -b00010000000000000000000000000000 main.counter +1main.clk +b10100110101000001100011010010111 main.counter 0main.$live #1 -b00001111111111111111111111111111 main.counter +b10100110101000001100011010010110 main.counter #2 -1main.clk -b00001111111111111111111111111110 main.counter +b10100110101000001100011010010101 main.counter #3 -0main.clk -b00001111111111111111111111111101 main.counter +b10100110101000001100011010010100 main.counter #4 -b00001111111111111111111111111100 main.counter +b10100110101000001100011010010011 main.counter #5 -b00001111111111111111111111111011 main.counter +0main.clk +b10100110101000001100011010010010 main.counter #6 -b00001111111111111111111111111010 main.counter +1main.clk +b10100110101000001100011010010001 main.counter #7 -b00001111111111111111111111111001 main.counter +0main.clk +b10100110101000001100011010010000 main.counter #8 1main.clk -b00001111111111111111111111111000 main.counter +b10100110101000001100011010001111 main.counter #9 -0main.clk -b00001111111111111111111111110111 main.counter +b10100110101000001100011010001110 main.counter #10 -1main.clk -b00001111111111111111111111110110 main.counter +b10100110101000001100011010001101 main.counter diff --git a/regression/nuterm/counters/counter1/trace.3 b/regression/nuterm/counters/counter1/trace.3 index 68b813118..fc3e5c8f0 100644 --- a/regression/nuterm/counters/counter1/trace.3 +++ b/regression/nuterm/counters/counter1/trace.3 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,31 +12,30 @@ $upscope $end $enddefinitions $end #0 1main.clk -b00010000000000000000000000000000 main.counter +b11010010001101000001010111110111 main.counter 0main.$live #1 -0main.clk -b00001111111111111111111111111111 main.counter +b11010010001101000001010111110110 main.counter #2 -b00001111111111111111111111111110 main.counter +b11010010001101000001010111110101 main.counter #3 -1main.clk -b00001111111111111111111111111101 main.counter +0main.clk +b11010010001101000001010111110100 main.counter #4 -b00001111111111111111111111111100 main.counter +1main.clk +b11010010001101000001010111110011 main.counter #5 -b00001111111111111111111111111011 main.counter +b11010010001101000001010111110010 main.counter #6 -b00001111111111111111111111111010 main.counter -#7 0main.clk -b00001111111111111111111111111001 main.counter +b11010010001101000001010111110001 main.counter +#7 +b11010010001101000001010111110000 main.counter #8 1main.clk -b00001111111111111111111111111000 main.counter +b11010010001101000001010111101111 main.counter #9 0main.clk -b00001111111111111111111111110111 main.counter +b11010010001101000001010111101110 main.counter #10 -1main.clk -b00001111111111111111111111110110 main.counter +b11010010001101000001010111101101 main.counter diff --git a/regression/nuterm/counters/counter1/trace.4 b/regression/nuterm/counters/counter1/trace.4 index d9b50731b..f06a84751 100644 --- a/regression/nuterm/counters/counter1/trace.4 +++ b/regression/nuterm/counters/counter1/trace.4 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -11,33 +11,31 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -0main.clk -b00010000000000000000000000000000 main.counter +1main.clk +b11001011110001011101001011001010 main.counter 0main.$live #1 -1main.clk -b00001111111111111111111111111111 main.counter +0main.clk +b11001011110001011101001011001001 main.counter #2 -b00001111111111111111111111111110 main.counter +1main.clk +b11001011110001011101001011001000 main.counter #3 -0main.clk -b00001111111111111111111111111101 main.counter +b11001011110001011101001011000111 main.counter #4 -1main.clk -b00001111111111111111111111111100 main.counter +0main.clk +b11001011110001011101001011000110 main.counter #5 -b00001111111111111111111111111011 main.counter +b11001011110001011101001011000101 main.counter #6 -0main.clk -b00001111111111111111111111111010 main.counter +1main.clk +b11001011110001011101001011000100 main.counter #7 -b00001111111111111111111111111001 main.counter +0main.clk +b11001011110001011101001011000011 main.counter #8 -1main.clk -b00001111111111111111111111111000 main.counter +b11001011110001011101001011000010 main.counter #9 -0main.clk -b00001111111111111111111111110111 main.counter +b11001011110001011101001011000001 main.counter #10 -1main.clk -b00001111111111111111111111110110 main.counter +b11001011110001011101001011000000 main.counter diff --git a/regression/nuterm/counters/counter1/trace.5 b/regression/nuterm/counters/counter1/trace.5 index 21cbd62ac..ddc1c58e0 100644 --- a/regression/nuterm/counters/counter1/trace.5 +++ b/regression/nuterm/counters/counter1/trace.5 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,29 +12,33 @@ $upscope $end $enddefinitions $end #0 1main.clk -b00010000000000000000000000000000 main.counter +b01000001001000100101001100011000 main.counter 0main.$live #1 -b00001111111111111111111111111111 main.counter +0main.clk +b01000001001000100101001100010111 main.counter #2 -b00001111111111111111111111111110 main.counter +1main.clk +b01000001001000100101001100010110 main.counter #3 -b00001111111111111111111111111101 main.counter -#4 0main.clk -b00001111111111111111111111111100 main.counter -#5 +b01000001001000100101001100010101 main.counter +#4 1main.clk -b00001111111111111111111111111011 main.counter -#6 +b01000001001000100101001100010100 main.counter +#5 0main.clk -b00001111111111111111111111111010 main.counter +b01000001001000100101001100010011 main.counter +#6 +b01000001001000100101001100010010 main.counter #7 -1main.clk -b00001111111111111111111111111001 main.counter +b01000001001000100101001100010001 main.counter #8 -b00001111111111111111111111111000 main.counter +1main.clk +b01000001001000100101001100010000 main.counter #9 -b00001111111111111111111111110111 main.counter +0main.clk +b01000001001000100101001100001111 main.counter #10 -b00001111111111111111111111110110 main.counter +1main.clk +b01000001001000100101001100001110 main.counter diff --git a/regression/nuterm/counters/counter1/trace.6 b/regression/nuterm/counters/counter1/trace.6 index 936aff9d8..7478ec230 100644 --- a/regression/nuterm/counters/counter1/trace.6 +++ b/regression/nuterm/counters/counter1/trace.6 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,33 +12,30 @@ $upscope $end $enddefinitions $end #0 0main.clk -b00010000000000000000000000000000 main.counter +b00111100011010010111100011101111 main.counter 0main.$live #1 -1main.clk -b00001111111111111111111111111111 main.counter +b00111100011010010111100011101110 main.counter #2 -0main.clk -b00001111111111111111111111111110 main.counter +1main.clk +b00111100011010010111100011101101 main.counter #3 -b00001111111111111111111111111101 main.counter +0main.clk +b00111100011010010111100011101100 main.counter #4 1main.clk -b00001111111111111111111111111100 main.counter +b00111100011010010111100011101011 main.counter #5 -b00001111111111111111111111111011 main.counter -#6 0main.clk -b00001111111111111111111111111010 main.counter +b00111100011010010111100011101010 main.counter +#6 +b00111100011010010111100011101001 main.counter #7 -1main.clk -b00001111111111111111111111111001 main.counter +b00111100011010010111100011101000 main.counter #8 -0main.clk -b00001111111111111111111111111000 main.counter -#9 1main.clk -b00001111111111111111111111110111 main.counter +b00111100011010010111100011100111 main.counter +#9 +b00111100011010010111100011100110 main.counter #10 -0main.clk -b00001111111111111111111111110110 main.counter +b00111100011010010111100011100101 main.counter diff --git a/regression/nuterm/counters/counter1/trace.7 b/regression/nuterm/counters/counter1/trace.7 index fda15d36b..cbe40981b 100644 --- a/regression/nuterm/counters/counter1/trace.7 +++ b/regression/nuterm/counters/counter1/trace.7 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,28 +12,30 @@ $upscope $end $enddefinitions $end #0 0main.clk -b00010000000000000000000000000000 main.counter +b11110001010110001001111010000111 main.counter 0main.$live #1 -b00001111111111111111111111111111 main.counter +b11110001010110001001111010000110 main.counter #2 -b00001111111111111111111111111110 main.counter +1main.clk +b11110001010110001001111010000101 main.counter #3 -b00001111111111111111111111111101 main.counter +b11110001010110001001111010000100 main.counter #4 -1main.clk -b00001111111111111111111111111100 main.counter +0main.clk +b11110001010110001001111010000011 main.counter #5 -b00001111111111111111111111111011 main.counter +b11110001010110001001111010000010 main.counter #6 -0main.clk -b00001111111111111111111111111010 main.counter +b11110001010110001001111010000001 main.counter #7 -b00001111111111111111111111111001 main.counter +1main.clk +b11110001010110001001111010000000 main.counter #8 -b00001111111111111111111111111000 main.counter +b11110001010110001001111001111111 main.counter #9 -1main.clk -b00001111111111111111111111110111 main.counter +0main.clk +b11110001010110001001111001111110 main.counter #10 -b00001111111111111111111111110110 main.counter +1main.clk +b11110001010110001001111001111101 main.counter diff --git a/regression/nuterm/counters/counter1/trace.8 b/regression/nuterm/counters/counter1/trace.8 index 86ee47095..b34272c91 100644 --- a/regression/nuterm/counters/counter1/trace.8 +++ b/regression/nuterm/counters/counter1/trace.8 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -12,30 +12,29 @@ $upscope $end $enddefinitions $end #0 0main.clk -b00010000000000000000000000000000 main.counter +b01111111111000011101111111000011 main.counter 0main.$live #1 1main.clk -b00001111111111111111111111111111 main.counter +b01111111111000011101111111000010 main.counter #2 0main.clk -b00001111111111111111111111111110 main.counter +b01111111111000011101111111000001 main.counter #3 -b00001111111111111111111111111101 main.counter +b01111111111000011101111111000000 main.counter #4 1main.clk -b00001111111111111111111111111100 main.counter +b01111111111000011101111110111111 main.counter #5 -0main.clk -b00001111111111111111111111111011 main.counter +b01111111111000011101111110111110 main.counter #6 -1main.clk -b00001111111111111111111111111010 main.counter +b01111111111000011101111110111101 main.counter #7 -b00001111111111111111111111111001 main.counter +b01111111111000011101111110111100 main.counter #8 -b00001111111111111111111111111000 main.counter +b01111111111000011101111110111011 main.counter #9 -b00001111111111111111111111110111 main.counter +b01111111111000011101111110111010 main.counter #10 -b00001111111111111111111111110110 main.counter +0main.clk +b01111111111000011101111110111001 main.counter diff --git a/regression/nuterm/counters/counter1/trace.9 b/regression/nuterm/counters/counter1/trace.9 index 562f94619..2293005b2 100644 --- a/regression/nuterm/counters/counter1/trace.9 +++ b/regression/nuterm/counters/counter1/trace.9 @@ -1,5 +1,5 @@ $date - Mon May 20 17:39:58 2024 + Sun May 26 21:33:09 2024 $end $timescale 1ns @@ -11,32 +11,34 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -1main.clk -b00010000000000000000000000000000 main.counter +0main.clk +b00111010100001110100111011010110 main.counter 0main.$live #1 -0main.clk -b00001111111111111111111111111111 main.counter -#2 1main.clk -b00001111111111111111111111111110 main.counter +b00111010100001110100111011010101 main.counter +#2 +0main.clk +b00111010100001110100111011010100 main.counter #3 -b00001111111111111111111111111101 main.counter +b00111010100001110100111011010011 main.counter #4 -0main.clk -b00001111111111111111111111111100 main.counter +1main.clk +b00111010100001110100111011010010 main.counter #5 -b00001111111111111111111111111011 main.counter +0main.clk +b00111010100001110100111011010001 main.counter #6 1main.clk -b00001111111111111111111111111010 main.counter +b00111010100001110100111011010000 main.counter #7 0main.clk -b00001111111111111111111111111001 main.counter +b00111010100001110100111011001111 main.counter #8 -b00001111111111111111111111111000 main.counter -#9 1main.clk -b00001111111111111111111111110111 main.counter +b00111010100001110100111011001110 main.counter +#9 +0main.clk +b00111010100001110100111011001101 main.counter #10 -b00001111111111111111111111110110 main.counter +b00111010100001110100111011001100 main.counter diff --git a/regression/nuterm/counters/counter2/trace.1 b/regression/nuterm/counters/counter2/trace.1 index 3e2f4ea87..ddd695e86 100644 --- a/regression/nuterm/counters/counter2/trace.1 +++ b/regression/nuterm/counters/counter2/trace.1 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,7 +12,7 @@ $upscope $end $enddefinitions $end #0 0main.clk -b10000000000000000000000000001000 main.counter +b00100000101100111101010110110010 main.counter 0main.$live #1 1main.clk diff --git a/regression/nuterm/counters/counter2/trace.10 b/regression/nuterm/counters/counter2/trace.10 index 0f0c351a4..23232ce3b 100644 --- a/regression/nuterm/counters/counter2/trace.10 +++ b/regression/nuterm/counters/counter2/trace.10 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,30 +12,28 @@ $upscope $end $enddefinitions $end #0 0main.clk -b10000000000000000000000000001000 main.counter +b01010011111011100110111000100000 main.counter 0main.$live #1 1main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 -0main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 +0main.clk b00000000000000000000000000000010 main.counter #4 1main.clk b00000000000000000000000000000011 main.counter #5 -0main.clk b00000000000000000000000000000100 main.counter #6 b00000000000000000000000000000101 main.counter #7 b00000000000000000000000000000110 main.counter #8 -1main.clk b00000000000000000000000000000111 main.counter #9 b00000000000000000000000000001000 main.counter diff --git a/regression/nuterm/counters/counter2/trace.2 b/regression/nuterm/counters/counter2/trace.2 index 02ca97c9f..f79464fcb 100644 --- a/regression/nuterm/counters/counter2/trace.2 +++ b/regression/nuterm/counters/counter2/trace.2 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -11,33 +11,32 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -0main.clk -b10000000000000000000000000001000 main.counter +1main.clk +b10100110101000001100011010010111 main.counter 0main.$live #1 b00000000000000000000000000000000 main.counter 1main.$live #2 -1main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 -0main.clk b00000000000000000000000000000010 main.counter #4 b00000000000000000000000000000011 main.counter #5 +0main.clk b00000000000000000000000000000100 main.counter #6 +1main.clk b00000000000000000000000000000101 main.counter #7 +0main.clk b00000000000000000000000000000110 main.counter #8 1main.clk b00000000000000000000000000000111 main.counter #9 -0main.clk b00000000000000000000000000001000 main.counter #10 -1main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.3 b/regression/nuterm/counters/counter2/trace.3 index 72e7ab63a..06c21806c 100644 --- a/regression/nuterm/counters/counter2/trace.3 +++ b/regression/nuterm/counters/counter2/trace.3 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,26 +12,26 @@ $upscope $end $enddefinitions $end #0 1main.clk -b10000000000000000000000000001000 main.counter +b11010010001101000001010111110111 main.counter 0main.$live #1 -0main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 b00000000000000000000000000000001 main.counter 0main.$live #3 -1main.clk +0main.clk b00000000000000000000000000000010 main.counter #4 +1main.clk b00000000000000000000000000000011 main.counter #5 b00000000000000000000000000000100 main.counter #6 +0main.clk b00000000000000000000000000000101 main.counter #7 -0main.clk b00000000000000000000000000000110 main.counter #8 1main.clk @@ -40,5 +40,4 @@ b00000000000000000000000000000111 main.counter 0main.clk b00000000000000000000000000001000 main.counter #10 -1main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.4 b/regression/nuterm/counters/counter2/trace.4 index 0518fe3ed..04d2c96da 100644 --- a/regression/nuterm/counters/counter2/trace.4 +++ b/regression/nuterm/counters/counter2/trace.4 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -11,35 +11,33 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -0main.clk -b10000000000000000000000000001000 main.counter +1main.clk +b11001011110001011101001011001010 main.counter 0main.$live #1 -1main.clk +0main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 +1main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 -0main.clk b00000000000000000000000000000010 main.counter #4 -1main.clk +0main.clk b00000000000000000000000000000011 main.counter #5 b00000000000000000000000000000100 main.counter #6 -0main.clk +1main.clk b00000000000000000000000000000101 main.counter #7 +0main.clk b00000000000000000000000000000110 main.counter #8 -1main.clk b00000000000000000000000000000111 main.counter #9 -0main.clk b00000000000000000000000000001000 main.counter #10 -1main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.5 b/regression/nuterm/counters/counter2/trace.5 index 60bd38a99..7a72e1aed 100644 --- a/regression/nuterm/counters/counter2/trace.5 +++ b/regression/nuterm/counters/counter2/trace.5 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,31 +12,35 @@ $upscope $end $enddefinitions $end #0 1main.clk -b10000000000000000000000000001000 main.counter +b01000001001000100101001100011000 main.counter 0main.$live #1 +0main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 +1main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 +0main.clk b00000000000000000000000000000010 main.counter #4 -0main.clk +1main.clk b00000000000000000000000000000011 main.counter #5 -1main.clk +0main.clk b00000000000000000000000000000100 main.counter #6 -0main.clk b00000000000000000000000000000101 main.counter #7 -1main.clk b00000000000000000000000000000110 main.counter #8 +1main.clk b00000000000000000000000000000111 main.counter #9 +0main.clk b00000000000000000000000000001000 main.counter #10 +1main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.6 b/regression/nuterm/counters/counter2/trace.6 index d015d1828..58651c612 100644 --- a/regression/nuterm/counters/counter2/trace.6 +++ b/regression/nuterm/counters/counter2/trace.6 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,35 +12,32 @@ $upscope $end $enddefinitions $end #0 0main.clk -b10000000000000000000000000001000 main.counter +b00111100011010010111100011101111 main.counter 0main.$live #1 -1main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 -0main.clk +1main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 +0main.clk b00000000000000000000000000000010 main.counter #4 1main.clk b00000000000000000000000000000011 main.counter #5 +0main.clk b00000000000000000000000000000100 main.counter #6 -0main.clk b00000000000000000000000000000101 main.counter #7 -1main.clk b00000000000000000000000000000110 main.counter #8 -0main.clk +1main.clk b00000000000000000000000000000111 main.counter #9 -1main.clk b00000000000000000000000000001000 main.counter #10 -0main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.7 b/regression/nuterm/counters/counter2/trace.7 index 397fc0ff1..6fe0ca067 100644 --- a/regression/nuterm/counters/counter2/trace.7 +++ b/regression/nuterm/counters/counter2/trace.7 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,30 +12,32 @@ $upscope $end $enddefinitions $end #0 0main.clk -b10000000000000000000000000001000 main.counter +b11110001010110001001111010000111 main.counter 0main.$live #1 b00000000000000000000000000000000 main.counter 1main.$live #2 +1main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 b00000000000000000000000000000010 main.counter #4 -1main.clk +0main.clk b00000000000000000000000000000011 main.counter #5 b00000000000000000000000000000100 main.counter #6 -0main.clk b00000000000000000000000000000101 main.counter #7 +1main.clk b00000000000000000000000000000110 main.counter #8 b00000000000000000000000000000111 main.counter #9 -1main.clk +0main.clk b00000000000000000000000000001000 main.counter #10 +1main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.8 b/regression/nuterm/counters/counter2/trace.8 index fe600de06..928f5db7e 100644 --- a/regression/nuterm/counters/counter2/trace.8 +++ b/regression/nuterm/counters/counter2/trace.8 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -12,7 +12,7 @@ $upscope $end $enddefinitions $end #0 0main.clk -b10000000000000000000000000001000 main.counter +b01111111111000011101111111000011 main.counter 0main.$live #1 1main.clk @@ -28,10 +28,8 @@ b00000000000000000000000000000010 main.counter 1main.clk b00000000000000000000000000000011 main.counter #5 -0main.clk b00000000000000000000000000000100 main.counter #6 -1main.clk b00000000000000000000000000000101 main.counter #7 b00000000000000000000000000000110 main.counter @@ -40,4 +38,5 @@ b00000000000000000000000000000111 main.counter #9 b00000000000000000000000000001000 main.counter #10 +0main.clk b00000000000000000000000000001001 main.counter diff --git a/regression/nuterm/counters/counter2/trace.9 b/regression/nuterm/counters/counter2/trace.9 index af98eb204..9824cf93d 100644 --- a/regression/nuterm/counters/counter2/trace.9 +++ b/regression/nuterm/counters/counter2/trace.9 @@ -1,5 +1,5 @@ $date - Mon May 20 17:40:02 2024 + Sun May 26 21:39:19 2024 $end $timescale 1ns @@ -11,23 +11,24 @@ $scope module Verilog::main $end $upscope $end $enddefinitions $end #0 -1main.clk -b10000000000000000000000000001000 main.counter +0main.clk +b00111010100001110100111011010110 main.counter 0main.$live #1 -0main.clk +1main.clk b00000000000000000000000000000000 main.counter 1main.$live #2 -1main.clk +0main.clk b00000000000000000000000000000001 main.counter 0main.$live #3 b00000000000000000000000000000010 main.counter #4 -0main.clk +1main.clk b00000000000000000000000000000011 main.counter #5 +0main.clk b00000000000000000000000000000100 main.counter #6 1main.clk @@ -36,9 +37,10 @@ b00000000000000000000000000000101 main.counter 0main.clk b00000000000000000000000000000110 main.counter #8 +1main.clk b00000000000000000000000000000111 main.counter #9 -1main.clk +0main.clk b00000000000000000000000000001000 main.counter #10 b00000000000000000000000000001001 main.counter diff --git a/src/nuterm/CMakeLists.txt b/src/nuterm/CMakeLists.txt index fa2383654..206c19d5f 100644 --- a/src/nuterm/CMakeLists.txt +++ b/src/nuterm/CMakeLists.txt @@ -8,6 +8,6 @@ add_executable(pytorch_tests pytorch_tests.cpp) target_link_libraries(pytorch_tests "${TORCH_LIBRARIES}") set_property(TARGET pytorch_tests PROPERTY CXX_STANDARD 17) -add_executable(nuterm nuterm_main.cpp vcd_parser.cpp training.cpp) +add_executable(nuterm nuterm_main.cpp vcd_parser.cpp training.cpp traces_to_tensors.cpp) target_link_libraries(nuterm "${TORCH_LIBRARIES}") set_property(TARGET nuterm PROPERTY CXX_STANDARD 17) diff --git a/src/nuterm/batch.h b/src/nuterm/batch.h new file mode 100644 index 000000000..7ce6a2e39 --- /dev/null +++ b/src/nuterm/batch.h @@ -0,0 +1,20 @@ +/*******************************************************************\ + +Module: Batch + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#ifndef NUTERM_BATCH_H +#define NUTERM_BATCH_H + +#include + +struct batcht +{ + batcht(const std::vector &__curr, const std::vector &__next) : curr(torch::stack(__curr)), next(torch::stack(__next)) { } + torch::Tensor curr, next; +}; + +#endif // NUTERM_BATCH_H diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index ed57654bd..575663f97 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -7,7 +7,7 @@ Author: Daniel Kroening, dkr@amazon.com \*******************************************************************/ #include "training.h" -#include "vcd_parser.h" +#include "traces_to_tensors.h" #include #include @@ -16,8 +16,6 @@ Author: Daniel Kroening, dkr@amazon.com #include #include -using tracest = std::list; - tracest read_traces(const std::string &path) { std::vector file_names; @@ -42,24 +40,6 @@ tracest read_traces(const std::string &path) return traces; } -std::size_t number_of_transitions(const tracest &traces) -{ - std::size_t result = 0; - - for(auto &trace : traces) - result += trace.states.empty() ? 0 : trace.states.size() - 1; - - return result; -} - -struct state_variablet -{ - std::size_t index; - std::string reference; -}; - -using state_variablest = std::map; - state_variablest state_variables(const tracest &traces) { // number all identifiers @@ -90,61 +70,6 @@ bool has_suffix(const std::string &s, const std::string &suffix) return false; } -#include - -double vcd_to_value(const std::string &src) -{ - // VCD gives binary values - auto integer = std::stoull(src, nullptr, 2); - //std::cout << "VALUE " << src << " -> " << double(integer) << "\n"; - return integer; -} - -torch::Tensor state_to_tensor( - const state_variablest &state_variables, - const vcdt::statet &state) -{ - std::vector data; - data.resize(state_variables.size(), 0); - for(auto &[id, var] : state_variables) - { - if(var.reference == "clk") - continue; - auto v_it = state.changes.find(id); - if(v_it != state.changes.end()) - data[var.index] = vcd_to_value(v_it->second); - } - - return torch::tensor(data, torch::kFloat64); -} - -torch::Tensor state_pair_to_tensor( - const state_variablest &state_variables, - const vcdt::statet ¤t, - const vcdt::statet &next) -{ - // We make a tensor that has dimensions 2 x |V|. - // The '2' allows for current and next state. - auto tensor_current = state_to_tensor(state_variables, current); - auto tensor_next = state_to_tensor(state_variables, next); - auto tensor_pair = torch::stack({tensor_current, tensor_next}, 0); - // std::cout << "P: " << tensor_pair << "\n" << std::flush; - return std::move(tensor_pair); -} - -bool is_live_state( - const std::string &liveness_signal, - const vcdt::statet &state) -{ - auto value_it = state.changes.find(liveness_signal); - if(value_it == state.changes.end()) - { - std::cerr << "state without liveness signal" << '\n'; - abort(); - } - return vcd_to_value(value_it->second) != 0; -} - std::string liveness_signal(const state_variablest &state_variables) { for(auto &[id, var] : state_variables) @@ -157,44 +82,6 @@ std::string liveness_signal(const state_variablest &state_variables) abort(); } -std::vector traces_to_tensors( - const state_variablest &state_variables, - const std::string &liveness_signal, - const tracest &traces) -{ - auto t = number_of_transitions(traces); - - std::vector result; - result.reserve(t); - - for(auto &trace : traces) - { - const auto full_trace = trace.full_trace(); - - for(std::size_t t = 1; t < full_trace.size(); t++) - { - auto ¤t = full_trace[t - 1]; - auto &next = full_trace[t]; - - // We must discard transitions in/out of 'live' states. - // There is no need for the ranking function to decrease - // on such transitions. - if( - !is_live_state(liveness_signal, current) && - !is_live_state(liveness_signal, next)) - { - // std::cout << "\n" << current << "---->\n" << next; - auto tensor = state_pair_to_tensor(state_variables, current, next); - assert(tensor.size(0) == 2); - assert(tensor.size(1) == state_variables.size()); - result.push_back(std::move(tensor)); - } - } - } - - return result; -} - std::string sum(const std::vector &terms) { std::string result; @@ -279,12 +166,14 @@ int main(int argc, const char *argv[]) torch::manual_seed(0); - const auto tensors = - traces_to_tensors(state_variables, liveness_signal, traces); + const std::size_t batch_size = 1000; + + const auto batches = + traces_to_tensors(state_variables, liveness_signal, traces, batch_size); - std::cout << "Got " << tensors.size() << " transitions to rank\n"; + std::cout << "Got " << batches.size() << " batch(es) to rank\n"; - if(tensors.empty()) + if(batches.empty()) { return 0; } @@ -318,7 +207,7 @@ int main(int argc, const char *argv[]) } std::cout << "TRAINING\n"; - ranking_function_training(net, tensors); + ranking_function_training(net, batches); { auto weight = net->named_parameters()["fc1.weight"]; diff --git a/src/nuterm/traces_to_tensors.cpp b/src/nuterm/traces_to_tensors.cpp new file mode 100644 index 000000000..6176cb0fe --- /dev/null +++ b/src/nuterm/traces_to_tensors.cpp @@ -0,0 +1,110 @@ +/*******************************************************************\ + +Module: Traces to Tensors + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include "traces_to_tensors.h" + +double vcd_to_value(const std::string &src) +{ + // VCD gives binary values + auto integer = std::stoull(src, nullptr, 2); + //std::cout << "VALUE " << src << " -> " << double(integer) << "\n"; + return integer; +} + +torch::Tensor state_to_tensor( + const state_variablest &state_variables, + const vcdt::statet &state) +{ + std::vector data; + data.resize(state_variables.size(), 0); + for(auto &[id, var] : state_variables) + { + if(var.reference == "clk") + continue; + auto v_it = state.changes.find(id); + if(v_it != state.changes.end()) + data[var.index] = vcd_to_value(v_it->second); + } + + return torch::tensor(data, torch::kFloat64); +} + +bool is_live_state( + const std::string &liveness_signal, + const vcdt::statet &state) +{ + auto value_it = state.changes.find(liveness_signal); + if(value_it == state.changes.end()) + { + std::cerr << "state without liveness signal" << '\n'; + abort(); + } + return vcd_to_value(value_it->second) != 0; +} + +std::vector traces_to_tensors( + const state_variablest &state_variables, + const std::string &liveness_signal, + const tracest &traces, + std::size_t batch_size) +{ + // all batches + std::vector result; + + // current batch + std::vector batch_curr, batch_next; + batch_curr.reserve(batch_size); + batch_next.reserve(batch_size); + + for(auto &trace : traces) + { + const auto full_trace = trace.full_trace(); + + for(std::size_t t = 1; t < full_trace.size(); t++) + { + auto ¤t = full_trace[t - 1]; + auto &next = full_trace[t]; + + // We must discard transitions in/out of 'live' states. + // There is no need for the ranking function to decrease + // on such transitions. + if( + !is_live_state(liveness_signal, current) && + !is_live_state(liveness_signal, next)) + { + // std::cout << "\n" << current << "---->\n" << next; + auto tensor_curr = state_to_tensor(state_variables, current); + auto tensor_next = state_to_tensor(state_variables, next); + assert(tensor_curr.size(0) == state_variables.size()); + assert(tensor_next.size(0) == state_variables.size()); + + // add to batch + batch_curr.push_back(std::move(tensor_curr)); + batch_next.push_back(std::move(tensor_next)); + + // full batch? + if(batch_curr.size() == batch_size) + { + result.emplace_back(batch_curr, batch_next); + batch_curr.resize(0); + batch_next.resize(0); + batch_curr.reserve(batch_size); + batch_next.reserve(batch_size); + } + } + } + } + + // incomplete batch? + if(!batch_curr.empty()) + { + result.emplace_back(batch_curr, batch_next); + } + + return result; +} diff --git a/src/nuterm/traces_to_tensors.h b/src/nuterm/traces_to_tensors.h new file mode 100644 index 000000000..b40857c9a --- /dev/null +++ b/src/nuterm/traces_to_tensors.h @@ -0,0 +1,29 @@ +/*******************************************************************\ + +Module: Traces to Tensors + +Author: Daniel Kroening, dkr@amazon.com + +\*******************************************************************/ + +#include "batch.h" +#include "vcd_parser.h" + +#include +#include + +struct state_variablet +{ + std::size_t index; + std::string reference; +}; + +using state_variablest = std::map; + +using tracest = std::list; + +std::vector traces_to_tensors( + const state_variablest &, + const std::string &liveness_signal, + const tracest &traces, + std::size_t batch_size); diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 40bc65568..286405311 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -16,42 +16,12 @@ const double delta = 1; void ranking_function_training( std::shared_ptr net, - const std::vector &data) + const std::vector &batches) { assert(net != nullptr); - for(auto &sample : data) - assert(sample.size(0) == 2); - - // Form batches. These are 2 x batch-size x state-vars. - std::vector> batches; - std::size_t batch_size = 100; - std::vector batch_current, batch_next; - batch_current.reserve(batch_size); - batch_next.reserve(batch_size); - - for(auto &sample : data) - { - if(batch_current.size() == batch_size) - { - auto tensor_current = torch::stack(batch_current, 0); - auto tensor_next = torch::stack(batch_next, 0); - auto pair = std::pair{std::move(tensor_current), std::move(tensor_next)}; - batches.push_back(std::move(pair)); - batch_current.clear(); - batch_next.clear(); - } - else - { - batch_current.push_back(sample[0]); - batch_next.push_back(sample[1]); - } - } - - std::cout << "BATCHES.size(): " << batches.size() << "\n"; - std::cout << "BATCHES[0].first.size(0): " << batches[0].first.size(0) << "\n"; - std::cout << "BATCHES[0].second.size(0): " << batches[0].second.size(0) << "\n"; - std::cout << "BATCHES[1].first.size(0): " << batches[1].first.size(0) << "\n"; + std::cout << "BATCHES[0].curr.size(0): " << batches[0].curr.size(0) << "\n"; + std::cout << "BATCHES[0].curr.size(1): " << batches[0].curr.size(1) << "\n"; auto ranking_function_loss = [](const torch::Tensor &curr, const torch::Tensor &next) -> torch::Tensor { @@ -59,7 +29,10 @@ void ranking_function_training( assert(curr.dim() == 2 && next.dim() == 2); // The ranking needs to decrease from 'curr' to 'next' // by at least 'delta'. Anything less than that is loss. - return torch::relu(next - curr + delta); + auto point_loss = torch::relu(next - curr + delta); + auto loss = torch::sum(point_loss); + assert(loss.dim() == 0); + return loss; }; #if 0 @@ -78,18 +51,18 @@ void ranking_function_training( // Iterate the data loader to yield batches from the dataset. for(auto &batch : batches) { - // std::cout << "B: " << batch << "\n"; + // std::cout << "batch.curr: " << batch.curr << "\n"; // Reset gradients. optimizer.zero_grad(); // Execute the model on the input data vectors. - torch::Tensor prediction_curr = net->forward(batch.first); - torch::Tensor prediction_next = net->forward(batch.second); + torch::Tensor prediction_curr = net->forward(batch.curr); + torch::Tensor prediction_next = net->forward(batch.next); // std::cout << "B: " << std::fixed << batch[0][1].item() << " -> " << batch[1][1].item() << "\n"; // std::cout << "R: " << std::fixed << prediction_curr.item() << " -> " << prediction_next.item() << "\n"; - std::cout << "prediction_curr: " << prediction_curr.dim() << "\n"; - return; + //std::cout << "prediction_curr: " << prediction_curr.dim() << "\n"; + //return; // Compute a loss value to judge the prediction of our model. torch::Tensor loss = diff --git a/src/nuterm/training.h b/src/nuterm/training.h index 95b788023..f94c475e0 100644 --- a/src/nuterm/training.h +++ b/src/nuterm/training.h @@ -6,7 +6,7 @@ Author: Daniel Kroening, dkr@amazon.com \*******************************************************************/ -#include +#include "batch.h" #include @@ -38,4 +38,4 @@ struct RankingNet : torch::nn::Module void ranking_function_training( const std::shared_ptr net, - const std::vector &); + const std::vector &); From c3df29ffb1a04394b14bf4a8f96ae6960fd01dea Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 26 May 2024 21:39:41 +0100 Subject: [PATCH 37/40] fx --- src/nuterm/batch.h | 7 ++++++- src/nuterm/nuterm_main.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/nuterm/batch.h b/src/nuterm/batch.h index 7ce6a2e39..e56bb8796 100644 --- a/src/nuterm/batch.h +++ b/src/nuterm/batch.h @@ -13,7 +13,12 @@ Author: Daniel Kroening, dkr@amazon.com struct batcht { - batcht(const std::vector &__curr, const std::vector &__next) : curr(torch::stack(__curr)), next(torch::stack(__next)) { } + batcht( + const std::vector &__curr, + const std::vector &__next) + : curr(torch::stack(__curr)), next(torch::stack(__next)) + { + } torch::Tensor curr, next; }; diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 575663f97..3a30d9236 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -6,8 +6,8 @@ Author: Daniel Kroening, dkr@amazon.com \*******************************************************************/ -#include "training.h" #include "traces_to_tensors.h" +#include "training.h" #include #include From a39b5f23d429a441a67ff88b803a3fee4631a2ad Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 26 May 2024 22:24:18 +0100 Subject: [PATCH 38/40] fx --- examples/Benchmarks/run_nuterm | 85 +++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/examples/Benchmarks/run_nuterm b/examples/Benchmarks/run_nuterm index 71724275a..e4d60dd22 100755 --- a/examples/Benchmarks/run_nuterm +++ b/examples/Benchmarks/run_nuterm @@ -2,15 +2,18 @@ set -e -ebmc PWM_1.sv --neural-liveness --trace-steps 700 --traces 1 -ebmc PWM_2.sv --neural-liveness --trace-steps 1000 --traces 1 -ebmc PWM_3.sv --neural-liveness --trace-steps 3000 --traces 1 -ebmc PWM_4.sv --neural-liveness --trace-steps 5000 --traces 1 -ebmc PWM_5.sv --neural-liveness --trace-steps 10000 --traces 1 -ebmc PWM_6.sv --neural-liveness --trace-steps 20000 --traces 1 -ebmc PWM_7.sv --neural-liveness --trace-steps 40000 --traces 1 -ebmc PWM_8.sv --neural-liveness --trace-steps 80000 --traces 1 -ebmc PWM_9.sv --neural-liveness --trace-steps 160000 --traces 1 +if false ; then +# ok +ebmc PWM_1.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_2.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_3.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_4.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_5.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_6.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_7.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_8.sv --neural-liveness --trace-steps 10 --traces 20 +ebmc PWM_9.sv --neural-liveness --trace-steps 10 --traces 20 +fi if false ; then ebmc delay_1.sv --neural-liveness "750-cnt" @@ -31,17 +34,20 @@ ebmc delay_15.sv --neural-liveness "200000-cnt" ebmc delay_16.sv --neural-liveness "400000-cnt" fi -ebmc gray_1.sv --neural-liveness -ebmc gray_2.sv --neural-liveness -ebmc gray_3.sv --neural-liveness -ebmc gray_4.sv --neural-liveness -ebmc gray_5.sv --neural-liveness -ebmc gray_6.sv --neural-liveness -ebmc gray_7.sv --neural-liveness -ebmc gray_8.sv --neural-liveness -ebmc gray_9.sv --neural-liveness -ebmc gray_10.sv --neural-liveness -ebmc gray_11.sv --neural-liveness +if false ; then +# ok +ebmc gray_1.sv --neural-liveness --trace-steps 10 +ebmc gray_2.sv --neural-liveness --trace-steps 10 +ebmc gray_3.sv --neural-liveness --trace-steps 10 +ebmc gray_4.sv --neural-liveness --trace-steps 10 +ebmc gray_5.sv --neural-liveness --trace-steps 10 +ebmc gray_6.sv --neural-liveness --trace-steps 10 +ebmc gray_7.sv --neural-liveness --trace-steps 10 +ebmc gray_8.sv --neural-liveness --trace-steps 10 +ebmc gray_9.sv --neural-liveness --trace-steps 10 +ebmc gray_10.sv --neural-liveness --trace-steps 10 +ebmc gray_11.sv --neural-liveness --trace-steps 10 +fi if false ; then ebmc i2c_1.sv --neural-liveness "2**9-cnt" @@ -83,21 +89,24 @@ ebmc lcd_13.sv --neural-liveness "{3-state,90000-cnt}" ebmc lcd_14.sv --neural-liveness "{3-state,180000-cnt}" fi -ebmc seven_seg_1.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_2.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_3.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_4.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_5.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_6.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_7.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_8.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_9.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_10.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_11.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_12.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_16.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_17.sv --neural-liveness --property SEVEN.property.p1 -ebmc seven_seg_18.sv --neural-liveness --property SEVEN.property.p1 +if false ; then +# ok +ebmc seven_seg_1.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_2.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_3.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_4.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_5.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_6.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_7.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_8.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_9.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_10.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_11.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_12.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_16.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_17.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +ebmc seven_seg_18.sv --neural-liveness --property SEVEN.property.p1 --traces 10 +fi if false ; then ebmc thermocouple_1.sv --neural-liveness "{2-state,2**5-cnt}" @@ -119,8 +128,9 @@ ebmc thermocouple_16.sv --neural-liveness "{2-state,2**18-cnt}" ebmc thermocouple_17.sv --neural-liveness "{2-state,2**19-cnt}" fi -ebmc uart_transmit_1.sv --neural-liveness --trace-steps 100 --traces 20 -ebmc uart_transmit_2.sv --neural-liveness --trace-steps 100 --traces 20 +if false ; then +ebmc uart_transmit_1.sv --neural-liveness --trace-steps 10 --traces 10 +ebmc uart_transmit_2.sv --neural-liveness --trace-steps 10 --traces 10 ebmc uart_transmit_3.sv --neural-liveness --trace-steps 100 --traces 20 ebmc uart_transmit_4.sv --neural-liveness --trace-steps 100 --traces 20 ebmc uart_transmit_5.sv --neural-liveness --trace-steps 100 --traces 20 @@ -131,6 +141,7 @@ ebmc uart_transmit_9.sv --neural-liveness --trace-steps 100 --traces 20 ebmc uart_transmit_10.sv --neural-liveness --trace-steps 200 --traces 20 ebmc uart_transmit_11.sv --neural-liveness --trace-steps 200 --traces 20 ebmc uart_transmit_12.sv --neural-liveness --trace-steps 200 --traces 20 +fi if false ; then ebmc vga_1.sv --neural-liveness "{2**5-v_cnt,2**7-h_cnt}" From 52186e75f2e4cc971da15d404520be8eff112aee Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Sun, 26 May 2024 22:36:34 +0100 Subject: [PATCH 39/40] fx --- src/nuterm/training.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 286405311..0df9726fb 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -42,11 +42,12 @@ void ranking_function_training( torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.1); #endif - torch::Tensor last_loss = {}; + double epoch_loss; for(size_t epoch = 1; epoch <= 20; ++epoch) { size_t batch_index = 0; + epoch_loss = 0; // Iterate the data loader to yield batches from the dataset. for(auto &batch : batches) @@ -80,7 +81,7 @@ void ranking_function_training( if(1) { std::cout << "Epoch: " << epoch << " | Batch: " << batch_index - << " | Loss: " << std::fixed << std::setprecision(3) + << " | Batch Loss: " << std::fixed << std::setprecision(3) << loss.item() << '\n'; //torch::save(net, "net.pt"); } @@ -88,13 +89,13 @@ void ranking_function_training( batch_index++; - last_loss = loss; + epoch_loss += loss.item(); } - if(last_loss.item() == 0) + if(epoch_loss == 0) break; // done } std::cout << "Final loss: " << std::fixed << std::setprecision(3) - << last_loss.item() << '\n'; + << epoch_loss << '\n'; } From 38865fbfe5938d3e5ddc7dba9e5fd5d288b8a7e6 Mon Sep 17 00:00:00 2001 From: Daniel Kroening Date: Tue, 28 May 2024 12:40:47 -0700 Subject: [PATCH 40/40] fx --- src/nuterm/nuterm_main.cpp | 39 +++++++++++++++++++++++++++++++++- src/nuterm/traces_to_tensors.h | 4 +++- src/nuterm/training.cpp | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/nuterm/nuterm_main.cpp b/src/nuterm/nuterm_main.cpp index 3a30d9236..2ab89050e 100644 --- a/src/nuterm/nuterm_main.cpp +++ b/src/nuterm/nuterm_main.cpp @@ -138,6 +138,41 @@ std::string ranking_net_to_string( return sum(terms); } +void normalize(batchest &batches) +{ + if(batches.empty()) + return; + + auto vars = batches.front().curr.size(1); + std::vector max; + max.resize(vars, 0.0); + + for(auto &batch : batches) + { + for(std::size_t j = 0; j()); + for(std::size_t j = 0; j()); + } + + for(std::size_t i=0; i; using tracest = std::list; -std::vector traces_to_tensors( +using batchest = std::vector; + +batchest traces_to_tensors( const state_variablest &, const std::string &liveness_signal, const tracest &traces, diff --git a/src/nuterm/training.cpp b/src/nuterm/training.cpp index 0df9726fb..f1e018668 100644 --- a/src/nuterm/training.cpp +++ b/src/nuterm/training.cpp @@ -39,7 +39,7 @@ void ranking_function_training( torch::optim::SGD optimizer(net->parameters(), /*lr=*/0.1); #endif #if 1 - torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.1); + torch::optim::Adam optimizer(net->parameters(), /*lr=*/0.001); #endif double epoch_loss;