Commit d665e705 authored by Bowen Wu's avatar Bowen Wu
Browse files

Disable timeout, add emphasis, allow two schedulers

parent bf2f8288
......@@ -28,6 +28,12 @@ def parse_args_function():
default="seed/",
help="Place where you store the seeds for fuzzing."
)
parser.add_argument(
"--schedule",
type=str,
default="fifo",
help="Scheduler policy, fifo or pq"
)
parser.add_argument(
"--save_path",
type=str,
......
......@@ -23,7 +23,8 @@ class OptFuzzer(object):
def __init__(self, seed : List,
mut_method : List,
cplex : CplexSolver,
gurobi : GurobiSolver,
gurobi : GurobiSolver,
schedule: str,
save_path : str,
checkpoint_freq : int,
checkpoint_path : str,
......@@ -46,8 +47,11 @@ class OptFuzzer(object):
self.abs_tol = abs_tol
self.diff = [] # mutants that cause differences
self.all_mutant = []
# self.queue = Queue(maxsize=0) # unbounded queue for seeds
self.queue = []
self.schedule = schedule
if self.schedule == 'fifo':
self.queue = Queue(maxsize=0) # unbounded queue for seeds
else:
self.queue = []
self.next_id = 0 # id assigned to the next mutant
print("Initializing seeds")
for s in self.seed:
......@@ -58,16 +62,21 @@ class OptFuzzer(object):
"mut_method" : "",
"mps" : load_mps_dict(s)
}
heapq.heappush(self.queue, ((-1, self.next_id, 1), mutant))
if self.schedule == 'fifo':
self.queue.put_nowait(mutant)
else:
heapq.heappush(self.queue, ((-1, self.next_id, 1), mutant))
self.next_id += 1
# self.queue.put_nowait(mutant)
self.mut_cnt_per_seed = [0] * len(self.seed)
print("Seeds initialized")
def get_mutant(self, mut_choice : str, nr_mutations: int = 3) -> Tuple[dict, dict]:
# parent = self.queue.get()
parent_ent = heapq.heappop(self.queue)
parent = parent_ent[1]
if self.schedule == 'fifo':
parent = self.queue.get()
parent_ent = parent
else:
parent_ent = heapq.heappop(self.queue)
parent = parent_ent[1]
# print(parent_ent[0])
self.mut_cnt_per_seed[parent["root"]] += 1
......@@ -115,11 +124,13 @@ class OptFuzzer(object):
def sol_equal(self, sol1 : dict, sol2 : dict, check_var = False) -> bool:
if sol1['status'] != sol2['status']:
print("Diff ", len(self.diff), " produces different status, ", sol1["status"], " vs. ", sol2["status"])
return False
if sol1['status'] == OPTIMAL:
# check if the obj value is the same
if not math.isclose(sol1['obj_val'], sol2['obj_val'], abs_tol=self.abs_tol):
print("Diff ", len(self.diff), " produces different obj_val, ", sol1['obj_val'], " vs. ", sol2["obj_val"])
return False
# check if the variable values are the same
......@@ -170,10 +181,13 @@ class OptFuzzer(object):
are_equal = self.sol_equal(cplex_sol, gurobi_sol)
scaled_time_diff = self.get_scaled_time_diff(c_time, g_time)
new_key = scaled_time_diff * 1.0 + math.fabs(scaled_time_diff - p[0][2]) * 0
new_key = self.get_perturbed_time_diff(new_key)
heapq.heappush(self.queue, ((-new_key, p[1]["id"], scaled_time_diff), p[1]))
if self.schedule == "fifo":
self.queue.put(p)
else:
scaled_time_diff = self.get_scaled_time_diff(c_time, g_time)
new_key = scaled_time_diff * 1.0 + math.fabs(scaled_time_diff - p[0][2]) * 0
new_key = self.get_perturbed_time_diff(new_key)
heapq.heappush(self.queue, ((-new_key, p[1]["id"], scaled_time_diff), p[1]))
# print("time-diff = ", self.get_perturbed_time_diff(scaled_time_diff))
if not are_equal:
......@@ -257,8 +271,8 @@ def main():
import glob
seed = glob.glob(os.path.join(args.seed_path, "*.mps"))
cpx = CplexSolver()
grb = GurobiSolver()
cpx = CplexSolver(timeout=False)
grb = GurobiSolver(timeout=False)
ts = str(time.time())
print("Timestamp = ", ts)
......@@ -268,8 +282,12 @@ def main():
diff_path = os.path.join(args.diff_path, ts)
max_time = args.max_time
mut_choice = args.mut_choice
schedule = args.schedule
if schedule != "fifo" and schedule != "pq":
parser.print_help()
os.abort()
fuzzer = OptFuzzer(seed, mut_method, cpx, grb, save_path, checkpoint_freq, checkpoint_path, diff_path)
fuzzer = OptFuzzer(seed, mut_method, cpx, grb, schedule, save_path, checkpoint_freq, checkpoint_path, diff_path)
fuzzer.fuzz(max_time, mut_choice)
if __name__ == "__main__":
......
......@@ -58,8 +58,9 @@ class CplexSolver(Solver):
119 : INF_OR_UNBD
}
def __init__(self, verbose = False, timeout = True) -> None:
def __init__(self, verbose = False, timeout = True, emphasis = 0) -> None:
super().__init__(verbose, timeout)
self.emphasis = emphasis
def __call__(self, mps_file: str) -> dict:
model = Cplex()
......@@ -70,6 +71,7 @@ class CplexSolver(Solver):
ps = model.create_parameter_set()
ps.add(model.parameters.threads, 4) # somehow 32 threads is very slow
ps.add(model.parameters.emphasis.mip, self.emphasis)
if self.timeout:
ps.add(model.parameters.timelimit, MAX_TIME_LIMIT)
......
......@@ -3,8 +3,15 @@ import glob
import os
import sys
MIPEmphasisBalanced = 0
MIPEmphasisFeasibility = 1
MIPEmphasisOptimality = 2
MIPEmphasisBestBound = 3
CPX_MIPEMPHASIS_HIDDENFEAS = 4
MIPEmphasisHeuristic = 5
def replay(path):
cpx = CplexSolver(timeout=False)
cpx = CplexSolver(timeout=False, emphasis=MIPEmphasisBestBound)
grb = GurobiSolver(timeout=False)
diff_mps = glob.glob(os.path.join(path, "*.mps"))
print(diff_mps)
......
......@@ -15,8 +15,18 @@ else
fi
set -x
${euler_command} python opt_fuzz.py \
--mut_methods FlipSignMut \
--seed_path seed/ \
--max_time 14400
for mut in FlipSignMut MoreIntMut; do
if [ $mut = "FlipSignMut" ]; then
seed="seed/"
else
seed="seed2/"
fi
for policy in fifo pq; do
${euler_command} python opt_fuzz.py \
--mut_methods $mut \
--seed_path $seed \
--schedule $policy \
--max_time 14400
done
done
set +x
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment