-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting a solution with the simple synthesizer
- Loading branch information
Showing
7 changed files
with
79 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
basic.smt | ||
flamegraph.svg | ||
perf.data | ||
perf.data.old |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ | |
// released under BSD 3-Clause License | ||
// author: Kevin Laeufer <[email protected]> | ||
|
||
use crate::repair::{RepairAssignment, RepairVars}; | ||
use crate::repair::{RepairAssignment, RepairVars, CHANGE_COUNT_WIDTH}; | ||
use crate::testbench::Testbench; | ||
use crate::Solver; | ||
use easy_smt as smt; | ||
use easy_smt::Response; | ||
use libpatron::ir::*; | ||
use libpatron::mc::{Simulator, SmtSolverCmd, TransitionSystemEncoding, UnrollSmtEncoding}; | ||
use libpatron::sim::interpreter::ValueRef; | ||
|
@@ -25,6 +26,7 @@ pub fn basic_repair( | |
sim: &impl Simulator, | ||
tb: &Testbench, | ||
conf: &BasicConfig, | ||
change_count_ref: ExprRef, | ||
) -> Result<Option<Vec<RepairAssignment>>> { | ||
let mut smt_ctx = create_smt_ctx(&conf.solver, conf.dump_file.as_deref())?; | ||
|
||
|
@@ -36,17 +38,72 @@ pub fn basic_repair( | |
// constrain starting state to that from the simulator | ||
constrain_starting_state(sys, synth_vars, sim, &enc, &mut smt_ctx)?; | ||
|
||
let start_unroll = std::time::Instant::now(); | ||
// unroll system and constrain inputs and outputs | ||
for _ in 0..(tb.step_count() - 1) { | ||
enc.unroll(&mut smt_ctx)?; | ||
} | ||
if conf.verbose { | ||
println!( | ||
"Took {:?} to unroll", | ||
std::time::Instant::now() - start_unroll | ||
); | ||
} | ||
|
||
let start_apply_const = std::time::Instant::now(); | ||
tb.apply_constraints(&mut smt_ctx, &enc)?; | ||
if conf.verbose { | ||
println!( | ||
"Took {:?} to apply constraints", | ||
std::time::Instant::now() - start_apply_const | ||
); | ||
} | ||
|
||
// check to see if a solution exists | ||
let start_check = std::time::Instant::now(); | ||
let r = smt_ctx.check()?; | ||
println!("{r:?}"); | ||
let check_duration = std::time::Instant::now() - start_check; | ||
if conf.verbose { | ||
println!("Check-Sat took {check_duration:?}"); | ||
} | ||
match r { | ||
// cannot find a repair | ||
Response::Unsat | Response::Unknown => return Ok(None), | ||
Response::Sat => {} // OK, continue | ||
} | ||
|
||
// find a minimal repair | ||
let min_num_changes = minimize_changes(&mut smt_ctx, change_count_ref, &enc)?; | ||
if conf.verbose { | ||
println!("Found a minimal solution with {min_num_changes} changes.") | ||
} | ||
|
||
let solution = synth_vars.read_assignment(&mut smt_ctx, &enc); | ||
Ok(Some(vec![solution])) | ||
} | ||
|
||
Ok(None) | ||
fn minimize_changes( | ||
smt_ctx: &mut smt::Context, | ||
change_count_ref: ExprRef, | ||
enc: &impl TransitionSystemEncoding, | ||
) -> Result<u32> { | ||
let mut num_changes = 1u32; | ||
let change_count_expr = enc.get_at(smt_ctx, change_count_ref, 0); | ||
loop { | ||
let constraint = smt_ctx.eq( | ||
change_count_expr, | ||
smt_ctx.binary(CHANGE_COUNT_WIDTH as usize, num_changes), | ||
); | ||
match smt_ctx.check_assuming([constraint])? { | ||
Response::Sat => { | ||
// found a solution | ||
return Ok(num_changes); | ||
} | ||
Response::Unsat => {} | ||
Response::Unknown => panic!("SMT solver returned unknown!"), | ||
} | ||
num_changes += 1; | ||
} | ||
} | ||
|
||
fn constrain_starting_state( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters