def parse_arguments(module, argv): arguments_module = algorithm.import_algorithm(module, extras=["Arguments"]) a = arguments_module.Arguments.Arguments() a.parse(argv) return a
def __init__(self, sim_name, algorithm_modules, comparison_functions, remove_redundant_parameters=False): self.algorithm_modules = [ algorithm.import_algorithm(module) if isinstance(module, str) else module for module in algorithm_modules ] self.sim_name = sim_name self.safety_factor_indexes = {} self.comparison_functions = comparison_functions self.remove_redundant_parameters = remove_redundant_parameters self.dominated_data = None raise RuntimeError("Broken, come to Matt to fix me later") self.global_parameter_names = sim.global_parameter_names[:-1]
from datetime import timedelta import itertools import os.path from simulator import CommandLineCommon import simulator.sim import algorithm protectionless = algorithm.import_algorithm("protectionless", extras=["Analysis"]) adaptive_spr_notify = algorithm.import_algorithm("adaptive_spr_notify", extras=["Analysis"]) adaptive_spr_notify_tinyoslpl = algorithm.import_algorithm( "adaptive_spr_notify_tinyoslpl", extras=["Analysis"]) from data import results, submodule_loader from data.table import fake_result from data.graph import summary, min_max_versus from data.util import scalar_extractor import data.testbed safety_period_equivalence = {"low power listening": {"enabled": "disabled"}} class CLI(CommandLineCommon.CLI): def __init__(self): super().__init__(protectionless.name, safety_period_equivalence=safety_period_equivalence) subparser = self._add_argument("table", self._run_table) subparser.add_argument("sim",
def all_results(algorithms): modules = [algorithm.import_algorithm(algo) for algo in algorithms] module_results = [ results.Results(module.result_file_path, parameters=module.local_parameter_names, results=result_names) for module in modules ] for (name, module_result) in zip(algorithms, module_results): safety_factor_indexes[name] = module_result.parameter_names.index( "safety factor") parameters = {} for result in module_results: parameters.update(dict(result.parameters())) parameters_to_remove = [k for (k, v) in parameters.items() if len(v) == 1] new_global_parameters = tuple([ name for name in global_parameter_names[:-1] if name not in parameters_to_remove ]) results_data = [ transform_results_data(result.data, parameters_to_remove) for result in module_results ] combined_data = {} for (algo_name, result_data) in zip(algorithms, results_data): safety_factor_idx = safety_factor_indexes[algo_name] for (global_params, items1) in result_data.items(): if global_params not in combined_data: combined_data[global_params] = {} for (source_period, items2) in items1.items(): if source_period not in combined_data[global_params]: combined_data[global_params][source_period] = {} for (local_params, algo_results) in items2.items(): safety_factor = local_params[safety_factor_idx] if safety_factor not in combined_data[global_params][ source_period]: combined_data[global_params][source_period][ safety_factor] = {} new_local_params = transform_key(local_params, safety_factor_idx) combined_data[global_params][source_period][safety_factor][ (algo_name, new_local_params)] = algo_results return new_global_parameters, combined_data
import itertools import math import os.path import numpy as np from data.results_transformer import EliminateDominatedResultsTransformer import simulator.sim from simulator import CommandLineCommon from simulator import Configuration #import algorithm.protectionless as protectionless import algorithm protectionless = algorithm.import_algorithm("protectionless") phantom_chen = algorithm.import_algorithm("phantom_chen") #lprouting_chen = algorithm.import_algorithm("ilprouting_chen") #adaptive_spr_notify_chen = algorithm.import_algorithm("adaptive_spr_notify_chen") #protectionless_chen = algorithm.import_algorithm("protectionless_chen") #protectionless_ctp_chen = algorithm.import_algorithm("protectionless_ctp_chen") from data import results from data.table import safety_period, fake_result from data.graph import summary, versus, min_max_versus from data.util import scalar_extractor, useful_log10 from data.run.common import RunSimulationsCommon from data import submodule_loader
from __future__ import print_function, division import itertools import os import datetime import simulator.sim from simulator import CommandLineCommon import simulator.Configuration import algorithm protectionless_tdma_das = algorithm.import_algorithm("protectionless_tdma_das", extras=["Analysis"]) from data import results, submodule_loader from data.run.common import RunSimulationsCommon from data.graph import summary, versus, baseline_versus from data.table import safety_period from data.util import scalar_extractor class RunSimulations(RunSimulationsCommon): def _get_safety_period(self, darguments): # tafn = super(RunSimulations, self)._get_safety_period(darguments) #XXX Ugly hack using 0 as seed but we need the config only for SSD configuration = simulator.Configuration.create( darguments["configuration"], { "seed": 0, **darguments
#!/usr/bin/env python3 import sys import numpy as np import algorithm if __name__ == "__main__": from simulator import dependency dependency.check_all() args = [] if len(sys.argv[1:]) == 0: raise RuntimeError( "No arguments provided! Please provide the name of the algorithm.") else: args = sys.argv[1:] algorithm_name = args[0] args = args[1:] algorithm_module = algorithm.import_algorithm(algorithm_name, extras=["CommandLine"]) # Raise all numpy errors np.seterr(all='raise') cli = algorithm_module.CommandLine.CLI() cli.run(args)
def main(argv): # Print a traceback in the case of segfaults faulthandler.enable() if __debug__: if len(argv) <= 1: print( "Please provide the algorithm module as the first parameter. (e.g., algorithm.protectionless)", file=sys.stderr) return 1 module = argv[1] if __debug__: if not (module.startswith('algorithm.') or module.startswith('cluster.')): print( "You can only run algorithms in the 'algorithm' or 'cluster' module.", file=sys.stderr) return 2 algorithm_module = algorithm.import_algorithm(module, extras=["Arguments"]) a = algorithm_module.Arguments.Arguments() a.parse(argv[2:]) sim = submodule_loader.load(simulator.sim, a.args.sim) if a.args.mode in ("SINGLE", "GUI", "RAW", "PARALLEL"): sim.build(module, a) # Make the mode SINGLE, as PROFILE is SINGLE except for not building the code if a.args.mode == "PROFILE": a.args.mode = "SINGLE" # Set the thread count, but only for jobs that need it if hasattr(a.args, "thread_count") and a.args.thread_count is None: import psutil # Set the number of usable CPUs a.args.thread_count = len(psutil.Process().cpu_affinity()) # When doing cluster array jobs only print out this header information on the first job if a.args.mode != "CLUSTER" or a.args.job_id is None or a.args.job_id == 1: from datetime import datetime metrics_class = MetricsCommon.import_algorithm_metrics( module, a.args.sim, a.args.extra_metrics) # Print out the versions of slp-algorithms-tinyos and tinyos being used print(f"@version:python={VersionDetection.python_version()}") print(f"@version:numpy={VersionDetection.numpy_version()}") print( f"@version:slp-algorithms={VersionDetection.slp_algorithms_version()}" ) sim.print_version() # Print other potentially useful meta data print(f"@date:{str(datetime.now())}") print(f"@host:{os.uname()}") # Record what algorithm is being run and under what simulator print(f"@module:{module}") print(f"@sim:{a.args.sim}") # Print out the argument settings sim.print_arguments(module, a) # Print the header for the results metrics_class.print_header() # Make sure this header has been written sys.stdout.flush() # Because of the way TOSSIM is architectured each individual simulation # needs to be run in a separate process. if a.args.mode in ("GUI", "SINGLE", "RAW"): sim.run_simulation(module, a, print_warnings=True) else: _run_parallel(sim, module, a, argv)
from __future__ import print_function import os.path from simulator import CommandLineCommon import algorithm protectionless = algorithm.import_algorithm("protectionless") adaptive = algorithm.import_algorithm("adaptive") adaptive_spr = algorithm.import_algorithm("adaptive_spr") from data import results from data.table import fake_result, comparison from data.graph import summary, versus, min_max_versus from data.util import scalar_extractor class CLI(CommandLineCommon.CLI): def __init__(self): super(CLI, self).__init__(protectionless.name) subparser = self._subparsers.add_parser("table") subparser = self._subparsers.add_parser("graph") subparser = self._subparsers.add_parser("comparison-table") subparser = self._subparsers.add_parser("min-max-versus") def time_after_first_normal_to_safety_period(self, tafn): return tafn * 2.0 def _run_table(self, args):
from __future__ import print_function, division import itertools import os import datetime from simulator import CommandLineCommon import algorithm protectionless_tdma_das = algorithm.import_algorithm("protectionless_tdma_das") from data import results from data.run.common import RunSimulationsCommon from data.graph import summary, versus, baseline_versus from data.table import safety_period from data.util import scalar_extractor class RunSimulations(RunSimulationsCommon): def _get_safety_period(self, darguments): # tafn = super(RunSimulations, self)._get_safety_period(darguments) network_size = darguments["network size"] search_distance = darguments["search distance"] dissem_period = darguments["dissem period"] slot_period = darguments["slot period"] tdma_num_slots = darguments["tdma num slots"] tdma_period_length = dissem_period + (slot_period * tdma_num_slots) ssd = network_size - 1 #XXX Cheap fix until I find the real solution change_distance = ssd // 3
with open(filename, 'w') as result_file: print("% !TEX root = ../Thesis.tex", file=result_file) latex.print_header(result_file, orientation="portrait") for (sim_name, algos) in sim_and_algo.items(): print(f"\\section{{{titles[sim_name]}}}", file=result_file) for algo in algos: print(f"\\subsection{{{titles[algo]}}}", file=result_file) algorithm_module = algorithm.import_algorithm(algo, extras=["Analysis"]) if sim_name != "real": result_file_path = algorithm_module.result_file_path(sim_name) else: result_file_path = testbed_results_path(algorithm_module) res = results.Results( sim_name, result_file_path, parameters=algorithm_module.local_parameter_names, results=parameters, results_filter=results_filter) result_table = fake_result.ResultTable( res,
def __init__(self, algorithm_modules): self.algorithm_modules = [ algorithm.import_algorithm(module) if isinstance(module, str) else module for module in algorithm_modules ]
import itertools import os import simulator.sim from simulator import CommandLineCommon import algorithm protectionless = algorithm.import_algorithm("protectionless") phantom = algorithm.import_algorithm("phantom", extras=["Analysis"]) from data import submodule_loader, results from data.table import fake_result from data.graph import summary, versus, min_max_versus, dual_min_max_versus from data.util import scalar_extractor safety_period_equivalence = {"low power listening": {"enabled": "disabled"}} class CLI(CommandLineCommon.CLI): def __init__(self): super().__init__(protectionless.name, safety_period_equivalence=safety_period_equivalence) subparser = self._add_argument("table", self._run_table) subparser.add_argument("sim", choices=submodule_loader.list_available( simulator.sim), help="The simulator you wish to run with.") subparser.add_argument("--show", action="store_true", default=False) subparser = self._add_argument("graph", self._run_graph)
from __future__ import print_function from datetime import timedelta import os.path from simulator import CommandLineCommon import simulator.sim import algorithm protectionless = algorithm.import_algorithm("protectionless", extras=["Analysis"]) adaptive = algorithm.import_algorithm("adaptive") template = algorithm.import_algorithm("template") ilprouting = algorithm.import_algorithm("ilprouting") from data import results, submodule_loader from data.table import fake_result from data.graph import summary, min_max_versus from data.util import scalar_extractor import data.testbed class CLI(CommandLineCommon.CLI): def __init__(self): super().__init__(protectionless.name) subparser = self._add_argument("table", self._run_table) subparser.add_argument("sim", choices=submodule_loader.list_available( simulator.sim), help="The simulator you wish to run with.")
from __future__ import print_function import datetime import os.path from simulator import CommandLineCommon import algorithm protectionless_ctp = algorithm.import_algorithm("protectionless_ctp") from data import results from data.graph import summary, versus from data.util import scalar_extractor class CLI(CommandLineCommon.CLI): def __init__(self): super(CLI, self).__init__(protectionless_ctp.result_file_path) subparser = self._add_argument("table", self._run_table) subparser = self._add_argument("graph", self._run_graph) def time_after_first_normal_to_safety_period(self, tafn): return tafn * 2.0 def _cluster_time_estimator(self, sim, args, **kwargs): """Estimates how long simulations are run for. Override this in algorithm specific CommandLine if these values are too small or too big. In general these have been good amounts of time to run simulations for. You might want to adjust the number of repeats to get the simulation time in this range.""" size = args['network size'] if size == 11:
import datetime import itertools import simulator.sim from simulator import CommandLineCommon import algorithm protectionless = algorithm.import_algorithm("protectionless") phantom_chen = algorithm.import_algorithm("phantom_chen") lprouting_chen = algorithm.import_algorithm("ilprouting_chen") adaptive_spr_notify_chen = algorithm.import_algorithm("adaptive_spr_notify_chen") from data import results from data.table import fake_result, comparison from data.graph import summary, min_max_versus, dual_min_max_versus from data.util import scalar_extractor from data import submodule_loader class CLI(CommandLineCommon.CLI): def __init__(self): super(CLI, self).__init__(protectionless.name) subparser = self._add_argument("table", self._run_table) subparser.add_argument("sim", choices=submodule_loader.list_available(simulator.sim), help="The simulator you wish to run with.") subparser.add_argument("--show", action="store_true", default=False) subparser = self._add_argument("graph", self._run_graph)
from __future__ import print_function from datetime import timedelta import os.path from simulator import CommandLineCommon import algorithm protectionless = algorithm.import_algorithm("protectionless") adaptive = algorithm.import_algorithm("adaptive") template = algorithm.import_algorithm("template") from data import results from data.table import fake_result, comparison from data.graph import summary, versus, min_max_versus, dual_min_max_versus from data.util import scalar_extractor safety_period_equivalence = { "attacker model": { "SeqNoReactiveAttacker()": "SeqNosReactiveAttacker()" } } class CLI(CommandLineCommon.CLI): def __init__(self): super(CLI, self).__init__( protectionless.name, safety_period_equivalence=safety_period_equivalence)
from datetime import timedelta import itertools import simulator.sim from simulator import CommandLineCommon import algorithm protectionless = algorithm.import_algorithm("protectionless") from data import submodule_loader # Use the safety periods for SeqNosReactiveAttacker() if none are available for SeqNosOOOReactiveAttacker() safety_period_equivalence = { "attacker model": { "SeqNosOOOReactiveAttacker()": "SeqNosReactiveAttacker()", "SeqNosOOOReactiveAttacker(message_detect='within_range(4.75)')": "SeqNosReactiveAttacker(message_detect='within_range(4.75)')" }, "low power listening": { "enabled": "disabled" }, } class CLI(CommandLineCommon.CLI): def __init__(self): super(CLI, self).__init__( protectionless.name, safety_period_equivalence=safety_period_equivalence)
from __future__ import print_function, division import itertools import os import datetime from simulator import CommandLineCommon import simulator.sim import simulator.Configuration import algorithm slp_tdma_das = algorithm.import_algorithm("slp_tdma_das") from data import results, submodule_loader from data.run.common import RunSimulationsCommon from data.graph import summary, versus from data.table import safety_period from data.util import scalar_extractor class RunSimulations(RunSimulationsCommon): def _get_safety_period(self, darguments): # tafn = super(RunSimulations, self)._get_safety_period(darguments) #XXX Ugly hack using 0 as seed but we need the config only for SSD configuration = simulator.Configuration.create( darguments["configuration"], { "seed": 0, **darguments })