def main(args=None): # Fix a bug introduced by an annoying Google extension import absl.logging try: logging.root.removeHandler(absl.logging._absl_handler) absl.logging._warn_preinit_stderr = False except Exception as e: print("Failed to fix absl logging bug", e) logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO) args = get_args(args) if args is None: log.error("Something went wrong while parsing arguments!") exit(1) log.info("Registering the DC environment...") register_env("dc_env", get_env) # Configure all ray input parameters based on the arguments config = configure_ray(args) output_dir = config["env_config"]["output_dir"] # Check if the output directory exists before running dc_utils.check_dir(output_dir) # Dump the configuration dc_utils.dump_json(path=output_dir, name="ray_config", data=config) log.info("Starting Ray...") ts = time.time() ray.init(ignore_reinit_error=True, logging_level=logging.INFO, temp_dir=output_dir, plasma_store_socket_name="/tmp/plasma_socket%s" % ts, raylet_socket_name="/tmp/raylet_socket%s" % ts) log.info("Starting experiment.") if args.tune: tune_run(config, args.episodes, args.root_output, args.schedule) else: run_ray(config, args.episodes) # Wait until the topology is torn down completely # The flaky Mininet stop() call necessitates this # This is an unfortunate reality and may conflict with other ovs setups log.info("Waiting for environment to complete...") wait_for_ovs() # Take control back from root dc_utils.change_owner(args.root_output) # Ray doesn't play nice and prevents proper shutdown sometimes ray.shutdown() # time.sleep(1) # kill_ray() log.info("Experiment has completed.")
def dump_config(path, pattern): test_config = {} test_config["transport"] = TRANSPORT test_config["episodes"] = EPISODES test_config["runs"] = RUNS test_config["topology"] = TOPO test_config["tcp_algorithms"] = TCP_ALGOS test_config["rl_algorithms"] = RL_ALGOS test_config["rates"] = NETWORK_RATES test_config["pattern"] = pattern # Get a string formatted time stamp ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d_%H_%M_%S') test_config["timestamp"] = st dc_utils.dump_json(path=path, name="bench_config", data=test_config)
def __init__(self, conf={}): self.conf = DEFAULT_CONF self.conf.update(conf) # Init one-to-one mapped variables self.net_man = None self.state_man = None self.traffic_gen = None self.bw_ctrl = None self.sampler = None self.input_file = None self.terminated = False self.reward = RawValue('d', 0) # set the id of this environment self.short_id = dc_utils.generate_id() if self.conf["parallel_envs"]: self.conf["topo_conf"]["id"] = self.short_id # initialize the topology self.topo = TopoFactory.create(self.conf["topo"], self.conf["topo_conf"]) # Save the configuration we have, id does not matter here dc_utils.dump_json(path=self.conf["output_dir"], name="env_config", data=self.conf) dc_utils.dump_json(path=self.conf["output_dir"], name="topo_config", data=self.topo.conf) # set the dimensions of the state matrix self._set_gym_matrices() # Set the active traffic matrix self._set_traffic_matrix(self.conf["tf_index"], self.conf["input_dir"], self.topo) # each unique id has its own sub folder if self.conf["parallel_envs"]: self.conf["output_dir"] += f"/{self.short_id}" # check if the directory we are going to work with exists dc_utils.check_dir(self.conf["output_dir"]) # handle unexpected exits scenarios gracefully atexit.register(self.close)