def serialize_solution(base_path: Path, solution: Solution) -> Path: """ Serializes the given solution (pickle, network_description, graphs, optimization results...) into a folder and returns its path """ path = base_path / solution.get_folder_name() path.mkdir(parents=True, exist_ok=True) # Pickle solution object with open(path / "solution.pickle", "wb") as f: # Pickle solution object pickle.dump(solution, f, pickle.HIGHEST_PROTOCOL) f.close() # Create flex_network_description create_flex_network_description( path / "{}_mode{}.flex_network_description".format( solution.input_params.tc_name, solution.input_params.mode.value), solution.tc, ) # Output scheduling time with open(path / "scheduling_time.txt", "w") as f: f.write("Total time (ms):\n" + str(solution.timing_object.get_total_time()) + "\nScheduling time (ms):\n" + str(solution.timing_object.time_optimizing_scheduling)) # Create graphviz graphs svg_path = path / "svg" svg_path.mkdir(exist_ok=True) serialize_graphs(svg_path, solution) # Create plotly schedules fig = solution_parser.get_solution_schedule_plotly(solution) if fig is not None: fig.write_html(str(path / "schedule.html")) try: fig.write_image(str(path / "schedule.pdf"), width=1920, height=640, engine="kaleido") except Exception as e: raise e # Append to results.csv df = solution_parser.get_solution_results_info_dataframe(solution) df.insert(0, "Testcase Name", solution.get_folder_name()) with open(base_path / "solutions.csv", "a") as f: df.to_csv(f, header=f.tell() == 0, index=False) return path
def get_testcase_topology_graph(solution: Solution) -> str: """ Returns a html.img src string of the topology graph """ svg_file_path = Path( "testcases/output/{}/svg/base_topology.gv.svg".format( solution.get_folder_name() ) ) encoded = base64.b64encode(open(svg_file_path, "rb").read()) svg = "data:image/svg+xml;base64,{}".format(encoded.decode()) return svg
def get_derived_security_application_taskgraphs(solution: Solution) -> Dict[str, str]: """ Returns a dictionary mapping app_id's to html.img src strings of the application taskgraphs """ app_id_graph_b64_map = {} for app in solution.tc.A_sec.values(): svg_file_path = Path( "testcases/output/{}/svg/taskgraph_{}.svg".format( solution.get_folder_name(), app.id ) ) encoded = base64.b64encode(open(svg_file_path, "rb").read()) svg = "data:image/svg+xml;base64,{}".format(encoded.decode()) app_id_graph_b64_map[app.id] = svg return app_id_graph_b64_map