Ejemplo n.º 1
0
def establish_new_server_port_for_service(service_name: str) -> int:
    with FileLock(f"{PORT_LISTING_PATH}.lock"):
        file_mode = "r+" if os.path.exists(PORT_LISTING_PATH) else "w+"
        with open(PORT_LISTING_PATH, file_mode) as port_listing_file:
            retries = 10
            for retry in range(retries):
                file_is_empty = os.path.getsize(PORT_LISTING_PATH) == 0
                port_listings: Dict[str, str] = {}
                if not file_is_empty:
                    port_listings: Dict[str,
                                        str] = json.load(port_listing_file)
                claimed_ports_from_file = list(
                    int(p) for p in port_listings.values())
                free_port_from_os = find_free_port()
                if (free_port_from_os in claimed_ports_from_file and
                        port_listings.get(service_name) != free_port_from_os):
                    time.sleep(0.05)
                    continue
                port_listings[service_name] = free_port_from_os
                port_listing_file.seek(0)
                json.dump(port_listings, port_listing_file)
                port_listing_file.truncate()
                return free_port_from_os
            raise ConnectionError(
                f"Couldn't find an unclaimed free port for service name {service_name} "
                f"in {retries} retries.")
Ejemplo n.º 2
0
    }

    avg_pol_scenario: NFSPScenario = scenario_catalog.get(
        scenario_name="1000_oshi_zumo_nfsp_larger_dqn_larger")

    trainer_class = PPOTrainer

    tmp_env = env_class(env_config=env_config)

    address_info = ray.init(num_cpus=num_cpus,
                            num_gpus=num_gpus,
                            object_store_memory=int(1073741824 * 1),
                            local_mode=False,
                            include_dashboard=True,
                            dashboard_host="0.0.0.0",
                            dashboard_port=find_free_port(),
                            ignore_reinit_error=True,
                            logging_level=logging.INFO,
                            log_to_driver=os.getenv("RAY_LOG_TO_DRIVER",
                                                    False))

    def select_policy(agent_id):
        if agent_id == br_player:
            return "best_response"
        else:
            return f"average_policy"

    avg_policy_model_config = avg_pol_scenario.get_avg_trainer_config(
        tmp_env)["model"]

    player_0_avg_pol_spec = StrategySpec.from_json_file(