def __init__(self, args): super().__init__() self.args = args self.device = torch.device( 'cuda' if torch.cuda.is_available() else 'cpu') self.nets, self.nets_ema = build_model(args) # self.arcface, self.conf = load_arcface() # self.arcface = load_arcface_2() self.writer = SummaryWriter( 'log/test_vox_256_smalldata_id_1_20_20_retrain_alldata_id_embedder_vggface_add_noise' ) # print(self.arcface) # assert False # below setattrs are to make networks be children of Solver, e.g., for self.to(self.device) for name, module in self.nets.items(): utils.print_network(module, name) setattr(self, name, module) for name, module in self.nets_ema.items(): setattr(self, name + '_ema', module) if args.mode == 'train': self.optims = Munch() for net in self.nets.keys(): if net == 'fan': continue self.optims[net] = torch.optim.Adam( params=self.nets[net].parameters(), lr=args.f_lr if net == 'mapping_network' else args.lr, betas=[args.beta1, args.beta2], weight_decay=args.weight_decay) # self.ckptios = [ # CheckpointIO(ospj(args.checkpoint_dir, '{:06d}_nets.ckpt'), **self.nets), # CheckpointIO(ospj(args.checkpoint_dir, '{:06d}_nets_ema.ckpt'), **self.nets_ema), # CheckpointIO(ospj(args.checkpoint_dir, '{:06d}_optims.ckpt'), **self.optims)] self.ckptios = [ CheckpointIO(ospj(args.checkpoint_dir, '{}_nets.ckpt'), **self.nets), CheckpointIO(ospj(args.checkpoint_dir, '{}_nets_ema.ckpt'), **self.nets_ema), CheckpointIO(ospj(args.checkpoint_dir, '{}_optims.ckpt'), **self.optims) ] else: self.ckptios = [ CheckpointIO( ospj(args.checkpoint_dir, '{}_nets_ema.ckpt'.format(args.resume_iter)), **self.nets_ema) ] # self.ckptios = [CheckpointIO(ospj(args.checkpoint_dir, '{:06d}_nets_ema.ckpt'), **self.nets_ema)] self.to(self.device) for name, network in self.named_children(): # Do not initialize the FAN parameters if ('ema' not in name) and ('fan' not in name): print('Initializing %s...' % name) network.apply(utils.he_init)
def run(protocol, csvfile): for path in sorted(glob.glob(f'../../data/grid4/*.json')): state = tools.load_json(path) (node_count, link_count) = tools.json_count(state) print(f'run {protocol} on {path}') network.apply(state=state, link_command=get_tc_command, remotes=remotes) tools.sleep(10) software_start_ms = tools.millis() software.start(protocol, remotes) software_startup_ms = tools.millis() - software_start_ms tools.sleep(30) paths = tools.get_random_paths(state, 2 * link_count) paths = tools.filter_paths(state, paths, min_hops=2, path_count=link_count) ping_result = tools.ping_paths(remotes=remotes, paths=paths, duration_ms=30000, verbosity='verbose') sysload_result = tools.sysload(remotes) software.clear(remotes) # add data to csv file extra = (['node_count', 'software_startup_ms'], [node_count, software_startup_ms]) tools.csv_update(csvfile, '\t', extra, ping_result.getData(), sysload_result) network.clear(remotes) # abort benchmark when less then 40% of the pings arrive if (ping_result.received / ping_result.transmitted) < 0.4: break
def run(protocol, csvfile, step_duration, step_distance): shared.seed_random(42) node_count = 50 state = topology.create_nodes(node_count) mobility.randomize_positions(state, xy_range=1000) mobility.connect_range(state, max_links=150) # create network and start routing software network.apply(state, link_command=get_tc_command, remotes=remotes) software.start(protocol) test_beg_ms = shared.millis() for n in range(0, 30): print(f'{protocol}: iteration {n}') #with open(f'graph-{step_duration}-{step_distance}-{n:03d}.json', 'w+') as file: # json.dump(state, file, indent=' ') # connect nodes range wait_beg_ms = shared.millis() # update network representation mobility.move_random(state, distance=step_distance) mobility.connect_range(state, max_links=150) # update network tmp_ms = shared.millis() network.apply(state=state, link_command=get_tc_command, remotes=remotes) #software.apply(protocol=protocol, state=state) # we do not change the node count network_ms = shared.millis() - tmp_ms # Wait until wait seconds are over, else error shared.wait(wait_beg_ms, step_duration) paths = ping.get_random_paths(state, 2 * 400) paths = ping.filter_paths(state, paths, min_hops=2, path_count=200) ping_result = ping.ping(paths=paths, duration_ms=2000, verbosity='verbose', remotes=remotes) # add data to csv file extra = (['node_count', 'time_ms'], [node_count, shared.millis() - test_beg_ms]) shared.csv_update(csvfile, '\t', extra, ping_result.getData()) software.clear(remotes) network.clear(remotes)
def run(protocol, csvfile): tools.seed_random(23) node_count = 50 state = topology.create_nodes(node_count) mobility.randomize_positions(state, xy_range=1000) mobility.connect_range(state, max_links=150) # create network and start routing software network.apply(state=state, link_command=get_tc_command) software.start(protocol) tools.sleep(30) for step_distance in [50, 100, 150, 200, 250, 300, 350, 400]: print(f'{protocol}: step_distance {step_distance}') traffic_beg = tools.traffic() for n in range(0, 6): #with open(f'graph-{step_distance}-{n}.json', 'w+') as file: # json.dump(state, file, indent=' ') # connect nodes range wait_beg_ms = tools.millis() # update network representation mobility.move_random(state, distance=step_distance) mobility.connect_range(state, max_links=150) # update network network.apply(state=state, link_command=get_tc_command) # Wait until wait seconds are over, else error tools.wait(wait_beg_ms, 10) paths = tools.get_random_paths(state, 2 * 200) paths = tools.filter_paths(state, paths, min_hops=2, path_count=200) ping_result = tools.ping_paths(paths=paths, duration_ms=2000, verbosity='verbose') packets_arrived_pc = 100 * (ping_result.received / ping_result.send) traffic_end = tools.traffic() # add data to csv file extra = (['node_count', 'time_ms', 'step_distance_m', 'n', 'packets_arrived_pc'], [node_count, tools.millis() - wait_beg_ms, step_distance, n, packets_arrived_pc]) tools.csv_update(csvfile, '\t', extra, (traffic_end - traffic_beg).getData(), ping_result.getData()) traffic_beg = traffic_end software.clear() network.clear()
def run(protocol, files, csvfile): tools.seed_random(1234) for path in sorted(glob.glob(files)): state = tools.load_json(path) (node_count, link_count) = tools.json_count(state) print(f'run {protocol} on {path}') network.apply(state=state, link_command=get_tc_command) tools.sleep(10) for offset in range(0, 60, 2): tmp_ms = tools.millis() traffic_beg = tools.traffic() traffic_ms = tools.millis() - tmp_ms tmp_ms = tools.millis() software.start(protocol) software_ms = tools.millis() - tmp_ms # Wait until wait seconds are over, else error tools.sleep(offset) paths = tools.get_random_paths(state, 2 * 200) paths = tools.filter_paths(state, paths, min_hops=2, path_count=200) ping_result = tools.ping_paths(paths=paths, duration_ms=2000, verbosity='verbose') traffic_end = tools.traffic() sysload_result = tools.sysload() software.clear() # add data to csv file extra = (['node_count', 'traffic_ms', 'software_ms', 'offset_ms'], [node_count, traffic_ms, software_ms, offset * 1000]) tools.csv_update(csvfile, '\t', extra, (traffic_end - traffic_beg).getData(), ping_result.getData(), sysload_result) network.clear()
def run(protocol, files, csvfile): for path in sorted(glob.glob(files)): state = shared.load_json(path) (node_count, link_count) = shared.json_count(state) # Limit node count to 300 if node_count > 300: continue print(f'run {protocol} on {path}') network.apply(state=state, link_command=get_tc_command, remotes=remotes) shared.sleep(10) software_start_ms = shared.millis() software.start(protocol, remotes) software_startup_ms = shared.millis() - software_start_ms shared.sleep(300) start_ms = shared.millis() traffic_beg = traffic.traffic(remotes) paths = ping.get_random_paths(state, 2 * 200) paths = ping.filter_paths(state, paths, min_hops=2, path_count=200) ping_result = ping.ping(remotes=remotes, paths=paths, duration_ms=300000, verbosity='verbose') traffic_ms = shared.millis() - start_ms traffic_end = traffic.traffic(remotes) sysload_result = shared.sysload(remotes) software.clear(remotes) network.clear(remotes) # add data to csv file extra = (['node_count', 'traffic_ms', 'software_startup_ms'], [node_count, traffic_ms, software_startup_ms]) shared.csv_update(csvfile, '\t', extra, (traffic_end - traffic_beg).getData(), ping_result.getData(), sysload_result)
def run(protocol, tasks, csvfile): for path, gateways in tasks: state = shared.load_json(path) (node_count, link_count) = shared.json_count(state) # Limit node count to 300 if node_count > 300: continue print(f'run {protocol} on {path}') network.apply(state=state, remotes=remotes) shared.sleep(10) software_start_ms = shared.millis() software.start(protocol, remotes) software_startup_ms = shared.millis() - software_start_ms shared.sleep(30) start_ms = shared.millis() traffic_beg = traffic.traffic(remotes) paths = ping.get_paths_to_gateways(state, gateways) ping_result = ping.ping(remotes=remotes, paths=paths, duration_ms=300000, verbosity='verbose') traffic_ms = shared.millis() - start_ms traffic_end = traffic.traffic(remotes) sysload_result = shared.sysload(remotes) software.clear(remotes) network.clear(remotes) # add data to csv file extra = (['node_count', 'traffic_ms', 'software_startup_ms'], [node_count, traffic_ms, software_startup_ms]) shared.csv_update(csvfile, '\t', extra, (traffic_end - traffic_beg).getData(), ping_result.getData(), sysload_result)
def run(protocol, csvfile): shared.seed_random(1377) for path in sorted(glob.glob(f'../../data/freifunk/*.json')): state = shared.load_json(path) (node_count, link_count) = shared.json_count(state) dataset_name = '{}-{:04d}'.format(os.path.basename(path)[9:-5], node_count) # limit to what the host can handle if node_count > 310: continue print(f'run {protocol} on {path}') state = network.apply(state=state, link_command=get_tc_command, remotes=remotes) shared.sleep(10) software.start(protocol, remotes) shared.sleep(300) start_ms = shared.millis() traffic_beg = traffic.traffic(remotes) paths = ping.get_random_paths(state, 2 * node_count) paths = shared.filter_paths(state, paths, min_hops=2, path_count=node_count) ping_result = shared.ping(remotes=remotes, paths=paths, duration_ms=300000, verbosity='verbose') sysload_result = shared.sysload(remotes) traffic_ms = shared.millis() - start_ms traffic_end = traffic.traffic(remotes) software.clear(remotes) # add data to csv file extra = (['dataset_name', 'node_count', 'traffic_ms'], [dataset_name, node_count, traffic_ms]) shared.csv_update(csvfile, '\t', extra, (traffic_end - traffic_beg).getData(), ping_result.getData(), sysload_result) network.clear(remotes)
protocols = [ 'babel', 'batman-adv', 'bmx6', 'bmx7', 'cjdns', 'olsr1', 'olsr2', 'ospf', 'yggdrasil' ] for topology in ['line', 'grid4', 'grid8', 'rtree']: for path in sorted(glob.glob(f'../../data/{topology}/*.json')): state = shared.load_json(path) (node_count, link_count) = shared.json_count(state) # No test to be done for this topology if all((f'{p}_{topology}' in drop_test) for p in protocols): continue # Create network network.apply(state=state, remotes=remotes) for protocol in protocols: if f'{protocol}_{topology}' in drop_test: continue pc = run(topology, path, state) # Skip test if the successful pings drop below 60% if pc < 60: print( f'Less than 60% successful pings for {protocol} on {topology} with {node_count} nodes => skip other' ) drop_test.add(f'{protocol}_{topology}') # Remove network