From cdb831a47b962ba907df8eb6c6ca3f3095dedd6b Mon Sep 17 00:00:00 2001 From: 0xFugue <119708655+0xFugue@users.noreply.github.com> Date: Fri, 1 Sep 2023 11:45:05 +0530 Subject: [PATCH] build_cases: duplicate configs --- build_cases.py | 47 +++++++++++++++++++++++++++++++++++++++++ run.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ scripts/build_cases.py | 17 ++++++++++++--- 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 build_cases.py create mode 100644 run.sh diff --git a/build_cases.py b/build_cases.py new file mode 100644 index 0000000..045d283 --- /dev/null +++ b/build_cases.py @@ -0,0 +1,47 @@ +import os +import csv +import json +import random +import shutil +from build_config import build_config + +def build_case(overlay, committees, nodes, config_name, max_view=1, network='default'): + build_config(overlay, committees, nodes, config_name, max_view, network) + # rename the runs with same configs + if os.path.exists(f"../configs/{config_name}.json"): + tail = random.randint(1, 10000) + modified_name = f"{config_name}_{tail}" + os.rename(f"{config_name}.json", f"{modified_name}.json") + with open(f"{modified_name}.json", "r+") as f: + data = json.load(f) + data["stream_settings"]["path"] = f"{modified_name}.json" + f.seek(0) + json.dump(data, f) + f.truncate() + print((config_name, modified_name)) + config_name = modified_name + shutil.move(f"{config_name}.json", "../configs/") + +def build_cases(csv_path): + with open(csv_path, 'r') as csv_file: + reader = csv.reader(csv_file) + for row in reader: + overlay_type, node_count, committees, desc = row + if overlay_type == "overlay": + continue + config_name = f"{overlay_type}_{node_count}_{committees}" + # build_case(overlay_type, committees, node_count, f"{config_name}_view_1_default") + # build_case(overlay_type, committees, node_count, f"{config_name}_view_10_default", max_view="5") + # build_case(overlay_type, committees, node_count, f"{config_name}_view_10_optimistic", max_view="5", network="optimistic") + # build_case(overlay_type, committees, node_count, f"{config_name}_view_10_pessimistic", max_view="5", network="pessimistic") + build_case(overlay_type, committees, node_count, f"{config_name}_view_10_nolat", max_view="10", network="nolat") + +if __name__ == "__main__": + import sys + if len(sys.argv) != 2: + print("Usage: python generate_configs.py ") + sys.exit(1) + + csv_path = sys.argv[1] + build_cases(csv_path) + diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..6cff076 --- /dev/null +++ b/run.sh @@ -0,0 +1,48 @@ + +#for i in "10 100 200 300 400 500 600 700 800 900 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000" +prefix="compare" +for p in 0.8 0.5 #0.1 0.01 0.001 0.0001 +do + dir="compare_"$p"/" + mkdir -p $dir + echo "overlay,nodes,committees_or_depth,description" > $dir$prefix"_"$p".csv" + for i in 10 50 100 250 500 #750 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 12000 1400 + do + python3 build_tests.py --num-nodes $i --failure-threshold $p >> $dir$prefix"_"$p".csv" + echo "num-nodes = $i, failure-threshold = $p" + done +done + + + +for p in 0.8 0.5 0.1 0.01 0.001 0.0001 +do + dir="compare_"$p"/" + cd $dir + mkdir configs output scripts + cp ../*.py scripts + cd scripts + ln -s ../../config_builder/ + python3 build_cases.py ../$prefix"_"$p".csv" + cd .. + python3 scripts/run_configs.py configs/ + rm -rf scripts + cd .. + echo "config gen ($p) done.." +done + + + +for p in 0.8 0.5 #0.1 0.01 0.001 0.0001 +do + + dir="compare_"$p"/" + cd $dir + pwd + ls -l output/*.json | awk '{print $9}' > json_files + sed -e s/\.json//g -i json_files + for i in `cat json_files` + do + mv output/$i.json output/$i.csv + done +done diff --git a/scripts/build_cases.py b/scripts/build_cases.py index 0f6c4c9..045d283 100644 --- a/scripts/build_cases.py +++ b/scripts/build_cases.py @@ -1,14 +1,25 @@ import os import csv +import json +import random import shutil from build_config import build_config def build_case(overlay, committees, nodes, config_name, max_view=1, network='default'): build_config(overlay, committees, nodes, config_name, max_view, network) + # rename the runs with same configs if os.path.exists(f"../configs/{config_name}.json"): - os.rename(f"{config_name}.json", f"{config_name}1.json") - config_name=f"{config_name}1" - print(config_name) + tail = random.randint(1, 10000) + modified_name = f"{config_name}_{tail}" + os.rename(f"{config_name}.json", f"{modified_name}.json") + with open(f"{modified_name}.json", "r+") as f: + data = json.load(f) + data["stream_settings"]["path"] = f"{modified_name}.json" + f.seek(0) + json.dump(data, f) + f.truncate() + print((config_name, modified_name)) + config_name = modified_name shutil.move(f"{config_name}.json", "../configs/") def build_cases(csv_path):