How to use the ray.services.get_node_ip_address function in ray

To help you get started, we’ve selected a few ray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ray-project / ray / python / ray / rllib / examples / carla / train_a3c.py View on Github external
env_config = ENV_CONFIG.copy()
env_config.update({
    "verbose": False,
    "x_res": 80,
    "y_res": 80,
    "squash_action_logits": grid_search([False, True]),
    "use_depth_camera": False,
    "discrete_actions": False,
    "server_map": "/Game/Maps/Town02",
    "reward_function": grid_search(["custom", "corl2017"]),
    "scenarios": TOWN2_STRAIGHT,
})

register_carla_model()
redis_address = ray.services.get_node_ip_address() + ":6379"

ray.init(redis_address=redis_address)
run_experiments({
    "carla-a3c": {
        "run": "A3C",
        "env": CarlaEnv,
        "config": {
            "env_config": env_config,
            "use_gpu_for_workers": True,
            "model": {
                "custom_model": "carla",
                "custom_options": {
                    "image_shape": [80, 80, 6],
                },
                "conv_filters": [
                    [16, [8, 8], 4],
github ray-project / ray / python / ray / tune / trainable.py View on Github external
def current_ip(self):
        logger.warning("Getting current IP.")
        self._local_ip = ray.services.get_node_ip_address()
        return self._local_ip
github ray-project / ray / python / ray / tune / syncer.py View on Github external
def __init__(self, local_dir, remote_dir, sync_client):
        self.local_ip = services.get_node_ip_address()
        self.worker_ip = None
        super(NodeSyncer, self).__init__(local_dir, remote_dir, sync_client)
github intel-analytics / analytics-zoo / pyzoo / zoo / ray / util / __init__.py View on Github external
def _shutdown_per_node(iter):
        print("Stopping pgids: {}".format(pgids))
        if node_ips:
            current_node_ip = rservices.get_node_ip_address()
            effect_pgids = [pair[0] for pair in zip(pgids, node_ips) if pair[1] == current_node_ip]
        else:
            effect_pgids = pgids
        for pgid in effect_pgids:
            print("Stopping by pgid {}".format(pgid))
            try:
                os.killpg(pgid, signal.SIGTERM)
            except Exception:
                print("WARNING: cannot kill pgid: {}".format(pgid))
github ray-project / ray / python / ray / services.py View on Github external
redis_client: A client for the primary Redis shard.

    Raises:
        Exception: An exception is raised if there is a version mismatch.
    """
    redis_reply = redis_client.get("VERSION_INFO")

    # Don't do the check if there is no version information in Redis. This
    # is to make it easier to do things like start the processes by hand.
    if redis_reply is None:
        return

    true_version_info = tuple(json.loads(ray.utils.decode(redis_reply)))
    version_info = _compute_version_info()
    if version_info != true_version_info:
        node_ip_address = ray.services.get_node_ip_address()
        error_message = ("Version mismatch: The cluster was started with:\n"
                         "    Ray: " + true_version_info[0] + "\n"
                         "    Python: " + true_version_info[1] + "\n"
                         "    Pyarrow: " + str(true_version_info[2]) + "\n"
                         "This process on node " + node_ip_address +
                         " was started with:" + "\n"
                         "    Ray: " + version_info[0] + "\n"
                         "    Python: " + version_info[1] + "\n"
                         "    Pyarrow: " + str(version_info[2]))
        if version_info[:2] != true_version_info[:2]:
            raise Exception(error_message)
        else:
            logger.warning(error_message)
github ray-project / ray / python / ray / resource_spec.py View on Github external
def resolve(self, is_head):
        """Returns a copy with values filled out with system defaults."""

        resources = (self.resources or {}).copy()
        assert "CPU" not in resources, resources
        assert "GPU" not in resources, resources
        assert "memory" not in resources, resources
        assert "object_store_memory" not in resources, resources

        # Automatically create a node id resource on each node. This is
        # queryable with ray.state.node_ids() and ray.state.current_node_id().
        resources[NODE_ID_PREFIX + ray.services.get_node_ip_address()] = 1.0

        num_cpus = self.num_cpus
        if num_cpus is None:
            num_cpus = multiprocessing.cpu_count()

        num_gpus = self.num_gpus
        gpu_ids = ray.utils.get_cuda_visible_devices()
        # Check that the number of GPUs that the raylet wants doesn't
        # excede the amount allowed by CUDA_VISIBLE_DEVICES.
        if (num_gpus is not None and gpu_ids is not None
                and num_gpus > len(gpu_ids)):
            raise Exception("Attempting to start raylet with {} GPUs, "
                            "but CUDA_VISIBLE_DEVICES contains {}.".format(
                                num_gpus, gpu_ids))
        if num_gpus is None:
            # Try to automatically detect the number of GPUs.
github cybertronai / ncluster / benchmarks / ray_two_machines.py View on Github external
def ip(self):
    return ray.services.get_node_ip_address()
github ray-project / ray / python / ray / reporter.py View on Github external
def __init__(self, redis_address, redis_password=None):
        """Initialize the reporter object."""
        self.cpu_counts = (psutil.cpu_count(), psutil.cpu_count(logical=False))
        self.ip = ray.services.get_node_ip_address()
        self.hostname = os.uname().nodename

        _ = psutil.cpu_percent()  # For initialization

        self.redis_key = "{}.{}".format(ray.gcs_utils.REPORTER_CHANNEL,
                                        self.hostname)
        self.redis_client = ray.services.create_redis_client(
            redis_address, password=redis_password)

        self.network_stats_hist = [(0, (0.0, 0.0))]  # time, (sent, recv)
github ray-project / ray / python / ray / scripts / scripts.py View on Github external
# Check that the arguments match.
            if len(redis_shard_ports) != num_redis_shards:
                raise Exception("If --redis-shard-ports is provided, it must "
                                "have the form '6380,6381,6382', and the "
                                "number of ports provided must equal "
                                "--num-redis-shards (which is 1 if not "
                                "provided)")

        if redis_address is not None:
            raise Exception("If --head is passed in, a Redis server will be "
                            "started, so a Redis address should not be "
                            "provided.")

        # Get the node IP address if one is not provided.
        ray_params.update_if_absent(
            node_ip_address=services.get_node_ip_address())
        logger.info("Using IP address {} for this node.".format(
            ray_params.node_ip_address))
        ray_params.update_if_absent(
            redis_port=redis_port,
            redis_shard_ports=redis_shard_ports,
            redis_max_memory=redis_max_memory,
            num_redis_shards=num_redis_shards,
            redis_max_clients=redis_max_clients,
            autoscaling_config=autoscaling_config,
            include_java=False,
        )

        node = ray.node.Node(ray_params, head=True, shutdown_at_exit=block)
        redis_address = node.redis_address

        logger.info(
github ray-project / ray / python / ray / autoscaler / autoscaler.py View on Github external
def __init__(self):
        self.last_used_time_by_ip = {}
        self.last_heartbeat_time_by_ip = {}
        self.static_resources_by_ip = {}
        self.dynamic_resources_by_ip = {}
        self.resource_load_by_ip = {}
        self.local_ip = services.get_node_ip_address()