[api] Annotate as public / move ray-core APIs to _private and add enforcement rule (#25695)

Enable checking of the ray core module, excluding serve, workflows, and tune, in ./ci/lint/check_api_annotations.py. This required moving many files to ray._private and associated fixes.
This commit is contained in:
Eric Liang 2022-06-21 15:13:29 -07:00 committed by GitHub
parent 565e366529
commit 43aa2299e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
284 changed files with 2777 additions and 2625 deletions

View file

@ -13,25 +13,30 @@ IGNORE_PATHS = {
".generated.",
".test_utils.",
".annotations.",
".deprecation",
".deprecation.",
".protobuf.",
".cloudpickle.",
}
def _fullname(attr):
"""Fully qualified name of an attribute."""
fullname = ""
if hasattr(attr, "__module__"):
fullname += attr.__module__
if hasattr(attr, "__name__"):
if fullname:
fullname += "."
fullname += attr.__name__
if not fullname:
fullname = str(attr)
try:
if hasattr(attr, "__module__"):
fullname += attr.__module__
if hasattr(attr, "__name__"):
if fullname:
fullname += "."
fullname += attr.__name__
if not fullname:
fullname = str(attr)
except Exception as e:
print("Error qualifying", e)
return fullname
def _ignore(attr):
def _ignore(attr, extra_ignore):
"""Whether an attr should be ignored from annotation checking."""
attr = _fullname(attr)
if "ray." not in attr or "._" in attr:
@ -39,10 +44,13 @@ def _ignore(attr):
for path in IGNORE_PATHS:
if path in attr:
return True
for path in extra_ignore or []:
if path in attr:
return True
return False
def verify(symbol, scanned, ok, output, prefix=None):
def verify(symbol, scanned, ok, output, prefix=None, ignore=None):
"""Recursively verify all child symbols of a given module."""
if not prefix:
prefix = symbol.__name__ + "."
@ -53,7 +61,7 @@ def verify(symbol, scanned, ok, output, prefix=None):
if child.startswith("_"):
continue
attr = getattr(symbol, child)
if _ignore(attr):
if _ignore(attr, ignore):
continue
if (inspect.isclass(attr) or inspect.isfunction(attr)) and prefix in _fullname(
attr
@ -68,7 +76,7 @@ def verify(symbol, scanned, ok, output, prefix=None):
scanned.add(attr)
elif inspect.ismodule(attr):
print("Scanning module", attr)
verify(attr, scanned, ok, output, prefix)
verify(attr, scanned, ok, output, prefix, ignore)
else:
print("Not scanning", attr, type(attr))
@ -77,8 +85,9 @@ if __name__ == "__main__":
import ray.data
import ray.rllib
import ray.serve
import ray.tune
import ray.train
import ray.tune
import ray.workflow
output = set()
ok = set()
@ -89,10 +98,12 @@ if __name__ == "__main__":
verify(ray.rllib, set(), ok, output)
verify(ray.air, set(), ok, output)
verify(ray.train, set(), ok, output)
verify(ray, set(), ok, output, ignore=["ray.workflow", "ray.tune", "ray.serve"])
assert len(ok) >= 400, len(ok)
# TODO(ekl) enable it for all modules.
# verify(ray.serve, set(), ok, output)
# verify(ray.tune, set(), ok, output)
# verify(ray, set(), ok, output)
# verify(ray.workflow, set(), ok, output)
print("Num ok", len(ok))
print("Num bad", len(output))

View file

@ -8,12 +8,12 @@ import os
import sys
import ray
import ray._private.ray_constants as ray_constants
import ray._private.services
import ray._private.utils
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
import ray.ray_constants as ray_constants
from ray._private.gcs_pubsub import GcsAioPublisher, GcsPublisher
from ray._private.gcs_utils import GcsAioClient, GcsClient
from ray._private.ray_logging import setup_component_logger

View file

@ -1,4 +1,4 @@
from ray.ray_constants import env_integer
from ray._private.ray_constants import env_integer
DASHBOARD_LOG_FILENAME = "dashboard.log"
DASHBOARD_AGENT_PORT_PREFIX = "DASHBOARD_AGENT_PORT_PREFIX:"

View file

@ -5,12 +5,12 @@ import logging.handlers
import platform
import traceback
import ray._private.ray_constants as ray_constants
import ray._private.services
import ray._private.utils
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.head as dashboard_head
import ray.dashboard.utils as dashboard_utils
import ray.ray_constants as ray_constants
import ray._private.services
import ray._private.utils
from ray._private.gcs_pubsub import GcsPublisher
from ray._private.ray_logging import setup_component_logger

View file

@ -1,28 +1,26 @@
import os
import asyncio
import logging
import os
import threading
from concurrent.futures import Future
from queue import Queue
import ray._private.services
import ray._private.utils
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
from ray._private import ray_constants
from ray._private.gcs_pubsub import GcsAioErrorSubscriber, GcsAioLogSubscriber
from ray._private.gcs_utils import GcsClient, check_health
from ray.dashboard.datacenter import DataOrganizer
from ray.dashboard.utils import async_loop_forever
try:
from grpc import aio as aiogrpc
except ImportError:
from grpc.experimental import aio as aiogrpc
import ray.experimental.internal_kv as internal_kv
import ray._private.utils
from ray._private.gcs_utils import GcsClient, check_health
import ray._private.services
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.utils as dashboard_utils
from ray import ray_constants
from ray._private.gcs_pubsub import (
GcsAioErrorSubscriber,
GcsAioLogSubscriber,
)
from ray.dashboard.datacenter import DataOrganizer
from ray.dashboard.utils import async_loop_forever
logger = logging.getLogger(__name__)

View file

@ -1,14 +1,12 @@
import base64
import logging
from collections import defaultdict
from enum import Enum
from typing import List
import ray
from ray._raylet import TaskID, ActorID, JobID
from ray.internal.internal_api import node_stats
import logging
from ray._private.internal_api import node_stats
from ray._raylet import ActorID, JobID, TaskID
logger = logging.getLogger(__name__)
@ -378,11 +376,11 @@ def memory_summary(
unit="B",
num_entries=None,
) -> str:
from ray.dashboard.modules.node.node_head import node_stats_to_dict
# Get terminal size
import shutil
from ray.dashboard.modules.node.node_head import node_stats_to_dict
size = shutil.get_terminal_size((80, 20)).columns
line_wrap_threshold = 137

View file

@ -1,28 +1,30 @@
import asyncio
import logging
import aiohttp.web
import ray._private.ray_constants as ray_constants
import ray._private.utils
from ray.dashboard.modules.actor import actor_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
from ray._private.gcs_pubsub import GcsAioActorSubscriber
from ray.core.generated import (
core_worker_pb2,
core_worker_pb2_grpc,
gcs_service_pb2,
gcs_service_pb2_grpc,
node_manager_pb2_grpc,
)
from ray.dashboard.datacenter import DataOrganizer, DataSource
from ray.dashboard.modules.actor import actor_consts, actor_utils
from ray.dashboard.modules.actor.actor_utils import actor_classname_from_func_descriptor
from ray.dashboard.optional_utils import rest_response
try:
from grpc import aio as aiogrpc
except ImportError:
from grpc.experimental import aio as aiogrpc
from ray._private.gcs_pubsub import GcsAioActorSubscriber
import ray.ray_constants as ray_constants
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
from ray.dashboard.optional_utils import rest_response
from ray.dashboard.modules.actor import actor_consts
from ray.dashboard.modules.actor.actor_utils import actor_classname_from_func_descriptor
from ray.core.generated import node_manager_pb2_grpc
from ray.core.generated import gcs_service_pb2
from ray.core.generated import gcs_service_pb2_grpc
from ray.core.generated import core_worker_pb2
from ray.core.generated import core_worker_pb2_grpc
from ray.dashboard.datacenter import DataSource, DataOrganizer
logger = logging.getLogger(__name__)
routes = dashboard_optional_utils.ClassMethodRouteTable

View file

@ -1,19 +1,18 @@
import logging
import os
import sys
import logging
import requests
import time
import traceback
import ray
import pytest
import ray.dashboard.utils as dashboard_utils
import requests
import ray
import ray._private.gcs_pubsub as gcs_pubsub
from ray.dashboard.tests.conftest import * # noqa
import ray.dashboard.utils as dashboard_utils
from ray._private.test_utils import format_web_url, wait_until_server_available
from ray.dashboard.modules.actor import actor_consts
from ray._private.test_utils import (
format_web_url,
wait_until_server_available,
)
from ray.dashboard.tests.conftest import * # noqa
logger = logging.getLogger(__name__)
@ -152,7 +151,7 @@ def test_kill_actor(ray_start_with_dashboard):
pass
def f(self):
ray.worker.show_in_dashboard("test")
ray._private.worker.show_in_dashboard("test")
return os.getpid()
a = Actor.remote()

View file

@ -1,18 +1,17 @@
import os
import asyncio
import logging
import os
from typing import Union
import ray.experimental.internal_kv as internal_kv
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
import ray._private.utils as utils
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.consts as dashboard_consts
from ray.dashboard.utils import async_loop_forever, create_task
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
from ray.core.generated import event_pb2, event_pb2_grpc
from ray.dashboard.modules.event import event_consts
from ray.dashboard.modules.event.event_utils import monitor_events
from ray.core.generated import event_pb2
from ray.core.generated import event_pb2_grpc
from ray.dashboard.utils import async_loop_forever, create_task
logger = logging.getLogger(__name__)

View file

@ -1,4 +1,4 @@
from ray.ray_constants import env_integer
from ray._private.ray_constants import env_integer
from ray.core.generated import event_pb2
LOG_ERROR_EVENT_STRING_LENGTH_LIMIT = 1000

View file

@ -1,18 +1,18 @@
import asyncio
import os
import pprint
from subprocess import list2cmdline
import time
from subprocess import list2cmdline
from typing import Optional, Tuple
import click
import ray.ray_constants as ray_constants
from ray.autoscaler._private.cli_logger import add_click_logging_options, cli_logger, cf
from ray.job_submission import JobStatus, JobSubmissionClient
from ray.internal.storage import _load_class
from ray.util.annotations import PublicAPI
import ray._private.ray_constants as ray_constants
from ray._private.storage import _load_class
from ray.autoscaler._private.cli_logger import add_click_logging_options, cf, cli_logger
from ray.dashboard.modules.dashboard_sdk import parse_runtime_env_args
from ray.job_submission import JobStatus, JobSubmissionClient
from ray.util.annotations import PublicAPI
def _get_sdk_client(

View file

@ -1,18 +1,18 @@
import pickle
import time
from dataclasses import dataclass, replace
from enum import Enum
import time
from typing import Any, Dict, Optional, Tuple
import pickle
from pathlib import Path
from typing import Any, Dict, Optional, Tuple
from ray import ray_constants
from ray._private import ray_constants
from ray._private.runtime_env.packaging import parse_uri
from ray.experimental.internal_kv import (
_internal_kv_initialized,
_internal_kv_get,
_internal_kv_initialized,
_internal_kv_list,
_internal_kv_put,
)
from ray._private.runtime_env.packaging import parse_uri
# NOTE(edoakes): these constants should be considered a public API because
# they're exposed in the snapshot API.

View file

@ -1,30 +1,30 @@
import asyncio
from asyncio.tasks import FIRST_COMPLETED
import copy
import os
import json
import logging
import os
import random
import string
import subprocess
import time
import traceback
import random
import subprocess
import string
from asyncio.tasks import FIRST_COMPLETED
from collections import deque
from typing import Any, Dict, Iterator, Tuple, Optional
from typing import Any, Dict, Iterator, Optional, Tuple
import ray
from ray.exceptions import RuntimeEnvSetupError
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
from ray._private.runtime_env.constants import RAY_JOB_CONFIG_JSON_ENV_VAR
from ray.actor import ActorHandle
from ray.job_submission import JobStatus
from ray.dashboard.modules.job.common import (
JobInfo,
JobInfoStorageClient,
JOB_ID_METADATA_KEY,
JOB_NAME_METADATA_KEY,
JobInfo,
JobInfoStorageClient,
)
from ray.dashboard.modules.job.utils import file_tail_iterator
from ray._private.runtime_env.constants import RAY_JOB_CONFIG_JSON_ENV_VAR
from ray.exceptions import RuntimeEnvSetupError
from ray.job_submission import JobStatus
logger = logging.getLogger(__name__)
@ -86,7 +86,7 @@ class JobLogStorageClient:
/tmp/ray/session_date/logs/job-driver-{job_id}.log
"""
return os.path.join(
ray.worker._global_node.get_logs_dir_path(),
ray._private.worker._global_node.get_logs_dir_path(),
self.JOB_LOGS_PATH.format(job_id=job_id),
)

View file

@ -1,7 +1,8 @@
import os
import ray
cuda_env = ray.ray_constants.NOSET_CUDA_VISIBLE_DEVICES_ENV_VAR
cuda_env = ray._private.ray_constants.NOSET_CUDA_VISIBLE_DEVICES_ENV_VAR
assert os.environ[cuda_env] == "1"

View file

@ -1,31 +1,28 @@
import json
import logging
from pathlib import Path
import os
import shutil
import sys
import json
import yaml
import tempfile
from pathlib import Path
from typing import Optional
import pytest
from unittest.mock import patch
import pytest
import yaml
import ray
from ray.job_submission import JobSubmissionClient, JobStatus
from ray.dashboard.modules.job.common import CURRENT_VERSION, JobInfo
from ray.dashboard.modules.dashboard_sdk import (
ClusterInfo,
parse_cluster_info,
)
from ray.dashboard.tests.conftest import * # noqa
from ray.tests.conftest import _ray_start
from ray._private.test_utils import (
chdir,
format_web_url,
wait_for_condition,
wait_until_server_available,
)
from ray.dashboard.modules.dashboard_sdk import ClusterInfo, parse_cluster_info
from ray.dashboard.modules.job.common import CURRENT_VERSION, JobInfo
from ray.dashboard.tests.conftest import * # noqa
from ray.job_submission import JobStatus, JobSubmissionClient
from ray.tests.conftest import _ray_start
logger = logging.getLogger(__name__)
@ -391,7 +388,7 @@ def test_job_metadata(job_sdk_client):
'python -c"'
"import ray;"
"ray.init();"
"job_config=ray.worker.global_worker.core_worker.get_job_config();"
"job_config=ray._private.worker.global_worker.core_worker.get_job_config();"
"print(dict(sorted(job_config.metadata.items())))"
'"'
)

View file

@ -1,24 +1,20 @@
import asyncio
import os
import psutil
import tempfile
import signal
import sys
import tempfile
import urllib.request
from uuid import uuid4
import signal
import psutil
import pytest
import ray
from ray.job_submission import JobStatus
from ray.dashboard.modules.job.common import (
JOB_ID_METADATA_KEY,
JOB_NAME_METADATA_KEY,
)
from ray.dashboard.modules.job.job_manager import generate_job_id, JobManager
from ray._private.ray_constants import RAY_ADDRESS_ENVIRONMENT_VARIABLE
from ray._private.test_utils import SignalActor, async_wait_for_condition
from ray.ray_constants import RAY_ADDRESS_ENVIRONMENT_VARIABLE
from ray.dashboard.modules.job.common import JOB_ID_METADATA_KEY, JOB_NAME_METADATA_KEY
from ray.dashboard.modules.job.job_manager import JobManager, generate_job_id
from ray.job_submission import JobStatus
from ray.tests.conftest import call_ray_start # noqa: F401
TEST_NAMESPACE = "jobs_test_namespace"
@ -395,7 +391,7 @@ class TestRuntimeEnv:
'python -c"'
"import ray;"
"ray.init();"
"job_config=ray.worker.global_worker.core_worker.get_job_config();"
"job_config=ray._private.worker.global_worker.core_worker.get_job_config();"
"print(dict(sorted(job_config.metadata.items())))"
'"'
)
@ -716,8 +712,8 @@ async def test_bootstrap_address(job_manager, monkeypatch):
cluster might be started with http://ip:{dashboard_port} from previous
runs.
"""
ip = ray.ray_constants.DEFAULT_DASHBOARD_IP
port = ray.ray_constants.DEFAULT_DASHBOARD_PORT
ip = ray._private.ray_constants.DEFAULT_DASHBOARD_IP
port = ray._private.ray_constants.DEFAULT_DASHBOARD_PORT
monkeypatch.setenv("RAY_ADDRESS", f"http://{ip}:{port}")
print_ray_address_cmd = (

View file

@ -1,17 +1,15 @@
import sys
import html.parser
import logging
import requests
import sys
import time
import traceback
import html.parser
import urllib.parse
import pytest
import ray
from ray._private.test_utils import (
format_web_url,
wait_until_server_available,
)
import pytest
import requests
import ray
from ray._private.test_utils import format_web_url, wait_until_server_available
from ray.dashboard.tests.conftest import * # noqa
logger = logging.getLogger(__name__)
@ -44,7 +42,7 @@ def test_log(disable_aiohttp_cache, ray_start_with_dashboard):
test_file = "test.log"
with open(
f"{ray.worker.global_worker.node.get_logs_dir_path()}/{test_file}", "w"
f"{ray._private.worker.global_worker.node.get_logs_dir_path()}/{test_file}", "w"
) as f:
f.write(test_log_text)
assert wait_until_server_available(ray_start_with_dashboard["webui_url"]) is True
@ -128,7 +126,7 @@ def test_log_proxy(ray_start_with_dashboard):
test_log_text = "test_log_text"
test_file = "test.log"
with open(
f"{ray.worker.global_worker.node.get_logs_dir_path()}/{test_file}", "w"
f"{ray._private.worker.global_worker.node.get_logs_dir_path()}/{test_file}", "w"
) as f:
f.write(test_log_text)
while True:

View file

@ -1,26 +1,29 @@
import asyncio
import re
import logging
import json
import logging
import re
import aiohttp.web
import ray._private.utils
from ray import ray_constants
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
from ray._private import ray_constants
from ray.core.generated import (
gcs_service_pb2,
gcs_service_pb2_grpc,
node_manager_pb2,
node_manager_pb2_grpc,
)
from ray.dashboard.datacenter import DataOrganizer, DataSource
from ray.dashboard.memory_utils import GroupByType, SortingType
from ray.dashboard.modules.node import node_consts
from ray.dashboard.modules.node.node_consts import (
MAX_LOGS_TO_CACHE,
LOG_PRUNE_THREASHOLD,
MAX_LOGS_TO_CACHE,
)
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.consts as dashboard_consts
from ray.dashboard.utils import async_loop_forever
from ray.dashboard.memory_utils import GroupByType, SortingType
from ray.core.generated import node_manager_pb2
from ray.core.generated import node_manager_pb2_grpc
from ray.core.generated import gcs_service_pb2
from ray.core.generated import gcs_service_pb2_grpc
from ray.dashboard.datacenter import DataSource, DataOrganizer
logger = logging.getLogger(__name__)
routes = dashboard_optional_utils.ClassMethodRouteTable

View file

@ -9,20 +9,19 @@ import sys
import traceback
import warnings
import psutil
import ray
import ray.dashboard.modules.reporter.reporter_consts as reporter_consts
from ray.dashboard import k8s_utils
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
import ray._private.services
import ray._private.utils
from ray.core.generated import reporter_pb2
from ray.core.generated import reporter_pb2_grpc
from ray.ray_constants import DEBUG_AUTOSCALING_STATUS
from ray._private.metrics_agent import MetricsAgent, Gauge, Record
import ray.dashboard.modules.reporter.reporter_consts as reporter_consts
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
from ray._private.metrics_agent import Gauge, MetricsAgent, Record
from ray._private.ray_constants import DEBUG_AUTOSCALING_STATUS
from ray.core.generated import reporter_pb2, reporter_pb2_grpc
from ray.dashboard import k8s_utils
from ray.util.debug import log_once
import psutil
logger = logging.getLogger(__name__)

View file

@ -1,4 +1,4 @@
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
REPORTER_PREFIX = "RAY_REPORTER:"
# The reporter will report its statistics this often (milliseconds).

View file

@ -1,25 +1,25 @@
import json
import logging
import yaml
import os
import aiohttp.web
import yaml
import ray
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.experimental.internal_kv as internal_kv
import ray._private.services
import ray._private.utils
from ray.ray_constants import (
GLOBAL_GRPC_OPTIONS,
DEBUG_AUTOSCALING_STATUS,
DEBUG_AUTOSCALING_STATUS_LEGACY,
DEBUG_AUTOSCALING_ERROR,
)
from ray.core.generated import reporter_pb2
from ray.core.generated import reporter_pb2_grpc
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
import ray.experimental.internal_kv as internal_kv
from ray._private.gcs_pubsub import GcsAioResourceUsageSubscriber
from ray._private.metrics_agent import PrometheusServiceDiscoveryWriter
from ray._private.ray_constants import (
DEBUG_AUTOSCALING_ERROR,
DEBUG_AUTOSCALING_STATUS,
DEBUG_AUTOSCALING_STATUS_LEGACY,
GLOBAL_GRPC_OPTIONS,
)
from ray.core.generated import reporter_pb2, reporter_pb2_grpc
from ray.dashboard.datacenter import DataSource
logger = logging.getLogger(__name__)

View file

@ -1,23 +1,24 @@
import logging
import os
import sys
import logging
from mock import patch
import requests
import time
import pytest
import requests
import ray
from ray import ray_constants
from mock import patch
from ray._private import ray_constants
from ray._private.test_utils import (
RayTestTimeoutException,
fetch_prometheus,
format_web_url,
wait_for_condition,
wait_until_server_available,
)
from ray.dashboard.modules.reporter.reporter_agent import ReporterAgent
from ray.dashboard.tests.conftest import * # noqa
from ray.dashboard.utils import Bunch
from ray.dashboard.modules.reporter.reporter_agent import ReporterAgent
from ray._private.test_utils import (
format_web_url,
RayTestTimeoutException,
wait_until_server_available,
wait_for_condition,
fetch_prometheus,
)
try:
import prometheus_client
@ -148,7 +149,7 @@ def test_prometheus_physical_stats_record(enable_test_module, shutdown_only):
def test_case_ip_correct():
components_dict, metric_names, metric_samples = fetch_prometheus(prom_addresses)
raylet_proc = ray.worker._global_node.all_processes[
raylet_proc = ray._private.worker._global_node.all_processes[
ray_constants.PROCESS_TYPE_RAYLET
][0]
raylet_pid = None

View file

@ -1,4 +1,4 @@
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
RUNTIME_ENV_RETRY_TIMES = ray_constants.env_integer("RUNTIME_ENV_RETRY_TIMES", 3)

View file

@ -1,29 +1,24 @@
import asyncio
import concurrent.futures
from typing import Any, Dict, List, Optional
import hashlib
import json
from typing import Any, Dict, List, Optional
import aiohttp.web
import ray
from ray import ray_constants
from ray.core.generated import gcs_service_pb2
from ray.core.generated import gcs_pb2
from ray.core.generated import gcs_service_pb2_grpc
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
from ray._private import ray_constants
from ray.core.generated import gcs_pb2, gcs_service_pb2, gcs_service_pb2_grpc
from ray.dashboard.modules.job.common import JOB_ID_METADATA_KEY, JobInfoStorageClient
from ray.experimental.internal_kv import (
_internal_kv_initialized,
_internal_kv_get,
_internal_kv_initialized,
_internal_kv_list,
)
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
from ray.runtime_env import RuntimeEnv
from ray.job_submission import JobInfo
from ray.dashboard.modules.job.common import (
JobInfoStorageClient,
JOB_ID_METADATA_KEY,
)
import json
import aiohttp.web
from ray.runtime_env import RuntimeEnv
routes = dashboard_optional_utils.ClassMethodRouteTable
@ -195,8 +190,8 @@ class APIHead(dashboard_utils.DashboardHeadModule):
# Conditionally import serve to prevent ModuleNotFoundError from serve
# dependencies when only ray[default] is installed (#17712)
try:
from ray.serve.controller import SNAPSHOT_KEY as SERVE_SNAPSHOT_KEY
from ray.serve.constants import SERVE_CONTROLLER_NAME
from ray.serve.controller import SNAPSHOT_KEY as SERVE_SNAPSHOT_KEY
except Exception:
return {}

View file

@ -1,15 +1,14 @@
import logging
import os
import sys
import logging
import requests
import time
import ray
import pytest
import requests
import ray
from ray._private.test_utils import format_web_url, wait_until_server_available
from ray.dashboard.tests.conftest import * # noqa
from ray._private.test_utils import (
format_web_url,
wait_until_server_available,
)
logger = logging.getLogger(__name__)
@ -59,7 +58,7 @@ def test_kill_actor_gcs(ray_start_with_dashboard):
@ray.remote
class Actor:
def f(self):
ray.worker.show_in_dashboard("test")
ray._private.worker.show_in_dashboard("test")
return os.getpid()
def loop(self):

View file

@ -2,11 +2,11 @@ import logging
import aiohttp.web
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.modules.test.test_utils as test_utils
import ray.dashboard.modules.test.test_consts as test_consts
from ray.ray_constants import env_bool
import ray.dashboard.modules.test.test_utils as test_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
from ray._private.ray_constants import env_bool
logger = logging.getLogger(__name__)
routes = dashboard_optional_utils.ClassMethodRouteTable

View file

@ -1,14 +1,14 @@
import time
import logging
import time
import aiohttp.web
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.modules.test.test_utils as test_utils
import ray.dashboard.modules.test.test_consts as test_consts
import ray.dashboard.modules.test.test_utils as test_utils
import ray.dashboard.optional_utils as dashboard_optional_utils
import ray.dashboard.utils as dashboard_utils
from ray._private.ray_constants import env_bool
from ray.dashboard.datacenter import DataSource
from ray.ray_constants import env_bool
logger = logging.getLogger(__name__)
routes = dashboard_optional_utils.ClassMethodRouteTable

View file

@ -14,16 +14,17 @@ import traceback
from collections import namedtuple
from typing import Any, Callable
from aiohttp.web import Response
import ray
import ray.dashboard.consts as dashboard_consts
from aiohttp.web import Response
from ray._private.ray_constants import env_bool
# All third-party dependencies that are not included in the minimal Ray
# installation must be included in this file. This allows us to determine if
# the agent has the necessary dependencies to be started.
from ray.dashboard.optional_deps import PathLike, RouteDef, aiohttp, hdrs
from ray.dashboard.utils import CustomEncoder, to_google_style
from ray.ray_constants import env_bool
try:
create_task = asyncio.create_task

View file

@ -1,43 +1,47 @@
import os
import sys
import copy
import json
import time
import logging
import asyncio
import ipaddress
import subprocess
import collections
import copy
import ipaddress
import json
import logging
import os
import subprocess
import sys
import time
import numpy as np
import ray
import psutil
import pytest
import requests
from ray import ray_constants
import ray
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.modules
import ray.dashboard.utils as dashboard_utils
from ray._private import ray_constants
from ray._private.ray_constants import (
DEBUG_AUTOSCALING_ERROR,
DEBUG_AUTOSCALING_STATUS_LEGACY,
)
from ray._private.test_utils import (
format_web_url,
get_error_message,
init_error_pubsub,
run_string_as_driver,
wait_for_condition,
wait_until_server_available,
run_string_as_driver,
wait_until_succeeded_without_exception,
init_error_pubsub,
get_error_message,
)
from ray.ray_constants import DEBUG_AUTOSCALING_STATUS_LEGACY, DEBUG_AUTOSCALING_ERROR
from ray.dashboard import dashboard
import ray.dashboard.consts as dashboard_consts
import ray.dashboard.utils as dashboard_utils
import ray.dashboard.modules
from ray.dashboard.modules.dashboard_sdk import DEFAULT_DASHBOARD_ADDRESS
from ray.experimental.state.exception import ServerUnavailable
from ray.experimental.state.common import ListApiOptions, StateResource
from ray.experimental.state.api import StateApiClient
from ray.experimental.state.common import ListApiOptions, StateResource
from ray.experimental.state.exception import ServerUnavailable
import psutil
try:
import aiohttp.web
import ray.dashboard.optional_utils as dashboard_optional_utils
routes = dashboard_optional_utils.ClassMethodRouteTable
@ -106,7 +110,7 @@ def test_basic(ray_start_with_dashboard):
gcs_client = make_gcs_client(address_info)
ray.experimental.internal_kv._initialize_internal_kv(gcs_client)
all_processes = ray.worker._global_node.all_processes
all_processes = ray._private.worker._global_node.all_processes
assert ray_constants.PROCESS_TYPE_DASHBOARD in all_processes
assert ray_constants.PROCESS_TYPE_REPORTER not in all_processes
dashboard_proc_info = all_processes[ray_constants.PROCESS_TYPE_DASHBOARD][0]
@ -151,7 +155,7 @@ def test_raylet_and_agent_share_fate(shutdown_only):
ray.init(include_dashboard=True)
p = init_error_pubsub()
node = ray.worker._global_node
node = ray._private.worker._global_node
all_processes = node.all_processes
raylet_proc_info = all_processes[ray_constants.PROCESS_TYPE_RAYLET][0]
raylet_proc = psutil.Process(raylet_proc_info.process.pid)
@ -174,7 +178,7 @@ def test_raylet_and_agent_share_fate(shutdown_only):
ray.shutdown()
ray.init(include_dashboard=True)
all_processes = ray.worker._global_node.all_processes
all_processes = ray._private.worker._global_node.all_processes
raylet_proc_info = all_processes[ray_constants.PROCESS_TYPE_RAYLET][0]
raylet_proc = psutil.Process(raylet_proc_info.process.pid)
wait_for_condition(lambda: search_agent(raylet_proc.children()))
@ -195,7 +199,7 @@ def test_agent_report_unexpected_raylet_death(shutdown_only):
ray.init(include_dashboard=True)
p = init_error_pubsub()
node = ray.worker._global_node
node = ray._private.worker._global_node
all_processes = node.all_processes
raylet_proc_info = all_processes[ray_constants.PROCESS_TYPE_RAYLET][0]
raylet_proc = psutil.Process(raylet_proc_info.process.pid)
@ -229,7 +233,7 @@ def test_agent_report_unexpected_raylet_death_large_file(shutdown_only):
ray.init(include_dashboard=True)
p = init_error_pubsub()
node = ray.worker._global_node
node = ray._private.worker._global_node
all_processes = node.all_processes
raylet_proc_info = all_processes[ray_constants.PROCESS_TYPE_RAYLET][0]
raylet_proc = psutil.Process(raylet_proc_info.process.pid)
@ -788,7 +792,7 @@ def test_dashboard_port_conflict(ray_start_with_dashboard):
def test_gcs_check_alive(fast_gcs_failure_detection, ray_start_with_dashboard):
assert wait_until_server_available(ray_start_with_dashboard["webui_url"]) is True
all_processes = ray.worker._global_node.all_processes
all_processes = ray._private.worker._global_node.all_processes
dashboard_info = all_processes[ray_constants.PROCESS_TYPE_DASHBOARD][0]
dashboard_proc = psutil.Process(dashboard_info.process.pid)
gcs_server_info = all_processes[ray_constants.PROCESS_TYPE_GCS_SERVER][0]

View file

@ -27,11 +27,11 @@ with InputNode() as user_input:
dag = combine.bind(m1_output, m2_output, kwargs_output=user_input[2])
# Partial DAG visualization
graph = ray.dag.vis_utils.dag_to_dot(m1_output)
graph = ray.dag.vis_utils._dag_to_dot(m1_output)
to_string = graph.to_string()
print(to_string)
# Entire DAG visualization
graph = ray.dag.vis_utils.dag_to_dot(dag)
graph = ray.dag.vis_utils._dag_to_dot(dag)
to_string = graph.to_string()
print(to_string)

View file

@ -1,3 +1,4 @@
# isort: skip_file
import logging
import os
@ -132,13 +133,13 @@ from ray._raylet import ( # noqa: E402
_config = _Config()
from ray.state import ( # noqa: E402
from ray._private.state import ( # noqa: E402
nodes,
timeline,
cluster_resources,
available_resources,
)
from ray.worker import ( # noqa: E402,F401
from ray._private.worker import ( # noqa: E402,F401
LOCAL_MODE,
SCRIPT_MODE,
WORKER_MODE,
@ -156,7 +157,6 @@ from ray.worker import ( # noqa: E402,F401
shutdown,
wait,
)
import ray.internal # noqa: E402
# We import ray.actor because some code is run in actor.py which initializes
# some functions in the worker.
@ -168,6 +168,7 @@ from ray.cross_language import java_function, java_actor_class # noqa: E402
from ray.runtime_context import get_runtime_context # noqa: E402
from ray import autoscaler # noqa:E402
from ray import data # noqa: E402,F401
from ray import internal # noqa: E402,F401
from ray import util # noqa: E402
from ray import _private # noqa: E402,F401
from ray import workflow # noqa: E402,F401
@ -175,6 +176,29 @@ from ray import workflow # noqa: E402,F401
# We import ClientBuilder so that modules can inherit from `ray.ClientBuilder`.
from ray.client_builder import client, ClientBuilder # noqa: E402
class _DeprecationWrapper(object):
def __init__(self, name, real_worker):
self._name = name
self._real_worker = real_worker
self._warned = set()
def __getattr__(self, attr):
value = getattr(self._real_worker, attr)
if attr not in self._warned:
self._warned.add(attr)
logger.warning(
f"DeprecationWarning: `ray.{self._name}.{attr}` is a private "
"attribute and access will be removed in a future Ray version."
)
return value
# TODO(ekl) remove this entirely after 3rd party libraries are all migrated.
worker = _DeprecationWrapper("worker", ray._private.worker)
ray_constants = _DeprecationWrapper("ray_constants", ray._private.ray_constants)
serialization = _DeprecationWrapper("serialization", ray._private.serialization)
__all__ = [
"__version__",
"_config",

View file

@ -1,7 +1,7 @@
import os
import threading
from contextlib import contextmanager
from functools import partial, wraps
import threading
# Attr set on func defs to mark they have been converted to client mode.
RAY_CLIENT_MODE_ATTR = "__ray_client_mode_key__"
@ -93,10 +93,10 @@ def client_mode_hook(func: callable = None, *, auto_init: bool):
if func is None:
return partial(client_mode_hook, auto_init=auto_init)
from ray.util.client import ray
@wraps(func)
def wrapper(*args, **kwargs):
from ray.util.client import ray
if client_mode_should_convert(auto_init=auto_init):
# Legacy code
# we only convert init function if RAY_CLIENT_MODE=1
@ -141,10 +141,11 @@ def client_mode_wrap(func):
side, this function is wrapped in a task to facilitate interaction with
the GCS.
"""
from ray.util.client import ray
@wraps(func)
def wrapper(*args, **kwargs):
from ray.util.client import ray
# Directly pass this through since `client_mode_wrap` is for
# Placement Group APIs
if client_mode_should_convert(auto_init=True):

View file

@ -1,15 +1,15 @@
import abc
import logging
import os
import shutil
import random
import shutil
import time
import urllib
from collections import namedtuple
from typing import List, IO, Tuple, Optional
from typing import IO, List, Optional, Tuple
import ray
from ray.ray_constants import DEFAULT_OBJECT_PREFIX
from ray._private.ray_constants import DEFAULT_OBJECT_PREFIX
from ray._raylet import ObjectRef
ParsedURL = namedtuple("ParsedURL", "base_url, offset, size")
@ -87,7 +87,7 @@ class ExternalStorage(metaclass=abc.ABCMeta):
HEADER_LENGTH = 24
def _get_objects_from_store(self, object_refs):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
# Since the object should always exist in the plasma store before
# spilling, it can directly get the object from the local plasma
# store.
@ -98,7 +98,7 @@ class ExternalStorage(metaclass=abc.ABCMeta):
def _put_object_to_store(
self, metadata, data_size, file_like, object_ref, owner_address
):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.core_worker.put_file_like_object(
metadata, data_size, file_like, object_ref, owner_address
)
@ -370,7 +370,7 @@ class ExternalStorageRayStorageImpl(ExternalStorage):
# Override the storage config for unit tests.
_force_storage_for_testing: Optional[str] = None,
):
from ray.internal import storage
from ray._private import storage
if _force_storage_for_testing:
storage._reset()

View file

@ -1,36 +1,33 @@
import dis
import hashlib
import os
import importlib
import inspect
import json
import logging
import os
import sys
import time
from typing import Optional
import threading
import time
import traceback
from collections import (
namedtuple,
defaultdict,
)
from collections import defaultdict, namedtuple
from typing import Optional
import ray
import ray._private.profiling as profiling
from ray import ray_constants
from ray import cloudpickle as pickle
from ray._raylet import PythonFunctionDescriptor, JobID
from ray._private import ray_constants
from ray._private.inspect_util import (
is_class_method,
is_function_or_method,
is_static_method,
)
from ray._private.ray_constants import KV_NAMESPACE_FUNCTION_TABLE
from ray._private.utils import (
check_oversized_function,
ensure_str,
format_error_message,
)
from ray.ray_constants import KV_NAMESPACE_FUNCTION_TABLE
from ray.util.inspect import (
is_function_or_method,
is_class_method,
is_static_method,
)
from ray._raylet import JobID, PythonFunctionDescriptor
FunctionExecutionInfo = namedtuple(
"FunctionExecutionInfo", ["function", "function_name", "max_calls"]

View file

@ -1,37 +1,36 @@
import enum
import logging
from typing import List, Optional
from functools import wraps
import time
from functools import wraps
from typing import List, Optional
import grpc
import ray
from ray import ray_constants
from ray._private import ray_constants
from ray.core.generated import gcs_service_pb2, gcs_service_pb2_grpc
from ray.core.generated.common_pb2 import ErrorType
from ray.core.generated import gcs_service_pb2_grpc
from ray.core.generated import gcs_service_pb2
from ray.core.generated.gcs_pb2 import (
ActorTableData,
GcsNodeInfo,
AvailableResources,
JobTableData,
JobConfig,
ErrorTableData,
GcsEntry,
ResourceUsageBatchData,
ResourcesData,
GcsNodeInfo,
JobConfig,
JobTableData,
ObjectTableData,
PlacementGroupTableData,
ProfileTableData,
TablePrefix,
TablePubsub,
PubSubMessage,
ResourceDemand,
ResourceLoad,
ResourceMap,
ResourcesData,
ResourceTableData,
PubSubMessage,
ResourceUsageBatchData,
TablePrefix,
TablePubsub,
WorkerTableData,
PlacementGroupTableData,
)
logger = logging.getLogger(__name__)

View file

@ -1,14 +1,14 @@
from collections import defaultdict
import logging
import threading
import traceback
from collections import defaultdict
import grpc
import ray
from ray import ray_constants
from ray import cloudpickle as pickle
import ray._private.profiling as profiling
import logging
from ray import cloudpickle as pickle
from ray._private import ray_constants
logger = logging.getLogger(__name__)

View file

@ -1,10 +1,10 @@
import ray
import ray._private.services as services
import ray.worker
import ray._private.profiling as profiling
import ray._private.services as services
import ray._private.utils as utils
from ray import ray_constants
from ray.state import GlobalState
import ray._private.worker
from ray._private import ray_constants
from ray._private.state import GlobalState
from ray._raylet import GcsClientOptions
__all__ = ["free", "global_gc"]
@ -14,7 +14,7 @@ MAX_MESSAGE_LENGTH = ray._config.max_grpc_message_size()
def global_gc():
"""Trigger gc.collect() on all workers in the cluster."""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.core_worker.global_gc()
@ -45,8 +45,7 @@ def memory_summary(
def get_store_stats(state, node_manager_address=None, node_manager_port=None):
"""Returns a formatted string describing memory usage in the cluster."""
from ray.core.generated import node_manager_pb2
from ray.core.generated import node_manager_pb2_grpc
from ray.core.generated import node_manager_pb2, node_manager_pb2_grpc
# We can ask any Raylet for the global memory info, that Raylet internally
# asks all nodes in the cluster for memory stats.
@ -85,8 +84,7 @@ def node_stats(
):
"""Returns NodeStats object describing memory usage in the cluster."""
from ray.core.generated import node_manager_pb2
from ray.core.generated import node_manager_pb2_grpc
from ray.core.generated import node_manager_pb2, node_manager_pb2_grpc
# We can ask any Raylet for the global memory info.
assert node_manager_address is not None and node_manager_port is not None
@ -192,7 +190,7 @@ def free(object_refs: list, local_only: bool = False):
local_only: Whether only deleting the list of objects in local
object store or all object stores.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
if isinstance(object_refs, ray.ObjectRef):
object_refs = [object_refs]

View file

@ -9,12 +9,10 @@ import re
import shutil
import time
import traceback
from typing import Set, List
from typing import Callable, List, Set
from typing import Callable
import ray.ray_constants as ray_constants
import ray._private.gcs_pubsub as gcs_pubsub
import ray._private.ray_constants as ray_constants
import ray._private.services as services
import ray._private.utils
from ray._private.gcs_pubsub import GcsPublisher

View file

@ -7,25 +7,24 @@ import traceback
from collections import namedtuple
from typing import List
from opencensus.metrics.export.value import ValueDouble
from opencensus.stats import aggregation
from opencensus.stats import measure as measure_module
from opencensus.stats import stats as stats_module
from opencensus.stats.view import View
from opencensus.stats.view_data import ViewData
from opencensus.stats.aggregation_data import (
CountAggregationData,
DistributionAggregationData,
LastValueAggregationData,
)
from opencensus.metrics.export.value import ValueDouble
from opencensus.stats.view import View
from opencensus.stats.view_data import ViewData
from opencensus.tags import tag_key as tag_key_module
from opencensus.tags import tag_map as tag_map_module
from opencensus.tags import tag_value as tag_value_module
import ray
from ray._private.gcs_utils import GcsClient
import ray._private.prometheus_exporter as prometheus_exporter
from ray._private.gcs_utils import GcsClient
from ray.core.generated.metrics_pb2 import Metric
logger = logging.getLogger(__name__)
@ -211,7 +210,7 @@ class PrometheusServiceDiscoveryWriter(threading.Thread):
gcs_client_options = ray._raylet.GcsClientOptions.from_gcs_address(gcs_address)
self.gcs_address = gcs_address
ray.state.state._initialize_global_state(gcs_client_options)
ray._private.state.state._initialize_global_state(gcs_client_options)
self.temp_dir = temp_dir
self.default_service_discovery_flush_period = 5
super().__init__()
@ -247,13 +246,15 @@ class PrometheusServiceDiscoveryWriter(threading.Thread):
def get_target_file_name(self):
return os.path.join(
self.temp_dir, ray.ray_constants.PROMETHEUS_SERVICE_DISCOVERY_FILE
self.temp_dir, ray._private.ray_constants.PROMETHEUS_SERVICE_DISCOVERY_FILE
)
def get_temp_file_name(self):
return os.path.join(
self.temp_dir,
"{}_{}".format("tmp", ray.ray_constants.PROMETHEUS_SERVICE_DISCOVERY_FILE),
"{}_{}".format(
"tmp", ray._private.ray_constants.PROMETHEUS_SERVICE_DISCOVERY_FILE
),
)
def run(self):

View file

@ -14,19 +14,19 @@ import tempfile
import threading
import time
import traceback
from typing import Optional, Dict
from collections import defaultdict
from typing import Dict, Optional
from filelock import FileLock
import ray
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
import ray._private.services
import ray._private.utils
from ray.internal import storage
from ray._private import storage
from ray._private.gcs_utils import GcsClient
from ray._private.resource_spec import ResourceSpec
from ray._private.utils import try_to_create_directory, try_to_symlink, open_log
from ray._private.utils import open_log, try_to_create_directory, try_to_symlink
# Logger for this module. It should be configured at the entry point
# into the program using Ray. Ray configures it by default automatically
@ -1118,7 +1118,7 @@ class Node:
gcs_options = ray._raylet.GcsClientOptions.from_gcs_address(
self.gcs_address
)
global_state = ray.state.GlobalState()
global_state = ray._private.state.GlobalState()
global_state._initialize_global_state(gcs_options)
new_config = global_state.get_system_config()
assert self._config.items() <= new_config.items(), (
@ -1448,7 +1448,7 @@ class Node:
object_spilling_config = self._config.get("object_spilling_config", {})
if object_spilling_config:
object_spilling_config = json.loads(object_spilling_config)
from ray import external_storage
from ray._private import external_storage
storage = external_storage.setup_external_storage(
object_spilling_config, self.session_name
@ -1493,7 +1493,7 @@ class Node:
self._config["is_external_storage_type_fs"] = is_external_storage_type_fs
# Validate external storage usage.
from ray import external_storage
from ray._private import external_storage
external_storage.setup_external_storage(deserialized_config, self.session_name)
external_storage.reset_external_storage()

View file

@ -1,10 +1,10 @@
import logging
import os
from typing import Optional, List, Dict
from typing import Dict, List, Optional
import numpy as np
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
logger = logging.getLogger(__name__)
@ -19,7 +19,7 @@ class RayParams:
It will also kill these processes when Python exits.
redis_port: The port that the primary Redis shard should listen
to. If None, then it will fall back to
ray.ray_constants.DEFAULT_PORT, or a random port if the default is
ray._private.ray_constants.DEFAULT_PORT, or a random port if the default is
not available.
redis_shard_ports: A list of the ports to use for the non-primary Redis
shards. If None, then it will fall back to the ports right after

View file

@ -1,6 +1,7 @@
import ray
import os
import ray
class _NullLogSpan:
"""A log span context manager that does nothing"""
@ -49,7 +50,7 @@ def profile(event_type, extra_data=None):
"""
if not PROFILING_ENABLED:
return NULL_LOG_SPAN
worker = ray.worker.global_worker
if worker.mode == ray.worker.LOCAL_MODE:
worker = ray._private.worker.global_worker
if worker.mode == ray._private.worker.LOCAL_MODE:
return NULL_LOG_SPAN
return worker.core_worker.profile_event(event_type.encode("ascii"), extra_data)

View file

@ -3,7 +3,6 @@ import os
import sys
import threading
from logging.handlers import RotatingFileHandler
from typing import Callable
import ray
@ -192,9 +191,12 @@ def get_worker_log_file_name(worker_type, job_id=None):
worker_name = "io_worker"
# Make sure these values are set already.
assert ray.worker._global_node is not None
assert ray.worker.global_worker is not None
filename = f"{worker_name}-" f"{binary_to_hex(ray.worker.global_worker.worker_id)}-"
assert ray._private.worker._global_node is not None
assert ray._private.worker.global_worker is not None
filename = (
f"{worker_name}-"
f"{binary_to_hex(ray._private.worker.global_worker.worker_id)}-"
)
if job_id:
filename += f"{job_id}-"
filename += f"{os.getpid()}"
@ -270,12 +272,12 @@ def setup_and_get_worker_interceptor_logger(
worker_name = "io_worker"
# Make sure these values are set already.
assert ray.worker._global_node is not None
assert ray.worker.global_worker is not None
assert ray._private.worker._global_node is not None
assert ray._private.worker.global_worker is not None
filename = (
f"{ray.worker._global_node.get_session_dir_path()}/logs/"
f"{ray._private.worker._global_node.get_session_dir_path()}/logs/"
f"{worker_name}-"
f"{binary_to_hex(ray.worker.global_worker.worker_id)}-"
f"{binary_to_hex(ray._private.worker.global_worker.worker_id)}-"
f"{job_id}-{os.getpid()}.{file_extension}"
)
handler = StandardFdRedirectionRotatingFileHandler(

View file

@ -1,12 +1,13 @@
"""Manage, parse and validate options for Ray tasks, actors and actor methods."""
from typing import Dict, Any, Callable, Tuple, Union, Optional
from dataclasses import dataclass
from typing import Any, Callable, Dict, Optional, Tuple, Union
import ray._private.ray_constants as ray_constants
from ray.util.placement_group import PlacementGroup
from ray.util.scheduling_strategies import (
PlacementGroupSchedulingStrategy,
NodeAffinitySchedulingStrategy,
PlacementGroupSchedulingStrategy,
)
import ray.ray_constants as ray_constants
@dataclass

View file

@ -1,14 +1,14 @@
import importlib.util
from collections import namedtuple
import logging
import os
import re
import subprocess
import sys
from collections import namedtuple
from typing import Optional
import ray
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
try:
import GPUtil
@ -158,7 +158,8 @@ class ResourceSpec(
node_ip_address = ray.util.get_node_ip_address()
# Automatically create a node id resource on each node. This is
# queryable with ray.state.node_ids() and ray.state.current_node_id().
# queryable with ray._private.state.node_ids() and
# ray._private.state.current_node_id().
resources[NODE_ID_PREFIX + node_ip_address] = 1.0
num_cpus = self.num_cpus

View file

@ -11,6 +11,10 @@ from zipfile import ZipFile
from filelock import FileLock
from ray._private.ray_constants import (
RAY_RUNTIME_ENV_URI_PIN_EXPIRATION_S_DEFAULT,
RAY_RUNTIME_ENV_URI_PIN_EXPIRATION_S_ENV_VAR,
)
from ray._private.gcs_utils import GcsAioClient
from ray._private.thirdparty.pathspec import PathSpec
from ray.experimental.internal_kv import (
@ -18,10 +22,6 @@ from ray.experimental.internal_kv import (
_internal_kv_put,
_pin_runtime_env_uri,
)
from ray.ray_constants import (
RAY_RUNTIME_ENV_URI_PIN_EXPIRATION_S_DEFAULT,
RAY_RUNTIME_ENV_URI_PIN_EXPIRATION_S_ENV_VAR,
)
default_logger = logging.getLogger(__name__)

View file

@ -2,43 +2,43 @@ import logging
import threading
import traceback
import ray.cloudpickle as pickle
from ray import ray_constants
import ray._private.utils
import ray.cloudpickle as pickle
from ray._private import ray_constants
from ray._private.gcs_utils import ErrorType
from ray.core.generated.common_pb2 import RayErrorInfo
from ray.exceptions import (
RayError,
PlasmaObjectNotAvailable,
RayTaskError,
RayActorError,
TaskCancelledError,
WorkerCrashedError,
ObjectLostError,
ObjectFetchTimedOutError,
ReferenceCountingAssertionError,
OwnerDiedError,
ObjectReconstructionFailedError,
ObjectReconstructionFailedMaxAttemptsExceededError,
ObjectReconstructionFailedLineageEvictedError,
RaySystemError,
RuntimeEnvSetupError,
TaskPlacementGroupRemoved,
ActorPlacementGroupRemoved,
LocalRayletDiedError,
TaskUnschedulableError,
ActorUnschedulableError,
)
from ray._raylet import (
MessagePackSerializedObject,
MessagePackSerializer,
Pickle5SerializedObject,
Pickle5Writer,
RawSerializedObject,
split_buffer,
unpack_pickle5_buffers,
Pickle5Writer,
Pickle5SerializedObject,
MessagePackSerializer,
MessagePackSerializedObject,
RawSerializedObject,
)
from ray import serialization_addons
from ray.core.generated.common_pb2 import RayErrorInfo
from ray.exceptions import (
ActorPlacementGroupRemoved,
ActorUnschedulableError,
LocalRayletDiedError,
ObjectFetchTimedOutError,
ObjectLostError,
ObjectReconstructionFailedError,
ObjectReconstructionFailedLineageEvictedError,
ObjectReconstructionFailedMaxAttemptsExceededError,
OwnerDiedError,
PlasmaObjectNotAvailable,
RayActorError,
RayError,
RaySystemError,
RayTaskError,
ReferenceCountingAssertionError,
RuntimeEnvSetupError,
TaskCancelledError,
TaskPlacementGroupRemoved,
TaskUnschedulableError,
WorkerCrashedError,
)
from ray.util import serialization_addons
logger = logging.getLogger(__name__)
@ -62,7 +62,7 @@ def _object_ref_deserializer(binary, call_site, owner_address, object_status):
# to 'self' here instead, but this function is itself pickled
# somewhere, which causes an error.
if owner_address:
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
context = worker.get_serialization_context()
outer_id = context.get_outer_object_ref()
@ -79,7 +79,7 @@ def _object_ref_deserializer(binary, call_site, owner_address, object_status):
def _actor_handle_deserializer(serialized_obj):
# If this actor handle was stored in another object, then tell the
# core worker.
context = ray.worker.global_worker.get_serialization_context()
context = ray._private.worker.global_worker.get_serialization_context()
outer_id = context.get_outer_object_ref()
return ray.actor.ActorHandle._deserialization_helper(serialized_obj, outer_id)
@ -96,7 +96,7 @@ class SerializationContext:
self._thread_local = threading.local()
def actor_handle_reducer(obj):
ray.worker.global_worker.check_connected()
ray._private.worker.global_worker.check_connected()
serialized, actor_handle_id = obj._serialization_helper()
# Update ref counting for the actor handle
self.add_contained_object_ref(actor_handle_id)
@ -105,7 +105,7 @@ class SerializationContext:
self._register_cloudpickle_reducer(ray.actor.ActorHandle, actor_handle_reducer)
def object_ref_reducer(obj):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
self.add_contained_object_ref(obj)
obj, owner_address, object_status = worker.core_worker.serialize_object_ref(
@ -171,7 +171,9 @@ class SerializationContext:
# cloudpickle directly or captured in a remote function/actor),
# then pin the object for the lifetime of this worker by adding
# a local reference that won't ever be removed.
ray.worker.global_worker.core_worker.add_object_ref_reference(object_ref)
ray._private.worker.global_worker.core_worker.add_object_ref_reference(
object_ref
)
def _deserialize_pickle5_data(self, data):
try:

View file

@ -4,10 +4,9 @@ import errno
import io
import json
import logging
import mmap
import multiprocessing
import os
from pathlib import Path
import mmap
import random
import shutil
import signal
@ -15,20 +14,21 @@ import socket
import subprocess
import sys
import time
from typing import Optional, List
import uuid
# Ray modules
import ray
import ray.ray_constants as ray_constants
from ray._raylet import GcsClientOptions
from ray._private.gcs_utils import GcsClient
from ray.core.generated.common_pb2 import Language
from pathlib import Path
from typing import List, Optional
# Import psutil and colorama after ray so the packaged version is used.
import colorama
import psutil
# Ray modules
import ray
import ray._private.ray_constants as ray_constants
from ray._private.gcs_utils import GcsClient
from ray._raylet import GcsClientOptions
from ray.core.generated.common_pb2 import Language
resource = None
if sys.platform != "win32":
import resource
@ -382,7 +382,7 @@ def wait_for_node(
the node appears in the client table.
"""
gcs_options = GcsClientOptions.from_gcs_address(gcs_address)
global_state = ray.state.GlobalState()
global_state = ray._private.state.GlobalState()
global_state._initialize_global_state(gcs_options)
start_time = time.time()
while time.time() - start_time < timeout:
@ -401,7 +401,7 @@ def get_node_to_connect_for_driver(
redis_address, gcs_address, node_ip_address, redis_password=None
):
# Get node table from global state accessor.
global_state = ray.state.GlobalState()
global_state = ray._private.state.GlobalState()
gcs_options = _get_gcs_client_options(redis_address, redis_password, gcs_address)
global_state._initialize_global_state(gcs_options)
return global_state.get_node_to_connect_for_driver(node_ip_address)
@ -437,12 +437,12 @@ def remaining_processes_alive():
Exception: An exception is raised if the processes were not started by
ray.init().
"""
if ray.worker._global_node is None:
if ray._private.worker._global_node is None:
raise RuntimeError(
"This process is not in a position to determine "
"whether all processes are alive or not."
)
return ray.worker._global_node.remaining_processes_alive()
return ray._private.worker._global_node.remaining_processes_alive()
def canonicalize_bootstrap_address(addr: str):
@ -540,8 +540,8 @@ def node_ip_address_from_perspective(address: str):
def get_node_ip_address(address="8.8.8.8:53"):
if ray.worker._global_node is not None:
return ray.worker._global_node.node_ip_address
if ray._private.worker._global_node is not None:
return ray._private.worker._global_node.node_ip_address
if sys.platform == "darwin" or sys.platform == "win32":
# Due to the mac osx/windows firewall,
# we use loopback ip as the ip address
@ -2185,7 +2185,7 @@ def start_ray_client_server(
"""
root_ray_dir = Path(__file__).resolve().parents[1]
setup_worker_path = os.path.join(
root_ray_dir, "workers", ray_constants.SETUP_WORKER_FILENAME
root_ray_dir, "_private", "workers", ray_constants.SETUP_WORKER_FILENAME
)
ray_client_server_host = (

View file

@ -1,8 +1,8 @@
import inspect
from inspect import Parameter
import logging
from inspect import Parameter
from ray.util.inspect import is_cython
from ray._private.inspect_util import is_cython
# Logger for this module. It should be configured at the entry point
# into the program using Ray. Ray provides a default configuration at

View file

@ -1,18 +1,17 @@
from collections import defaultdict
import json
import logging
from collections import defaultdict
from google.protobuf.json_format import MessageToDict
import ray
import ray._private.gcs_utils as gcs_utils
from ray.util.annotations import DeveloperAPI
from google.protobuf.json_format import MessageToDict
from ray.core.generated import gcs_pb2
from ray._private.client_mode_hook import client_mode_hook
from ray._private.utils import decode, binary_to_hex, hex_to_binary
from ray._private.resource_spec import NODE_ID_PREFIX
from ray._private.utils import binary_to_hex, decode, hex_to_binary
from ray._raylet import GlobalStateAccessor
from ray.core.generated import gcs_pb2
from ray.util.annotations import DeveloperAPI
logger = logging.getLogger(__name__)

View file

@ -1,9 +1,9 @@
from typing import List, Optional, TYPE_CHECKING
from pathlib import Path
import os
import urllib
import importlib
import os
import re
import urllib
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional
from ray._private.client_mode_hook import client_mode_hook
@ -260,7 +260,7 @@ class KVClient:
FileNotFoundError if the given path is not found.
NotADirectoryError if the given path isn't a valid directory.
"""
from pyarrow.fs import FileSelector, LocalFileSystem, FileType
from pyarrow.fs import FileSelector, FileType, LocalFileSystem
full_path = self._resolve_path(path)
selector = FileSelector(full_path, recursive=False)

View file

@ -1,43 +1,39 @@
import asyncio
import fnmatch
import functools
import io
import fnmatch
import logging
import math
import os
import pathlib
import socket
import subprocess
import sys
import tempfile
import time
import timeit
import socket
import math
import traceback
from typing import Optional, Any, List, Dict
from contextlib import redirect_stdout, redirect_stderr, contextmanager
from contextlib import contextmanager, redirect_stderr, redirect_stdout
from typing import Any, Dict, List, Optional
import yaml
import logging
import tempfile
import grpc
from grpc._channel import _InactiveRpcError
import numpy as np
import psutil # We must import psutil after ray because we bundle it with ray.
import yaml
from grpc._channel import _InactiveRpcError
import ray
import ray._private.services
import ray._private.utils
import ray._private.gcs_utils as gcs_utils
import ray._private.memory_monitor as memory_monitor
from ray._raylet import GcsClientOptions, GlobalStateAccessor
from ray.core.generated import gcs_pb2
from ray.core.generated import node_manager_pb2
from ray.core.generated import node_manager_pb2_grpc
from ray._private.gcs_pubsub import (
GcsErrorSubscriber,
GcsLogSubscriber,
)
import ray._private.services
import ray._private.utils
from ray._private.gcs_pubsub import GcsErrorSubscriber, GcsLogSubscriber
from ray._private.internal_api import memory_summary
from ray._private.tls_utils import generate_self_signed_tls_certs
from ray.util.queue import Queue, _QueueActor, Empty
from ray._raylet import GcsClientOptions, GlobalStateAccessor
from ray.core.generated import gcs_pb2, node_manager_pb2, node_manager_pb2_grpc
from ray.scripts.scripts import main as ray_main
from ray.internal.internal_api import memory_summary
from ray.util.queue import Empty, Queue, _QueueActor
try:
from prometheus_client.parser import text_string_to_metric_families
@ -47,9 +43,6 @@ except (ImportError, ModuleNotFoundError):
raise ModuleNotFoundError("`prometheus_client` not found")
import psutil # We must import psutil after ray because we bundle it with ray.
class RayTestTimeoutException(Exception):
"""Exception used to identify timeouts from test utilities."""
@ -282,7 +275,7 @@ def wait_for_num_actors(num_actors, state=None, timeout=10):
len(
[
_
for _ in ray.state.actors().values()
for _ in ray._private.state.actors().values()
if state is None or _["State"] == state
]
)
@ -328,11 +321,11 @@ def wait_for_num_nodes(num_nodes: int, timeout_s: int):
def kill_actor_and_wait_for_failure(actor, timeout=10, retry_interval_ms=100):
actor_id = actor._actor_id.hex()
current_num_restarts = ray.state.actors(actor_id)["NumRestarts"]
current_num_restarts = ray._private.state.actors(actor_id)["NumRestarts"]
ray.kill(actor)
start = time.time()
while time.time() - start <= timeout:
actor_status = ray.state.actors(actor_id)
actor_status = ray._private.state.actors(actor_id)
if (
actor_status["State"] == convert_actor_state(gcs_utils.ActorTableData.DEAD)
or actor_status["NumRestarts"] > current_num_restarts
@ -617,7 +610,8 @@ def get_other_nodes(cluster, exclude_head=False):
return [
node
for node in cluster.list_all_nodes()
if node._raylet_socket_name != ray.worker._global_node._raylet_socket_name
if node._raylet_socket_name
!= ray._private.worker._global_node._raylet_socket_name
and (exclude_head is False or node.head is False)
]
@ -629,7 +623,7 @@ def get_non_head_nodes(cluster):
def init_error_pubsub():
"""Initialize error info pub/sub"""
s = GcsErrorSubscriber(address=ray.worker.global_worker.gcs_client.address)
s = GcsErrorSubscriber(address=ray._private.worker.global_worker.gcs_client.address)
s.subscribe()
return s
@ -657,7 +651,7 @@ def get_error_message(subscriber, num=1e6, error_type=None, timeout=20):
def init_log_pubsub():
"""Initialize log pub/sub"""
s = GcsLogSubscriber(address=ray.worker.global_worker.gcs_client.address)
s = GcsLogSubscriber(address=ray._private.worker.global_worker.gcs_client.address)
s.subscribe()
return s
@ -1007,7 +1001,7 @@ def monitor_memory_usage(
"""
return self.peak_memory_usage, self.peak_top_n_memory_usage
current_node_ip = ray.worker.global_worker.node_ip_address
current_node_ip = ray._private.worker.global_worker.node_ip_address
# Schedule the actor on the current node.
memory_monitor_actor = MemoryMonitorActor.options(
resources={f"node:{current_node_ip}": 0.001}
@ -1160,8 +1154,8 @@ def get_and_run_node_killer(
alive_nodes += 1
return alive_nodes
head_node_ip = ray.worker.global_worker.node_ip_address
head_node_id = ray.worker.global_worker.current_node_id.hex()
head_node_ip = ray._private.worker.global_worker.node_ip_address
head_node_id = ray._private.worker.global_worker.current_node_id.hex()
# Schedule the actor on the current node.
node_killer = NodeKillerActor.options(
resources={f"node:{head_node_ip}": 0.001},
@ -1306,7 +1300,9 @@ def simulate_storage(storage_type, root=None):
yield "file://" + root
elif storage_type == "s3":
import uuid
from moto import mock_s3
from ray.tests.mock_s3_server import start_service, stop_process
@contextmanager

View file

@ -56,8 +56,8 @@ import requests
import yaml
import ray
import ray._private.ray_constants as ray_constants
import ray._private.usage.usage_constants as usage_constant
import ray.ray_constants as ray_constants
from ray.experimental.internal_kv import _internal_kv_initialized, _internal_kv_put
logger = logging.getLogger(__name__)
@ -184,8 +184,8 @@ def record_library_usage(library_usage: str):
# it can be reported if the library is imported from
# e.g., API server.
if (
ray.worker.global_worker.mode == ray.SCRIPT_MODE
or ray.worker.global_worker.mode == ray.WORKER_MODE
ray._private.worker.global_worker.mode == ray.SCRIPT_MODE
or ray._private.worker.global_worker.mode == ray.WORKER_MODE
):
_put_library_usage(library_usage)
@ -195,13 +195,13 @@ def _put_pre_init_library_usages():
# NOTE: When the lib is imported from a worker, ray should
# always be initialized, so there's no need to register the
# pre init hook.
if ray.worker.global_worker.mode != ray.SCRIPT_MODE:
if ray._private.worker.global_worker.mode != ray.SCRIPT_MODE:
return
for library_usage in _recorded_library_usages:
_put_library_usage(library_usage)
ray.worker._post_init_hooks.append(_put_pre_init_library_usages)
ray._private.worker._post_init_hooks.append(_put_pre_init_library_usages)
def _usage_stats_report_url():
@ -420,7 +420,7 @@ def get_cluster_status_to_report(gcs_client, num_retries: int) -> ClusterStatusT
try:
cluster_status = ray._private.utils.internal_kv_get_with_retry(
gcs_client,
ray.ray_constants.DEBUG_AUTOSCALING_STATUS,
ray._private.ray_constants.DEBUG_AUTOSCALING_STATUS,
namespace=None,
num_retries=num_retries,
)

View file

@ -3,6 +3,7 @@ import errno
import functools
import hashlib
import importlib
import inspect
import logging
import multiprocessing
import os
@ -12,28 +13,35 @@ import sys
import tempfile
import threading
import time
from typing import Optional, Sequence, Tuple, Any, Union, Dict
import uuid
import grpc
import warnings
from inspect import signature
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict, Optional, Sequence, Tuple, Union
import grpc
import numpy as np
# Import psutil after ray so the packaged version is used.
import psutil
from google.protobuf import json_format
import ray
import ray._private.ray_constants as ray_constants
from ray._private.tls_utils import load_certs_from_env
from ray.core.generated.gcs_pb2 import ErrorTableData
from ray.core.generated.runtime_env_common_pb2 import (
RuntimeEnvInfo as ProtoRuntimeEnvInfo,
)
if TYPE_CHECKING:
from ray.runtime_env import RuntimeEnv
try:
from grpc import aio as aiogrpc
except ImportError:
from grpc.experimental import aio as aiogrpc
import inspect
from inspect import signature
from pathlib import Path
import numpy as np
import ray
from ray.core.generated.gcs_pb2 import ErrorTableData
import ray.ray_constants as ray_constants
from ray._private.tls_utils import load_certs_from_env
# Import psutil after ray so the packaged version is used.
import psutil
pwd = None
if sys.platform != "win32":
@ -670,7 +678,7 @@ def detect_fate_sharing_support_win32():
import ctypes
try:
from ctypes.wintypes import BOOL, DWORD, HANDLE, LPVOID, LPCWSTR
from ctypes.wintypes import BOOL, DWORD, HANDLE, LPCWSTR, LPVOID
kernel32 = ctypes.WinDLL("kernel32")
kernel32.CreateJobObjectW.argtypes = (LPVOID, LPCWSTR)
@ -752,7 +760,7 @@ def detect_fate_sharing_support_linux():
global linux_prctl
if linux_prctl is None and sys.platform.startswith("linux"):
try:
from ctypes import c_int, c_ulong, CDLL
from ctypes import CDLL, c_int, c_ulong
prctl = CDLL(None).prctl
prctl.restype = c_int
@ -1349,3 +1357,78 @@ def check_version_info(cluster_metadata):
" Python: " + version_info[1] + "\n"
)
raise RuntimeError(error_message)
def get_runtime_env_info(
runtime_env: "RuntimeEnv",
*,
is_job_runtime_env: bool = False,
serialize: bool = False,
):
"""Create runtime env info from runtime env.
In the user interface, the argument `runtime_env` contains some fields
which not contained in `ProtoRuntimeEnv` but in `ProtoRuntimeEnvInfo`,
such as `eager_install`. This function will extract those fields from
`RuntimeEnv` and create a new `ProtoRuntimeEnvInfo`, and serialize it.
"""
from ray.runtime_env import RuntimeEnvConfig
proto_runtime_env_info = ProtoRuntimeEnvInfo()
proto_runtime_env_info.uris[:] = runtime_env.get_uris()
# Normally, `RuntimeEnv` should guarantee the accuracy of field eager_install,
# but so far, the internal code has not completely prohibited direct
# modification of fields in RuntimeEnv, so we should check it for insurance.
# TODO(Catch-Bull): overload `__setitem__` for `RuntimeEnv`, change the
# runtime_env of all internal code from dict to RuntimeEnv.
eager_install = runtime_env.get("eager_install")
if is_job_runtime_env or eager_install is not None:
if eager_install is None:
eager_install = True
elif not isinstance(eager_install, bool):
raise TypeError(
f"eager_install must be a boolean. got {type(eager_install)}"
)
proto_runtime_env_info.runtime_env_eager_install = eager_install
runtime_env_config = runtime_env.get("config")
if runtime_env_config is None:
runtime_env_config = RuntimeEnvConfig.default_config()
else:
runtime_env_config = RuntimeEnvConfig.parse_and_validate_runtime_env_config(
runtime_env_config
)
proto_runtime_env_info.runtime_env_config.CopyFrom(
runtime_env_config.build_proto_runtime_env_config()
)
proto_runtime_env_info.serialized_runtime_env = runtime_env.serialize()
if not serialize:
return proto_runtime_env_info
return json_format.MessageToJson(proto_runtime_env_info)
def parse_runtime_env(runtime_env: Optional[Union[Dict, "RuntimeEnv"]]):
from ray.runtime_env import RuntimeEnv
# Parse local pip/conda config files here. If we instead did it in
# .remote(), it would get run in the Ray Client server, which runs on
# a remote node where the files aren't available.
if runtime_env:
if isinstance(runtime_env, dict):
return RuntimeEnv(**(runtime_env or {}))
raise TypeError(
"runtime_env must be dict or RuntimeEnv, ",
f"but got: {type(runtime_env)}",
)
else:
# Keep the new_runtime_env as None. In .remote(), we need to know
# if runtime_env is None to know whether or not to fall back to the
# runtime_env specified in the @ray.remote decorator.
return None

View file

@ -1,4 +1,3 @@
from contextlib import contextmanager
import atexit
import faulthandler
import functools
@ -15,6 +14,7 @@ import traceback
import warnings
from abc import ABCMeta, abstractmethod
from collections.abc import Mapping
from contextlib import contextmanager
from dataclasses import dataclass
from typing import (
Any,
@ -31,64 +31,53 @@ from typing import (
overload,
)
# Ray modules
import ray.cloudpickle as pickle
import ray._private.memory_monitor as memory_monitor
import ray.internal.storage as storage
from ray.internal.storage import _load_class
import ray.node
import ray.job_config
import ray._private.parameter
import ray.ray_constants as ray_constants
import ray.remote_function
import ray.serialization as serialization
import ray._private.gcs_utils as gcs_utils
import ray._private.services as services
from ray._private.gcs_pubsub import (
GcsPublisher,
GcsErrorSubscriber,
GcsLogSubscriber,
GcsFunctionKeySubscriber,
)
from ray._private.runtime_env.py_modules import upload_py_modules_if_needed
from ray._private.runtime_env.working_dir import upload_working_dir_if_needed
from ray._private.runtime_env.constants import RAY_JOB_CONFIG_JSON_ENV_VAR
import ray._private.import_thread as import_thread
from ray.util.tracing.tracing_helper import import_from_string
from ray.util.annotations import PublicAPI, DeveloperAPI, Deprecated
from ray.util.debug import log_once
from ray._private import ray_option_utils
import ray
import colorama
import setproctitle
import ray.state
from ray import (
ActorID,
JobID,
ObjectRef,
Language,
)
import ray
import ray._private.gcs_utils as gcs_utils
import ray._private.import_thread as import_thread
import ray._private.memory_monitor as memory_monitor
import ray._private.node
import ray._private.parameter
import ray._private.profiling as profiling
import ray._private.ray_constants as ray_constants
import ray._private.serialization as serialization
import ray._private.services as services
import ray._private.state
import ray._private.storage as storage
from ray.exceptions import (
RaySystemError,
RayError,
RayTaskError,
ObjectStoreFullError,
)
from ray._private.function_manager import FunctionActorManager, make_function_table_key
from ray._private.ray_logging import setup_logger
from ray._private.ray_logging import global_worker_stdstream_dispatcher
from ray._private.utils import check_oversized_function
from ray.util.inspect import is_cython
from ray.experimental.internal_kv import (
_internal_kv_initialized,
_initialize_internal_kv,
_internal_kv_reset,
_internal_kv_get,
)
# Ray modules
import ray.cloudpickle as pickle
import ray.job_config
import ray.remote_function
from ray import ActorID, JobID, Language, ObjectRef
from ray._private import ray_option_utils
from ray._private.client_mode_hook import client_mode_hook
from ray._private.function_manager import FunctionActorManager, make_function_table_key
from ray._private.gcs_pubsub import (
GcsErrorSubscriber,
GcsFunctionKeySubscriber,
GcsLogSubscriber,
GcsPublisher,
)
from ray._private.inspect_util import is_cython
from ray._private.ray_logging import global_worker_stdstream_dispatcher, setup_logger
from ray._private.runtime_env.constants import RAY_JOB_CONFIG_JSON_ENV_VAR
from ray._private.runtime_env.py_modules import upload_py_modules_if_needed
from ray._private.runtime_env.working_dir import upload_working_dir_if_needed
from ray._private.storage import _load_class
from ray._private.utils import check_oversized_function
from ray.exceptions import ObjectStoreFullError, RayError, RaySystemError, RayTaskError
from ray.experimental.internal_kv import (
_initialize_internal_kv,
_internal_kv_get,
_internal_kv_initialized,
_internal_kv_reset,
)
from ray.util.annotations import Deprecated, DeveloperAPI, PublicAPI
from ray.util.debug import log_once
from ray.util.tracing.tracing_helper import _import_from_string
SCRIPT_MODE = 0
WORKER_MODE = 1
@ -411,7 +400,7 @@ class Worker:
functions outside of this class are considered exposed.
Attributes:
node (ray.node.Node): The node this worker is attached to.
node (ray._private.node.Node): The node this worker is attached to.
mode: The mode of the worker. One of SCRIPT_MODE, LOCAL_MODE, and
WORKER_MODE.
cached_functions_to_run: A list of functions to run on all of
@ -878,7 +867,7 @@ def get_resource_ids():
if _mode() == LOCAL_MODE:
raise RuntimeError(
"ray.worker.get_resource_ids() currently does not work in local_mode."
"ray._private.worker.get_resource_ids() does not work in local_mode."
)
return global_worker.core_worker.resource_ids()
@ -985,7 +974,7 @@ per worker process.
"""
_global_node = None
"""ray.node.Node: The global node object that is created by ray.init()."""
"""ray._private.node.Node: The global node object that is created by ray.init()."""
@PublicAPI
@ -1365,7 +1354,7 @@ def init(
# shutdown the node in the ray.shutdown call that happens in the atexit
# handler. We still spawn a reaper process in case the atexit handler
# isn't called.
_global_node = ray.node.Node(
_global_node = ray._private.node.Node(
head=True, shutdown_at_exit=False, spawn_reaper=True, ray_params=ray_params
)
else:
@ -1419,7 +1408,7 @@ def init(
enable_object_reconstruction=_enable_object_reconstruction,
metrics_export_port=_metrics_export_port,
)
_global_node = ray.node.Node(
_global_node = ray._private.node.Node(
ray_params,
head=False,
shutdown_at_exit=False,
@ -1502,7 +1491,7 @@ def shutdown(_exiting_interpreter: bool = False):
# We need to reset function actor manager to clear the context
global_worker.function_actor_manager = FunctionActorManager(global_worker)
# Disconnect global state from GCS.
ray.state.state.disconnect()
ray._private.state.state.disconnect()
# Shut down the Ray processes.
global _global_node
@ -1547,8 +1536,8 @@ def custom_excepthook(type, value, tb):
worker_type = gcs_utils.DRIVER
worker_info = {"exception": error_message}
ray.state.state._check_connected()
ray.state.state.add_worker(worker_id, worker_type, worker_info)
ray._private.state.state._check_connected()
ray._private.state.state.add_worker(worker_id, worker_type, worker_info)
# Call the normal excepthook.
normal_excepthook(type, value, tb)
@ -1747,7 +1736,7 @@ def is_initialized() -> bool:
Returns:
True if ray.init has already been called and false otherwise.
"""
return ray.worker.global_worker.connected
return ray._private.worker.global_worker.connected
def connect(
@ -1766,7 +1755,7 @@ def connect(
"""Connect this worker to the raylet, to Plasma, and to GCS.
Args:
node (ray.node.Node): The node to connect.
node (ray._private.node.Node): The node to connect.
mode: The mode of the worker. One of SCRIPT_MODE, WORKER_MODE, and LOCAL_MODE.
log_to_driver: If true, then output from all of the worker
processes on all nodes will be directed to the driver.
@ -1796,7 +1785,7 @@ def connect(
worker.gcs_client = node.get_gcs_client()
assert worker.gcs_client is not None
_initialize_internal_kv(worker.gcs_client)
ray.state.state._initialize_global_state(
ray._private.state.state._initialize_global_state(
ray._raylet.GcsClientOptions.from_gcs_address(node.gcs_address)
)
worker.gcs_publisher = GcsPublisher(address=worker.gcs_client.address)
@ -1814,7 +1803,7 @@ def connect(
else:
# This is the code path of driver mode.
if job_id is None:
job_id = ray.state.next_job_id()
job_id = ray._private.state.next_job_id()
if mode is not SCRIPT_MODE and mode is not LOCAL_MODE and setproctitle:
process_name = ray_constants.WORKER_PROCESS_TYPE_IDLE_WORKER
@ -2006,7 +1995,7 @@ def connect(
if tracing_hook_val is not None:
ray.util.tracing.tracing_helper._global_is_tracing_enabled = True
if not getattr(ray, "__traced__", False):
_setup_tracing = import_from_string(tracing_hook_val.decode("utf-8"))
_setup_tracing = _import_from_string(tracing_hook_val.decode("utf-8"))
_setup_tracing()
ray.__traced__ = True
@ -2045,7 +2034,7 @@ def disconnect(exiting_interpreter=False):
except AttributeError:
ray_actor = None # This can occur during program termination
if ray_actor is not None:
ray_actor.ActorClassMethodMetadata.reset_cache()
ray_actor._ActorClassMethodMetadata.reset_cache()
@contextmanager
@ -2189,7 +2178,7 @@ def get(
if debugger_breakpoint != b"":
frame = sys._getframe().f_back
rdb = ray.util.pdb.connect_ray_pdb(
rdb = ray.util.pdb._connect_ray_pdb(
host=None,
port=None,
patch_stdstreams=False,
@ -2230,10 +2219,12 @@ def put(
if _owner is None:
serialize_owner_address = None
elif isinstance(_owner, ray.actor.ActorHandle):
# Ensure `ray.state.state.global_state_accessor` is not None
ray.state.state._check_connected()
# Ensure `ray._private.state.state.global_state_accessor` is not None
ray._private.state.state._check_connected()
owner_address = gcs_utils.ActorTableData.FromString(
ray.state.state.global_state_accessor.get_actor_info(_owner._actor_id)
ray._private.state.state.global_state_accessor.get_actor_info(
_owner._actor_id
)
).address
if len(owner_address.worker_id) == 0:
raise RuntimeError(f"{_owner} is not alive, it's worker_id is empty!")
@ -2462,7 +2453,7 @@ def cancel(object_ref: "ray.ObjectRef", *, force: bool = False, recursive: bool
Raises:
TypeError: This is also raised for actor tasks.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
if not isinstance(object_ref, ray.ObjectRef):
@ -2496,7 +2487,7 @@ def _make_remote(function_or_class, options):
if inspect.isclass(function_or_class):
ray_option_utils.validate_actor_options(options, in_options=False)
return ray.actor.make_actor(function_or_class, options)
return ray.actor._make_actor(function_or_class, options)
raise TypeError(
"The @ray.remote decorator must be applied to either a function or a class."

View file

@ -1,17 +1,17 @@
import argparse
import base64
import json
import time
import sys
import os
import sys
import time
import ray
import ray.actor
import ray.node
import ray.ray_constants as ray_constants
import ray._private.node
import ray._private.ray_constants as ray_constants
import ray._private.utils
import ray.actor
from ray._private.parameter import RayParams
from ray._private.ray_logging import get_worker_log_file_name, configure_log_file
from ray._private.ray_logging import configure_log_file, get_worker_log_file_name
parser = argparse.ArgumentParser(
description=("Parse addresses for the worker to connect to.")
@ -182,7 +182,7 @@ if __name__ == "__main__":
gcs_address=args.gcs_address,
)
node = ray.node.Node(
node = ray._private.node.Node(
ray_params,
head=False,
shutdown_at_exit=False,
@ -194,8 +194,7 @@ if __name__ == "__main__":
# connect to raylet. Otherwise we may receive requests before the
# external storage is intialized.
if mode == ray.RESTORE_WORKER_MODE or mode == ray.SPILL_WORKER_MODE:
from ray import external_storage
from ray.internal import storage
from ray._private import external_storage, storage
storage._init_storage(args.storage, is_head=False)
if args.object_spilling_config:
@ -207,8 +206,8 @@ if __name__ == "__main__":
object_spilling_config, node.session_name
)
ray.worker._global_node = node
ray.worker.connect(
ray._private.worker._global_node = node
ray._private.worker.connect(
node,
mode=mode,
runtime_env_hash=args.runtime_env_hash,
@ -217,7 +216,7 @@ if __name__ == "__main__":
)
# Add code search path to sys.path, set load_code_from_local.
core_worker = ray.worker.global_worker.core_worker
core_worker = ray._private.worker.global_worker.core_worker
code_search_path = core_worker.get_job_config().code_search_path
load_code_from_local = False
if code_search_path:
@ -226,7 +225,7 @@ if __name__ == "__main__":
if os.path.isfile(p):
p = os.path.dirname(p)
sys.path.insert(0, p)
ray.worker.global_worker.set_load_code_from_local(load_code_from_local)
ray._private.worker.global_worker.set_load_code_from_local(load_code_from_local)
# Setup log file.
out_file, err_file = node.get_log_file_handles(
@ -235,7 +234,7 @@ if __name__ == "__main__":
configure_log_file(out_file, err_file)
if mode == ray.WORKER_MODE:
ray.worker.global_worker.main_loop()
ray._private.worker.global_worker.main_loop()
elif mode in [ray.RESTORE_WORKER_MODE, ray.SPILL_WORKER_MODE]:
# It is handled by another thread in the C++ core worker.
# We just need to keep the worker alive.

View file

@ -1,10 +1,10 @@
import argparse
import logging
from ray._private.ray_constants import LOGGER_FORMAT, LOGGER_LEVEL
from ray._private.ray_logging import setup_logger
from ray._private.runtime_env.context import RuntimeEnvContext
from ray.core.generated.common_pb2 import Language
from ray.ray_constants import LOGGER_LEVEL, LOGGER_FORMAT
logger = logging.getLogger(__name__)

View file

@ -125,12 +125,12 @@ from ray.exceptions import (
AsyncioActorExit,
PendingCallsLimitExceeded,
)
from ray import external_storage
from ray._private import external_storage
from ray.util.scheduling_strategies import (
PlacementGroupSchedulingStrategy,
NodeAffinitySchedulingStrategy,
)
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
from ray._private.async_compat import sync_to_async, get_new_event_loop
from ray._private.client_mode_hook import disable_client_hook
import ray._private.gcs_utils as gcs_utils
@ -396,7 +396,7 @@ cdef prepare_args_internal(
c_string put_arg_call_site
c_vector[CObjectReference] inlined_refs
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
put_threshold = RayConfig.instance().max_direct_call_object_size()
total_inlined = 0
rpc_inline_threshold = RayConfig.instance().task_rpc_inlined_bytes_limit()
@ -499,7 +499,7 @@ cdef execute_task(
is_application_level_error[0] = False
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
manager = worker.function_actor_manager
actor = None
cdef:
@ -637,14 +637,14 @@ cdef execute_task(
# We deserialize objects in event loop thread to
# prevent segfaults. See #7799
async def deserialize_args():
return (ray.worker.global_worker
return (ray._private.worker.global_worker
.deserialize_objects(
metadata_pairs, object_refs))
args = core_worker.run_async_func_in_event_loop(
deserialize_args, function_descriptor,
name_of_concurrency_group_to_execute)
else:
args = ray.worker.global_worker.deserialize_objects(
args = ray._private.worker.global_worker.deserialize_objects(
metadata_pairs, object_refs)
for arg in args:
@ -664,13 +664,13 @@ cdef execute_task(
if is_existing:
title = f"{title}::Exiting"
next_title = f"{next_title}::Exiting"
with ray.worker._changeproctitle(title, next_title):
with ray._private.worker._changeproctitle(title, next_title):
if debugger_breakpoint != b"":
ray.util.pdb.set_trace(
breakpoint_uuid=debugger_breakpoint)
outputs = function_executor(*args, **kwargs)
next_breakpoint = (
ray.worker.global_worker.debugger_breakpoint)
ray._private.worker.global_worker.debugger_breakpoint)
if next_breakpoint != b"":
# If this happens, the user typed "remote" and
# there were no more remote calls left in this
@ -684,7 +684,7 @@ cdef execute_task(
"RAY_PDB_CONTINUE_{}".format(next_breakpoint),
namespace=ray_constants.KV_NAMESPACE_PDB
)
ray.worker.global_worker.debugger_breakpoint = b""
ray._private.worker.global_worker.debugger_breakpoint = b""
task_exception = False
except AsyncioActorExit as e:
exit_current_actor_if_asyncio()
@ -834,7 +834,7 @@ cdef CRayStatus task_execution_handler(
"occurred while the worker "
"was executing a task.")
ray._private.utils.push_error_to_driver(
ray.worker.global_worker,
ray._private.worker.global_worker,
"worker_crash",
traceback_str,
job_id=None)
@ -910,7 +910,7 @@ cdef c_vector[c_string] spill_objects_handler(
object_refs_to_spill[i].owner_address()
.SerializeAsString())
try:
with ray.worker._changeproctitle(
with ray._private.worker._changeproctitle(
ray_constants.WORKER_PROCESS_TYPE_SPILL_WORKER,
ray_constants.WORKER_PROCESS_TYPE_SPILL_WORKER_IDLE):
urls = external_storage.spill_objects(
@ -923,7 +923,7 @@ cdef c_vector[c_string] spill_objects_handler(
"was spilling objects: {}".format(err))
logger.exception(exception_str)
ray._private.utils.push_error_to_driver(
ray.worker.global_worker,
ray._private.worker.global_worker,
"spill_objects_error",
traceback.format_exc() + exception_str,
job_id=None)
@ -944,7 +944,7 @@ cdef int64_t restore_spilled_objects_handler(
object_refs_to_restore,
skip_adding_local_ref=False)
try:
with ray.worker._changeproctitle(
with ray._private.worker._changeproctitle(
ray_constants.WORKER_PROCESS_TYPE_RESTORE_WORKER,
ray_constants.WORKER_PROCESS_TYPE_RESTORE_WORKER_IDLE):
bytes_restored = external_storage.restore_spilled_objects(
@ -956,7 +956,7 @@ cdef int64_t restore_spilled_objects_handler(
logger.exception(exception_str)
if os.getenv("RAY_BACKEND_LOG_LEVEL") == "debug":
ray._private.utils.push_error_to_driver(
ray.worker.global_worker,
ray._private.worker.global_worker,
"restore_objects_error",
traceback.format_exc() + exception_str,
job_id=None)
@ -987,7 +987,7 @@ cdef void delete_spilled_objects_handler(
assert False, ("This line shouldn't be reachable.")
# Delete objects.
with ray.worker._changeproctitle(
with ray._private.worker._changeproctitle(
proctitle,
original_proctitle):
external_storage.delete_spilled_objects(urls)
@ -997,7 +997,7 @@ cdef void delete_spilled_objects_handler(
"was deleting spilled objects.")
logger.exception(exception_str)
ray._private.utils.push_error_to_driver(
ray.worker.global_worker,
ray._private.worker.global_worker,
"delete_spilled_objects_error",
traceback.format_exc() + exception_str,
job_id=None)
@ -1005,7 +1005,7 @@ cdef void delete_spilled_objects_handler(
cdef void unhandled_exception_handler(const CRayObject& error) nogil:
with gil:
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
data = None
metadata = None
if error.HasData():
@ -1035,10 +1035,10 @@ cdef void get_py_stack(c_string* stack_out) nogil:
while frame and len(msg_frames) < 4:
filename = frame.f_code.co_filename
# Decode Ray internal frames to add annotations.
if filename.endswith("ray/worker.py"):
if filename.endswith("_private/worker.py"):
if frame.f_code.co_name == "put":
msg_frames = ["(put object) "]
elif filename.endswith("ray/workers/default_worker.py"):
elif filename.endswith("_private/workers/default_worker.py"):
pass
elif filename.endswith("ray/remote_function.py"):
# TODO(ekl) distinguish between task return objects and
@ -1048,7 +1048,7 @@ cdef void get_py_stack(c_string* stack_out) nogil:
# TODO(ekl) distinguish between actor return objects and
# arguments. This can only be done in the core worker.
msg_frames = ["(actor call) "]
elif filename.endswith("ray/serialization.py"):
elif filename.endswith("_private/serialization.py"):
if frame.f_code.co_name == "id_deserializer":
msg_frames = ["(deserialize task arg) "]
else:
@ -1071,7 +1071,7 @@ cdef shared_ptr[CBuffer] string_to_buffer(c_string& c_str):
cdef void terminate_asyncio_thread() nogil:
with gil:
core_worker = ray.worker.global_worker.core_worker
core_worker = ray._private.worker.global_worker.core_worker
core_worker.stop_and_join_asyncio_threads_if_exist()
@ -1837,7 +1837,7 @@ cdef class CoreWorker:
c_actor_id)
cdef make_actor_handle(self, ActorHandleSharedPtr c_actor_handle):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
manager = worker.function_actor_manager
@ -1858,7 +1858,7 @@ cdef class CoreWorker:
actor_method_cpu = 0 # Actor is created by non Python worker.
actor_class = manager.load_actor_class(
job_id, actor_creation_function_descriptor)
method_meta = ray.actor.ActorClassMethodMetadata.create(
method_meta = ray.actor._ActorClassMethodMetadata.create(
actor_class, actor_creation_function_descriptor)
return ray.actor.ActorHandle(language, actor_id,
method_meta.decorators,
@ -2049,14 +2049,14 @@ cdef class CoreWorker:
serialized_object = context.serialize(output)
data_size = serialized_object.total_bytes
metadata_str = serialized_object.metadata
if ray.worker.global_worker.debugger_get_breakpoint:
if ray._private.worker.global_worker.debugger_get_breakpoint:
breakpoint = (
ray.worker.global_worker.debugger_get_breakpoint)
ray._private.worker.global_worker.debugger_get_breakpoint)
metadata_str += (
b"," + ray_constants.OBJECT_METADATA_DEBUG_PREFIX +
breakpoint.encode())
# Reset debugging context of this worker.
ray.worker.global_worker.debugger_get_breakpoint = b""
ray._private.worker.global_worker.debugger_get_breakpoint = b""
metadata = string_to_buffer(metadata_str)
contained_id = ObjectRefsToVector(
serialized_object.contained_object_refs)
@ -2301,7 +2301,7 @@ cdef void async_callback(shared_ptr[CRayObject] obj,
data_metadata_pairs = RayObjectsToDataMetadataPairs(
objects_to_deserialize)
ids_to_deserialize = [ObjectRef(object_ref.Binary())]
result = ray.worker.global_worker.deserialize_objects(
result = ray._private.worker.global_worker.deserialize_objects(
data_metadata_pairs, ids_to_deserialize)[0]
py_callback = <object>user_callback

View file

@ -1,39 +1,38 @@
import inspect
import logging
import weakref
from typing import Optional, List, Dict, Any
from typing import Any, Dict, List, Optional
import ray.ray_constants as ray_constants
import ray._raylet
import ray._private.ray_constants as ray_constants
import ray._private.signature as signature
from ray.utils import get_runtime_env_info, parse_runtime_env
import ray.worker
from ray.util.annotations import PublicAPI, DeveloperAPI
from ray.util.placement_group import configure_placement_group_based_on_context
import ray._private.worker
import ray._raylet
from ray import ActorClassID, Language, cross_language
from ray._private import ray_option_utils
from ray._private.client_mode_hook import (
client_mode_convert_actor,
client_mode_hook,
client_mode_should_convert,
)
from ray._private.inspect_util import (
is_class_method,
is_function_or_method,
is_static_method,
)
from ray._private.utils import get_runtime_env_info, parse_runtime_env
from ray._raylet import PythonFunctionDescriptor
from ray.exceptions import AsyncioActorExit
from ray.util.annotations import DeveloperAPI, PublicAPI
from ray.util.placement_group import _configure_placement_group_based_on_context
from ray.util.scheduling_strategies import (
PlacementGroupSchedulingStrategy,
SchedulingStrategyT,
)
from ray import ActorClassID, Language
from ray._raylet import PythonFunctionDescriptor
from ray._private.client_mode_hook import client_mode_hook
from ray._private.client_mode_hook import client_mode_should_convert
from ray._private.client_mode_hook import client_mode_convert_actor
from ray import cross_language
from ray.util.inspect import (
is_function_or_method,
is_class_method,
is_static_method,
)
from ray.exceptions import AsyncioActorExit
from ray.util.tracing.tracing_helper import (
_inject_tracing_into_class,
_tracing_actor_creation,
_tracing_actor_method_invocation,
_inject_tracing_into_class,
)
from ray._private import ray_option_utils
logger = logging.getLogger(__name__)
@ -88,6 +87,7 @@ def method(*args, **kwargs):
# Create objects to wrap method invocations. This is done so that we can
# invoke methods with actor.method.remote() instead of actor.method().
@PublicAPI
class ActorMethod:
"""A class used to invoke an actor method.
@ -200,7 +200,7 @@ class ActorMethod:
)
class ActorClassMethodMetadata(object):
class _ActorClassMethodMetadata(object):
"""Metadata for all methods in an actor class. This data can be cached.
Attributes:
@ -214,7 +214,7 @@ class ActorClassMethodMetadata(object):
each actor method.
"""
_cache = {} # This cache will be cleared in ray.worker.disconnect()
_cache = {} # This cache will be cleared in ray._private.worker.disconnect()
def __init__(self):
class_name = type(self).__name__
@ -286,7 +286,7 @@ class ActorClassMethodMetadata(object):
return self
class ActorClassMetadata:
class _ActorClassMetadata:
"""Metadata for an actor class.
Attributes:
@ -353,18 +353,19 @@ class ActorClassMetadata:
self.concurrency_groups = concurrency_groups
self.scheduling_strategy = scheduling_strategy
self.last_export_session_and_job = None
self.method_meta = ActorClassMethodMetadata.create(
self.method_meta = _ActorClassMethodMetadata.create(
modified_class, actor_creation_function_descriptor
)
@PublicAPI
class ActorClassInheritanceException(TypeError):
pass
def _process_option_dict(actor_options):
_filled_options = {}
arg_names = set(inspect.getfullargspec(ActorClassMetadata.__init__)[0])
arg_names = set(inspect.getfullargspec(_ActorClassMetadata.__init__)[0])
for k, v in ray_option_utils.actor_options.items():
if k in arg_names:
_filled_options[k] = actor_options.get(k, v.default_value)
@ -372,6 +373,7 @@ def _process_option_dict(actor_options):
return _filled_options
@PublicAPI
class ActorClass:
"""An actor class.
@ -479,7 +481,7 @@ class ActorClass:
modified_class.__ray_actor_class__
)
self.__ray_metadata__ = ActorClassMetadata(
self.__ray_metadata__ = _ActorClassMetadata(
Language.PYTHON,
modified_class,
actor_creation_function_descriptor,
@ -500,7 +502,7 @@ class ActorClass:
actor_options,
):
self = ActorClass.__new__(ActorClass)
self.__ray_metadata__ = ActorClassMetadata(
self.__ray_metadata__ = _ActorClassMetadata(
language,
None,
actor_creation_function_descriptor,
@ -718,7 +720,7 @@ class ActorClass:
max_task_retries = actor_options["max_task_retries"]
max_pending_calls = actor_options["max_pending_calls"]
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
# Check whether the name is already taken.
@ -806,7 +808,7 @@ class ActorClass:
actor_placement_resources = resources.copy()
actor_placement_resources["CPU"] += 1
if meta.is_cross_language:
creation_args = cross_language.format_args(worker, args, kwargs)
creation_args = cross_language._format_args(worker, args, kwargs)
else:
function_signature = meta.method_meta.signatures["__init__"]
creation_args = signature.flatten_args(function_signature, args, kwargs)
@ -831,7 +833,7 @@ class ActorClass:
placement_group_capture_child_tasks = (
worker.should_capture_child_tasks_in_placement_group
)
placement_group = configure_placement_group_based_on_context(
placement_group = _configure_placement_group_based_on_context(
placement_group_capture_child_tasks,
placement_group_bundle_index,
resources,
@ -883,7 +885,7 @@ class ActorClass:
if meta.language == Language.CPP:
func_name = meta.actor_creation_function_descriptor.function_name
meta.actor_creation_function_descriptor = (
cross_language.get_function_descriptor_for_actor_method(
cross_language._get_function_descriptor_for_actor_method(
meta.language,
meta.actor_creation_function_descriptor,
func_name,
@ -944,6 +946,7 @@ class ActorClass:
)
@PublicAPI
class ActorHandle:
"""A handle to an actor.
@ -1022,8 +1025,8 @@ class ActorHandle:
def __del__(self):
# Mark that this actor handle has gone out of scope. Once all actor
# handles are out of scope, the actor will exit.
if ray.worker:
worker = ray.worker.global_worker
if ray._private.worker:
worker = ray._private.worker.global_worker
if worker.connected and hasattr(worker, "core_worker"):
worker.core_worker.remove_actor_handle_reference(self._ray_actor_id)
@ -1054,13 +1057,13 @@ class ActorHandle:
object_refs: A list of object refs returned by the remote actor
method.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
args = args or []
kwargs = kwargs or {}
if self._ray_is_cross_language:
list_args = cross_language.format_args(worker, args, kwargs)
function_descriptor = cross_language.get_function_descriptor_for_actor_method( # noqa: E501
list_args = cross_language._format_args(worker, args, kwargs)
function_descriptor = cross_language._get_function_descriptor_for_actor_method( # noqa: E501
self._ray_actor_language,
self._ray_actor_creation_function_descriptor,
method_name,
@ -1154,7 +1157,7 @@ class ActorHandle:
Returns:
A dictionary of the information needed to reconstruct the object.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
if hasattr(worker, "core_worker"):
@ -1188,7 +1191,7 @@ class ActorHandle:
to the actor handle.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker.check_connected()
if hasattr(worker, "core_worker"):
@ -1217,7 +1220,7 @@ class ActorHandle:
return ActorHandle._deserialization_helper, state
def modify_class(cls):
def _modify_class(cls):
# cls has been modified.
if hasattr(cls, "__ray_actor_class__"):
return cls
@ -1236,7 +1239,7 @@ def modify_class(cls):
__ray_actor_class__ = cls # The original actor class
def __ray_terminate__(self):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
if worker.mode != ray.LOCAL_MODE:
ray.actor.exit_actor()
@ -1256,8 +1259,8 @@ def modify_class(cls):
return Class
def make_actor(cls, actor_options):
Class = modify_class(cls)
def _make_actor(cls, actor_options):
Class = _modify_class(cls)
_inject_tracing_into_class(Class)
if "max_restarts" in actor_options:
@ -1275,6 +1278,7 @@ def make_actor(cls, actor_options):
)
@PublicAPI
def exit_actor():
"""Intentionally exit the current actor.
@ -1285,13 +1289,13 @@ def exit_actor():
Exception: An exception is raised if this is a driver or this
worker is not an actor.
"""
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
if worker.mode == ray.WORKER_MODE and not worker.actor_id.is_nil():
# Intentionally disconnect the core worker from the raylet so the
# raylet won't push an error message to the driver.
ray.worker.disconnect()
ray._private.worker.disconnect()
# Disconnect global state from GCS.
ray.state.state.disconnect()
ray._private.state.state.disconnect()
# In asyncio actor mode, we can't raise SystemExit because it will just
# quit the asycnio event loop thread, not the main thread. Instead, we

View file

@ -1,14 +1,15 @@
#!/usr/bin/env python
import time
import numpy as np
from typing import Optional
import sys
import time
from typing import Optional
import numpy as np
import ray
from ray import train
from ray.data.preprocessors import Chain, BatchMapper
from ray.air.config import DatasetConfig
from ray.data.preprocessors import BatchMapper, Chain
from ray.train.data_parallel_trainer import DataParallelTrainer
from ray.util.annotations import DeveloperAPI
@ -150,7 +151,7 @@ if __name__ == "__main__":
try:
print(
"Memory stats at end of ingest:\n\n{}".format(
ray.internal.internal_api.memory_summary(stats_only=True)
ray._private.internal_api.memory_summary(stats_only=True)
)
)
except Exception:

View file

@ -6,7 +6,7 @@ import re
from kubernetes import client
from kubernetes.client.rest import ApiException
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
from ray.autoscaler._private._kubernetes import auth_api, core_api, log_prefix
logger = logging.getLogger(__name__)

View file

@ -8,7 +8,7 @@ from typing import Any, Dict, List
import botocore
from boto3.resources.base import ServiceResource
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
from ray.autoscaler._private.aws.cloudwatch.cloudwatch_helper import (
CLOUDWATCH_AGENT_INSTALLED_AMI_TAG,
CLOUDWATCH_AGENT_INSTALLED_TAG,

View file

@ -20,6 +20,7 @@ import yaml
import ray
import ray._private.services as services
from ray._private.usage import usage_lib
from ray._private.worker import global_worker # type: ignore
from ray.autoscaler._private import subprocess_output_util as cmd_output_util
from ray.autoscaler._private.autoscaler import AutoscalerSummary
from ray.autoscaler._private.cli_logger import cf, cli_logger
@ -70,7 +71,6 @@ from ray.autoscaler.tags import (
)
from ray.experimental.internal_kv import _internal_kv_put
from ray.util.debug import log_once
from ray.worker import global_worker # type: ignore
try: # py3
from shlex import quote

View file

@ -1,7 +1,7 @@
import os
import sys
from ray.ray_constants import ( # noqa F401
from ray._private.ray_constants import ( # noqa F401
AUTOSCALER_RESOURCE_REQUEST_CHANNEL,
DEFAULT_OBJECT_STORE_MAX_MEMORY_BYTES,
DEFAULT_OBJECT_STORE_MEMORY_PROPORTION,

View file

@ -12,6 +12,7 @@ from typing import Any, Dict, Optional
import yaml
import ray
from ray._private.ray_constants import DEFAULT_PORT
from ray.autoscaler._private.fake_multi_node.command_runner import (
FakeDockerCommandRunner,
)
@ -26,7 +27,6 @@ from ray.autoscaler.tags import (
TAG_RAY_NODE_STATUS,
TAG_RAY_USER_NODE_TYPE,
)
from ray.ray_constants import DEFAULT_PORT
logger = logging.getLogger(__name__)
@ -326,7 +326,7 @@ class FakeMultiNodeProvider(NodeProvider):
"RAY_OVERRIDE_RESOURCES": json.dumps(resources),
},
)
node = ray.node.Node(
node = ray._private.node.Node(
ray_params, head=False, shutdown_at_exit=False, spawn_reaper=False
)
self._nodes[next_id] = {

View file

@ -4,7 +4,7 @@ import subprocess
import time
import ray
from ray import ray_constants
from ray._private import ray_constants
from ray._private.ray_logging import setup_component_logger
from ray._private.services import get_node_ip_address
from ray.autoscaler._private.kuberay.autoscaling_config import AutoscalingConfigProducer
@ -56,7 +56,9 @@ def _setup_logging() -> None:
logging_level=ray_constants.LOGGER_LEVEL, # info
logging_format=ray_constants.LOGGER_FORMAT,
log_dir=os.path.join(
ray._private.utils.get_ray_temp_dir(), ray.node.SESSION_LATEST, "logs"
ray._private.utils.get_ray_temp_dir(),
ray._private.node.SESSION_LATEST,
"logs",
),
filename=ray_constants.MONITOR_LOG_FILE_NAME, # monitor.log
max_bytes=ray_constants.LOGGING_ROTATE_BYTES,

View file

@ -1,7 +1,7 @@
import logging
from ray._private.ray_constants import DEBUG_AUTOSCALING_STATUS_LEGACY
from ray.experimental.internal_kv import _internal_kv_initialized, _internal_kv_put
from ray.ray_constants import DEBUG_AUTOSCALING_STATUS_LEGACY
"""This file provides legacy support for the old info string in order to
ensure the dashboard's `api/cluster_status` does not break backwards

View file

@ -6,7 +6,7 @@ from typing import Dict, List
import numpy as np
import ray.ray_constants
import ray._private.ray_constants
from ray._private.gcs_utils import PlacementGroupTableData
from ray.autoscaler._private.constants import (
AUTOSCALER_MAX_RESOURCE_DEMAND_VECTOR_SIZE,
@ -282,11 +282,12 @@ class LoadMetrics:
for key in total_resources:
if key in ["memory", "object_store_memory"]:
total = (
total_resources[key] * ray.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
total_resources[key]
* ray._private.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
)
available = (
available_resources[key]
* ray.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
* ray._private.ray_constants.MEMORY_RESOURCE_UNIT_BYTES
)
usage_dict[key] = (total - available, total)
else:

View file

@ -13,8 +13,8 @@ from multiprocessing.synchronize import Event
from typing import Any, Callable, Dict, Optional, Union
import ray
import ray._private.ray_constants as ray_constants
import ray._private.utils
import ray.ray_constants as ray_constants
from ray._private.gcs_pubsub import GcsPublisher
from ray._private.gcs_utils import GcsClient
from ray._private.ray_logging import setup_component_logger
@ -155,7 +155,7 @@ class Monitor:
if redis_password is not None:
logger.warning("redis_password has been deprecated.")
# Set the redis client and mode so _internal_kv works for autoscaler.
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
gcs_client = GcsClient(address=gcs_address)
if monitor_ip:
@ -319,7 +319,9 @@ class Monitor:
"""Fetches resource requests from the internal KV and updates load."""
if not _internal_kv_initialized():
return
data = _internal_kv_get(ray.ray_constants.AUTOSCALER_RESOURCE_REQUEST_CHANNEL)
data = _internal_kv_get(
ray._private.ray_constants.AUTOSCALER_RESOURCE_REQUEST_CHANNEL
)
if data:
try:
resource_request = json.loads(data)

View file

@ -14,7 +14,7 @@ from typing import Dict, List, Optional, Tuple
import numpy as np
import ray.ray_constants as ray_constants
import ray._private.ray_constants as ray_constants
from ray._private.gcs_utils import PlacementGroupTableData
from ray.autoscaler._private.constants import AUTOSCALER_CONSERVE_GPU_NODES
from ray.autoscaler._private.util import (

View file

@ -12,8 +12,8 @@ from numbers import Number, Real
from typing import Any, Dict, List, Optional, Tuple, Union
import ray
import ray._private.ray_constants
import ray._private.services as services
import ray.ray_constants
from ray.autoscaler._private import constants
from ray.autoscaler._private.cli_logger import cli_logger
from ray.autoscaler._private.docker import validate_docker_config

View file

@ -1,6 +1,9 @@
from typing import Any, Dict, List, Optional, Tuple
from ray.util.annotations import DeveloperAPI
@DeveloperAPI
class CommandRunnerInterface:
"""Interface to run commands on a remote cluster node.

View file

@ -4,10 +4,12 @@ from typing import Any, Dict, List, Optional
from ray.autoscaler._private.command_runner import DockerCommandRunner, SSHCommandRunner
from ray.autoscaler.command_runner import CommandRunnerInterface
from ray.util.annotations import DeveloperAPI
logger = logging.getLogger(__name__)
@DeveloperAPI
class NodeProvider:
"""Interface for getting and returning nodes from a Cloud.

View file

@ -10,8 +10,10 @@ from ray.autoscaler._private import commands
from ray.autoscaler._private.cli_logger import cli_logger
from ray.autoscaler._private.event_system import CreateClusterEvent # noqa: F401
from ray.autoscaler._private.event_system import global_event_system # noqa: F401
from ray.util.annotations import DeveloperAPI
@DeveloperAPI
def create_or_update_cluster(
cluster_config: Union[dict, str],
*,
@ -47,6 +49,7 @@ def create_or_update_cluster(
)
@DeveloperAPI
def teardown_cluster(
cluster_config: Union[dict, str],
workers_only: bool = False,
@ -72,6 +75,7 @@ def teardown_cluster(
)
@DeveloperAPI
def run_on_cluster(
cluster_config: Union[dict, str],
*,
@ -117,6 +121,7 @@ def run_on_cluster(
)
@DeveloperAPI
def rsync(
cluster_config: Union[dict, str],
*,
@ -161,6 +166,7 @@ def rsync(
)
@DeveloperAPI
def get_head_node_ip(cluster_config: Union[dict, str]) -> str:
"""Returns head node IP for given configuration file if exists.
@ -178,6 +184,7 @@ def get_head_node_ip(cluster_config: Union[dict, str]) -> str:
return commands.get_head_node_ip(config_file)
@DeveloperAPI
def get_worker_node_ips(cluster_config: Union[dict, str]) -> List[str]:
"""Returns worker node IPs for given configuration file.
@ -195,6 +202,7 @@ def get_worker_node_ips(cluster_config: Union[dict, str]) -> List[str]:
return commands.get_worker_node_ips(config_file)
@DeveloperAPI
def request_resources(
num_cpus: Optional[int] = None, bundles: Optional[List[dict]] = None
) -> None:
@ -235,6 +243,7 @@ def request_resources(
return commands.request_resources(num_cpus, bundles)
@DeveloperAPI
def configure_logging(
log_style: Optional[str] = None,
color_mode: Optional[str] = None,
@ -265,6 +274,7 @@ def configure_logging(
@contextmanager
@DeveloperAPI
def _as_config_file(cluster_config: Union[dict, str]) -> Iterator[str]:
if isinstance(cluster_config, dict):
tmp = tempfile.NamedTemporaryFile("w", prefix="autoscaler-sdk-tmp-")
@ -276,6 +286,7 @@ def _as_config_file(cluster_config: Union[dict, str]) -> Iterator[str]:
yield cluster_config
@DeveloperAPI
def bootstrap_config(
cluster_config: Dict[str, Any], no_config_cache: bool = False
) -> Dict[str, Any]:
@ -284,6 +295,7 @@ def bootstrap_config(
return commands._bootstrap_config(cluster_config, no_config_cache)
@DeveloperAPI
def fillout_defaults(config: Dict[str, Any]) -> Dict[str, Any]:
"""Fillout default values for a cluster_config based on the provider."""
from ray.autoscaler._private.util import fillout_defaults
@ -291,6 +303,7 @@ def fillout_defaults(config: Dict[str, Any]) -> Dict[str, Any]:
return fillout_defaults(config)
@DeveloperAPI
def register_callback_handler(
event_name: str,
callback: Union[Callable[[Dict], None], List[Callable[[Dict], None]]],
@ -307,6 +320,7 @@ def register_callback_handler(
global_event_system.add_callback_handler(event_name, callback)
@DeveloperAPI
def get_docker_host_mount_location(cluster_name: str) -> str:
"""Return host path that Docker mounts attach to."""
docker_mount_prefix = "/tmp/ray_tmp_mount/{cluster_name}"

View file

@ -1,23 +1,23 @@
import os
import importlib
import inspect
import json
import logging
import os
import sys
import warnings
from dataclasses import dataclass
import sys
from typing import Any, Dict, Optional, Tuple
from ray.ray_constants import (
import ray.util.client_connect
from ray._private.ray_constants import (
RAY_ADDRESS_ENVIRONMENT_VARIABLE,
RAY_NAMESPACE_ENVIRONMENT_VARIABLE,
RAY_RUNTIME_ENV_ENVIRONMENT_VARIABLE,
)
from ray._private.worker import BaseContext
from ray._private.worker import init as ray_driver_init
from ray.job_config import JobConfig
import ray.util.client_connect
from ray.worker import init as ray_driver_init, BaseContext
from ray.util.annotations import Deprecated
from ray.util.annotations import Deprecated, PublicAPI
logger = logging.getLogger(__name__)
@ -25,6 +25,7 @@ CLIENT_DOCS_URL = "https://docs.ray.io/en/latest/cluster/ray-client.html"
@dataclass
@PublicAPI
class ClientContext(BaseContext):
"""
Basic context manager for a ClientBuilder connection.
@ -67,10 +68,10 @@ class ClientContext(BaseContext):
if ray.util.client.ray.is_default() or force_disconnect:
# This is the only client connection
ray.util.client_connect.disconnect()
elif ray.worker.global_worker.node is None:
elif ray._private.worker.global_worker.node is None:
# Already disconnected.
return
elif ray.worker.global_worker.node.is_head():
elif ray._private.worker.global_worker.node.is_head():
logger.debug(
"The current Ray Cluster is scoped to this process. "
"Disconnecting is not possible as it will shutdown the "
@ -81,6 +82,7 @@ class ClientContext(BaseContext):
ray.shutdown()
@Deprecated
class ClientBuilder:
"""
Builder for a Ray Client connection. This class can be subclassed by
@ -163,7 +165,7 @@ class ClientBuilder:
_credentials=self._credentials,
ray_init_kwargs=self._remote_init_kwargs,
)
get_dashboard_url = ray.remote(ray.worker.get_dashboard_url)
get_dashboard_url = ray.remote(ray._private.worker.get_dashboard_url)
dashboard_url = ray.get(get_dashboard_url.options(num_cpus=0).remote())
cxt = ClientContext(
dashboard_url=dashboard_url,

View file

@ -1,23 +1,26 @@
import copy
import logging
import json
import yaml
import logging
import os
import subprocess
import tempfile
import time
import yaml
import ray
import ray._private.services
from ray._private import ray_constants
from ray._private.client_mode_hook import disable_client_hook
from ray import ray_constants
from ray._raylet import GcsClientOptions
from ray.util.annotations import DeveloperAPI
logger = logging.getLogger(__name__)
cluster_not_supported = os.name == "nt"
@DeveloperAPI
class AutoscalingCluster:
"""Create a local autoscaling cluster for testing.
@ -92,6 +95,7 @@ class AutoscalingCluster:
subprocess.check_call(["ray", "stop", "--force"])
@DeveloperAPI
class Cluster:
def __init__(
self,
@ -124,7 +128,7 @@ class Cluster:
self.redis_address = None
self.connected = False
# Create a new global state accessor for fetching GCS table.
self.global_state = ray.state.GlobalState()
self.global_state = ray._private.state.GlobalState()
self._shutdown_at_exit = shutdown_at_exit
if not initialize_head and connect:
raise RuntimeError("Cannot connect to uninitialized cluster.")
@ -186,7 +190,7 @@ class Cluster:
ray_params.update_if_absent(**default_kwargs)
with disable_client_hook():
if self.head_node is None:
node = ray.node.Node(
node = ray._private.node.Node(
ray_params,
head=True,
shutdown_at_exit=self._shutdown_at_exit,
@ -209,7 +213,7 @@ class Cluster:
# Let grpc pick a port.
ray_params.update_if_absent(node_manager_port=0)
node = ray.node.Node(
node = ray._private.node.Node(
ray_params,
head=False,
shutdown_at_exit=self._shutdown_at_exit,
@ -234,7 +238,7 @@ class Cluster:
node: Worker node of which all associated processes
will be removed.
"""
global_node = ray.worker._global_node
global_node = ray._private.worker._global_node
if global_node is not None:
if node._raylet_socket_name == global_node._raylet_socket_name:
ray.shutdown()
@ -269,7 +273,7 @@ class Cluster:
"""Wait until this node has appeared in the client table.
Args:
node (ray.node.Node): The node to wait for.
node (ray._private.node.Node): The node to wait for.
timeout: The amount of time in seconds to wait before raising an
exception.

View file

@ -1,11 +1,8 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import, division, print_function
from ray import Language
from ray._raylet import CppFunctionDescriptor, JavaFunctionDescriptor
from ray.util.annotations import PublicAPI
from ray._raylet import JavaFunctionDescriptor
from ray._raylet import CppFunctionDescriptor
__all__ = [
"java_function",
@ -14,60 +11,6 @@ __all__ = [
]
def format_args(worker, args, kwargs):
"""Format args for various languages.
Args:
worker: The global worker instance.
args: The arguments for cross language.
kwargs: The keyword arguments for cross language.
Returns:
List of args and kwargs (if supported).
"""
if not worker.load_code_from_local:
raise ValueError(
"Cross language feature needs --load-code-from-local to be set."
)
if kwargs:
raise TypeError("Cross language remote functions does not support kwargs.")
return args
def get_function_descriptor_for_actor_method(
language: str, actor_creation_function_descriptor, method_name: str, signature: str
):
"""Get function descriptor for cross language actor method call.
Args:
language: Target language.
actor_creation_function_descriptor:
The function signature for actor creation.
method_name: The name of actor method.
signature: The signature for the actor method. When calling Java from Python,
it should be string in the form of "{length_of_args}".
Returns:
Function descriptor for cross language actor method call.
"""
if language == Language.JAVA:
return JavaFunctionDescriptor(
actor_creation_function_descriptor.class_name,
method_name,
signature,
)
elif language == Language.CPP:
return CppFunctionDescriptor(
method_name,
"PYTHON",
actor_creation_function_descriptor.class_name,
)
else:
raise NotImplementedError(
"Cross language remote actor method " f"not support language {language}"
)
@PublicAPI(stability="beta")
def java_function(class_name: str, function_name: str):
"""Define a Java function.
@ -135,3 +78,57 @@ def cpp_actor_class(create_function_name: str, class_name: str):
CppFunctionDescriptor(create_function_name, "PYTHON", class_name),
{},
)
def _format_args(worker, args, kwargs):
"""Format args for various languages.
Args:
worker: The global worker instance.
args: The arguments for cross language.
kwargs: The keyword arguments for cross language.
Returns:
List of args and kwargs (if supported).
"""
if not worker.load_code_from_local:
raise ValueError(
"Cross language feature needs --load-code-from-local to be set."
)
if kwargs:
raise TypeError("Cross language remote functions does not support kwargs.")
return args
def _get_function_descriptor_for_actor_method(
language: str, actor_creation_function_descriptor, method_name: str, signature: str
):
"""Get function descriptor for cross language actor method call.
Args:
language: Target language.
actor_creation_function_descriptor:
The function signature for actor creation.
method_name: The name of actor method.
signature: The signature for the actor method. When calling Java from Python,
it should be string in the form of "{length_of_args}".
Returns:
Function descriptor for cross language actor method call.
"""
if language == Language.JAVA:
return JavaFunctionDescriptor(
actor_creation_function_descriptor.class_name,
method_name,
signature,
)
elif language == Language.CPP:
return CppFunctionDescriptor(
method_name,
"PYTHON",
actor_creation_function_descriptor.class_name,
)
else:
raise NotImplementedError(
"Cross language remote actor method " f"not support language {language}"
)

View file

@ -7,10 +7,12 @@ from ray.dag.constants import (
PREV_CLASS_METHOD_CALL_KEY,
DAGNODE_TYPE_KEY,
)
from ray.util.annotations import DeveloperAPI
from typing import Any, Dict, List, Optional, Tuple
@DeveloperAPI
class ClassNode(DAGNode):
"""Represents an actor creation in a Ray task DAG."""
@ -157,6 +159,7 @@ class _UnboundClassMethodNode(object):
return self
@DeveloperAPI
class ClassMethodNode(DAGNode):
"""Represents an actor method invocation in a Ray function DAG."""

View file

@ -1,5 +1,6 @@
import ray
from ray.dag.py_obj_scanner import _PyObjScanner
from ray.util.annotations import DeveloperAPI
from typing import (
Optional,
@ -16,6 +17,7 @@ import uuid
T = TypeVar("T")
@DeveloperAPI
class DAGNode:
"""Abstract class for a node in a Ray task graph.

View file

@ -1,15 +1,36 @@
from ray.dag import DAGNode
from ray.util.annotations import DeveloperAPI
def get_indentation(num_spaces=4):
@DeveloperAPI
def get_dag_node_str(
dag_node: DAGNode,
body_line,
):
indent = _get_indentation()
other_args_to_resolve_lines = _get_other_args_to_resolve_lines(
dag_node._bound_other_args_to_resolve
)
return (
f"({dag_node.__class__.__name__})(\n"
f"{indent}body={body_line}\n"
f"{indent}args={_get_args_lines(dag_node._bound_args)}\n"
f"{indent}kwargs={_get_kwargs_lines(dag_node._bound_kwargs)}\n"
f"{indent}options={_get_options_lines(dag_node._bound_options)}\n"
f"{indent}other_args_to_resolve={other_args_to_resolve_lines}\n"
f")"
)
def _get_indentation(num_spaces=4):
return " " * num_spaces
def get_args_lines(bound_args):
def _get_args_lines(bound_args):
"""Pretty prints bounded args of a DAGNode, and recursively handle
DAGNode in list / dict containers.
"""
indent = get_indentation()
indent = _get_indentation()
lines = []
for arg in bound_args:
if isinstance(arg, DAGNode):
@ -41,14 +62,14 @@ def get_args_lines(bound_args):
return args_line
def get_kwargs_lines(bound_kwargs):
def _get_kwargs_lines(bound_kwargs):
"""Pretty prints bounded kwargs of a DAGNode, and recursively handle
DAGNode in list / dict containers.
"""
# TODO: (jiaodong) Nits, we're missing keys and indentation was a bit off.
if not bound_kwargs:
return "{}"
indent = get_indentation()
indent = _get_indentation()
kwargs_lines = []
for key, val in bound_kwargs.items():
if isinstance(val, DAGNode):
@ -86,11 +107,11 @@ def get_kwargs_lines(bound_kwargs):
return kwargs_line
def get_options_lines(bound_options):
def _get_options_lines(bound_options):
"""Pretty prints .options() in DAGNode. Only prints non-empty values."""
if not bound_options:
return "{}"
indent = get_indentation()
indent = _get_indentation()
options_lines = []
for key, val in bound_options.items():
if val:
@ -103,10 +124,10 @@ def get_options_lines(bound_options):
return options_line
def get_other_args_to_resolve_lines(other_args_to_resolve):
def _get_other_args_to_resolve_lines(other_args_to_resolve):
if not other_args_to_resolve:
return "{}"
indent = get_indentation()
indent = _get_indentation()
other_args_to_resolve_lines = []
for key, val in other_args_to_resolve.items():
if isinstance(val, DAGNode):
@ -132,22 +153,3 @@ def get_other_args_to_resolve_lines(other_args_to_resolve):
other_args_to_resolve_line += f"\n{indent}{line}"
other_args_to_resolve_line += f"\n{indent}}}"
return other_args_to_resolve_line
def get_dag_node_str(
dag_node: DAGNode,
body_line,
):
indent = get_indentation()
other_args_to_resolve_lines = get_other_args_to_resolve_lines(
dag_node._bound_other_args_to_resolve
)
return (
f"({dag_node.__class__.__name__})(\n"
f"{indent}body={body_line}\n"
f"{indent}args={get_args_lines(dag_node._bound_args)}\n"
f"{indent}kwargs={get_kwargs_lines(dag_node._bound_kwargs)}\n"
f"{indent}options={get_options_lines(dag_node._bound_options)}\n"
f"{indent}other_args_to_resolve={other_args_to_resolve_lines}\n"
f")"
)

View file

@ -5,8 +5,10 @@ import ray
from ray.dag.dag_node import DAGNode
from ray.dag.format_utils import get_dag_node_str
from ray.dag.constants import DAGNODE_TYPE_KEY
from ray.util.annotations import DeveloperAPI
@DeveloperAPI
class FunctionNode(DAGNode):
"""Represents a bound task node in a Ray task DAG."""

View file

@ -3,10 +3,12 @@ from typing import Any, Dict, List, Union
from ray.dag import DAGNode
from ray.dag.format_utils import get_dag_node_str
from ray.dag.constants import DAGNODE_TYPE_KEY
from ray.util.annotations import DeveloperAPI
IN_CONTEXT_MANAGER = "__in_context_manager__"
@DeveloperAPI
class InputNode(DAGNode):
"""Ray dag node used in DAG building API to mark entrypoints of a DAG.
@ -146,6 +148,7 @@ class InputNode(DAGNode):
return node
@DeveloperAPI
class InputAttributeNode(DAGNode):
"""Represents partial access of user input based on an index (int),
object attribute or dict key (str).
@ -252,6 +255,7 @@ class InputAttributeNode(DAGNode):
return node
@DeveloperAPI
class DAGInputData:
"""If user passed multiple args and kwargs directly to dag.execute(), we
generate this wrapper for all user inputs as one object, accessible via

View file

@ -24,7 +24,7 @@ def test_basic_dag_with_names_plot():
ray.dag.plot(dag, to_file)
assert os.path.isfile(to_file)
graph = ray.dag.vis_utils.dag_to_dot(dag)
graph = ray.dag.vis_utils._dag_to_dot(dag)
to_string = graph.to_string()
assert "tmp1 -> tmp3" in to_string
assert "tmp2 -> tmp3" in to_string
@ -52,7 +52,7 @@ def test_basic_dag_without_names_plot():
ray.dag.plot(dag, to_file)
assert os.path.isfile(to_file)
graph = ray.dag.vis_utils.dag_to_dot(dag)
graph = ray.dag.vis_utils._dag_to_dot(dag)
to_string = graph.to_string()
assert "a_5 -> a_4" in to_string
assert "a_2 -> a_1" in to_string

View file

@ -10,7 +10,7 @@ from ray.dag import (
)
class DAGNodeNameGenerator(object):
class _DAGNodeNameGenerator(object):
"""
Generate unique suffix for each given Node in the DAG.
Apply monotonic increasing id suffix for duplicated names.

View file

@ -3,10 +3,42 @@ from ray.dag import DAGNode
import os
import tempfile
from ray.dag.utils import DAGNodeNameGenerator
from ray.dag.utils import _DAGNodeNameGenerator
from ray.util.annotations import DeveloperAPI
def check_pydot_and_graphviz():
@DeveloperAPI
def plot(dag: DAGNode, to_file=None):
if to_file is None:
tmp_file = tempfile.NamedTemporaryFile(suffix=".png")
to_file = tmp_file.name
extension = "png"
else:
_, extension = os.path.splitext(to_file)
if not extension:
extension = "png"
else:
extension = extension[1:]
graph = _dag_to_dot(dag)
graph.write(to_file, format=extension)
# Render the image directly if running inside a Jupyter notebook
try:
from IPython import display
return display.Image(filename=to_file)
except ImportError:
pass
# close temp file if needed
try:
tmp_file.close()
except NameError:
pass
def _check_pydot_and_graphviz():
"""Check if pydot and graphviz are installed.
pydot and graphviz are required for plotting. We check this
@ -28,7 +60,7 @@ def check_pydot_and_graphviz():
)
def get_nodes_and_edges(dag: DAGNode):
def _get_nodes_and_edges(dag: DAGNode):
"""Get all unique nodes and edges in the DAG.
A basic dfs with memorization to get all unique nodes
@ -50,7 +82,7 @@ def get_nodes_and_edges(dag: DAGNode):
return nodes, edges
def dag_to_dot(dag: DAGNode):
def _dag_to_dot(dag: DAGNode):
"""Create a Dot graph from dag.
TODO(lchu):
@ -61,14 +93,14 @@ def dag_to_dot(dag: DAGNode):
"""
# Step 0: check dependencies and init graph
check_pydot_and_graphviz()
_check_pydot_and_graphviz()
import pydot
graph = pydot.Dot(rankdir="LR")
# Step 1: generate unique name for each node in dag
nodes, edges = get_nodes_and_edges(dag)
name_generator = DAGNodeNameGenerator()
nodes, edges = _get_nodes_and_edges(dag)
name_generator = _DAGNodeNameGenerator()
node_names = {}
for node in nodes:
node_names[node] = name_generator.get_node_name(node)
@ -81,33 +113,3 @@ def dag_to_dot(dag: DAGNode):
graph.add_node(pydot.Node(node_names[nodes[0]]))
return graph
def plot(dag: DAGNode, to_file=None):
if to_file is None:
tmp_file = tempfile.NamedTemporaryFile(suffix=".png")
to_file = tmp_file.name
extension = "png"
else:
_, extension = os.path.splitext(to_file)
if not extension:
extension = "png"
else:
extension = extension[1:]
graph = dag_to_dot(dag)
graph.write(to_file, format=extension)
# Render the image directly if running inside a Jupyter notebook
try:
from IPython import display
return display.Image(filename=to_file)
except ImportError:
pass
# close temp file if needed
try:
tmp_file.close()
except NameError:
pass

View file

@ -44,7 +44,8 @@ _cached_cls = None
if ray.is_initialized():
_register_arrow_json_readoptions_serializer()
else:
ray.worker._post_init_hooks.append(_register_arrow_json_readoptions_serializer)
pass
# ray._internal.worker._post_init_hooks.append(_register_arrow_json_readoptions_serializer)
__all__ = [
"ActorPoolStrategy",

View file

@ -1,6 +1,6 @@
import collections
import itertools
from typing import TYPE_CHECKING, Dict, Iterable, Iterator, Optional, Union
from typing import TYPE_CHECKING, Iterable, Iterator, Optional, Union, Dict
import numpy as np
@ -155,7 +155,7 @@ def _sliding_window(iterable: Iterable, n: int, clear_block_after_read: bool = F
for elem in it:
block_ref = window.popleft()
if clear_block_after_read:
ray.internal.internal_api.free(block_ref, local_only=False)
ray._private.internal_api.free(block_ref, local_only=False)
window.append(elem)
yield tuple(window)

View file

@ -1,8 +1,8 @@
from typing import List, Any
import threading
from typing import Any, List
import ray
from ray.ray_constants import env_integer
from ray._private.ray_constants import env_integer
from ray.types import ObjectRef
from ray.util.annotations import PublicAPI

View file

@ -44,7 +44,7 @@ class SizeEstimator:
_ray_initialized = True
ray.put(None)
return (
ray.worker.global_worker.get_serialization_context()
ray._private.worker.global_worker.get_serialization_context()
.serialize(item)
.total_bytes
)

View file

@ -134,7 +134,7 @@ def _get_or_create_stats_actor():
def clear_actor():
_stats_actor[0] = None
ray.worker._post_init_hooks.append(clear_actor)
ray._private.worker._post_init_hooks.append(clear_actor)
return _stats_actor[0]

View file

@ -129,7 +129,7 @@ class DatasetContext:
if _default_context:
_default_context.block_owner = None
ray.worker._post_init_hooks.append(clear_owner)
ray._private.worker._post_init_hooks.append(clear_owner)
_default_context.block_owner = owner
return _default_context

View file

@ -1029,7 +1029,7 @@ class Dataset(Generic[T]):
def build_node_id_by_actor(actors: List[Any]) -> Dict[Any, str]:
"""Build a map from a actor to its node_id."""
actors_state = ray.state.actors()
actors_state = ray._private.state.actors()
return {
actor: actors_state.get(actor._actor_id.hex(), {})
.get("Address", {})
@ -3209,7 +3209,7 @@ class Dataset(Generic[T]):
state["_last_export_session_and_job"] = None
return reconstructor, args, state
context = ray.worker.global_worker.get_serialization_context()
context = ray._private.worker.global_worker.get_serialization_context()
try:
context._register_cloudpickle_reducer(
ray.remote_function.RemoteFunction, _reduce

View file

@ -3,10 +3,9 @@ import time
import pytest
import ray
from ray._private.internal_api import memory_summary
from ray.tests.conftest import * # noqa
from ray.internal.internal_api import memory_summary
def check_no_spill(ctx, pipe, prefetch_blocks: int = 0):
# Run .iter_batches() for 10 secs, and we expect no object spilling.

View file

@ -1,16 +1,16 @@
import pytest
import numpy as np
import pandas as pd
import os
from typing import List
import numpy as np
import pandas as pd
import pytest
import ray
from ray._private.internal_api import memory_summary
from ray.data.block import BlockMetadata
from ray.data.context import DatasetContext
from ray.data.datasource import Datasource, ReadTask
from ray.data.datasource.csv_datasource import CSVDatasource
from ray.internal.internal_api import memory_summary
from ray.tests.conftest import * # noqa

View file

@ -1,20 +1,19 @@
import math
import random
import time
from unittest.mock import patch
import numpy as np
import pytest
import ray
from ray.tests.conftest import * # noqa
from ray.data.dataset import Dataset
from ray.data.block import BlockAccessor
from ray.data._internal.block_list import BlockList
from ray.data._internal.stats import DatasetStats
from ray.data._internal.plan import ExecutionPlan
from ray.data._internal.stats import DatasetStats
from ray.data.block import BlockAccessor
from ray.data.dataset import Dataset
from ray.data.tests.conftest import * # noqa
from ray.tests.conftest import * # noqa
@ray.remote
@ -324,7 +323,7 @@ def test_split_hints(ray_start_regular_shared):
assert len(block_node_ids) == len(blocks)
actors = [Actor.remote() for i in range(len(actor_node_ids))]
with patch("ray.experimental.get_object_locations") as location_mock:
with patch("ray.state.actors") as state_mock:
with patch("ray._private.state.actors") as state_mock:
block_locations = {}
for i, node_id in enumerate(block_node_ids):
if node_id:

View file

@ -1,17 +1,24 @@
import os
from traceback import format_exception
from typing import Optional, Union
from typing import Union, Optional
import ray.cloudpickle as pickle
from ray.core.generated.common_pb2 import RayException, Language, PYTHON
from ray.core.generated.common_pb2 import Address, ActorDiedErrorContext
import ray.ray_constants as ray_constants
from ray._raylet import WorkerID, ActorID, TaskID
import colorama
import setproctitle
import ray._private.ray_constants as ray_constants
import ray.cloudpickle as pickle
from ray._raylet import ActorID, TaskID, WorkerID
from ray.core.generated.common_pb2 import (
PYTHON,
ActorDiedErrorContext,
Address,
Language,
RayException,
)
from ray.util.annotations import DeveloperAPI, PublicAPI
@PublicAPI
class RayError(Exception):
"""Super class of all ray exception types."""
@ -43,6 +50,7 @@ class RayError(Exception):
return CrossLanguageError(ray_exception)
@PublicAPI
class CrossLanguageError(RayError):
"""Raised from another language."""
@ -55,6 +63,7 @@ class CrossLanguageError(RayError):
)
@PublicAPI
class TaskCancelledError(RayError):
"""Raised when this task is cancelled.
@ -72,6 +81,7 @@ class TaskCancelledError(RayError):
return "Task: " + str(self.task_id) + " was cancelled"
@PublicAPI
class RayTaskError(RayError):
"""Indicates that a task threw an exception during execution.
@ -213,6 +223,7 @@ class RayTaskError(RayError):
return "\n".join(out)
@PublicAPI
class LocalRayletDiedError(RayError):
"""Indicates that the task's local raylet died."""
@ -220,6 +231,7 @@ class LocalRayletDiedError(RayError):
return "The task's local raylet died. Check raylet.out for more information."
@PublicAPI
class WorkerCrashedError(RayError):
"""Indicates that the worker died unexpectedly while executing a task."""
@ -230,6 +242,7 @@ class WorkerCrashedError(RayError):
)
@PublicAPI
class RayActorError(RayError):
"""Indicates that the actor died unexpectedly before finishing a task.
@ -293,6 +306,7 @@ class RayActorError(RayError):
return RayActorError(task_error)
@PublicAPI
class RaySystemError(RayError):
"""Indicates that Ray encountered a system error.
@ -310,6 +324,7 @@ class RaySystemError(RayError):
return error_msg
@PublicAPI
class ObjectStoreFullError(RayError):
"""Indicates that the object store is full.
@ -326,6 +341,7 @@ class ObjectStoreFullError(RayError):
)
@PublicAPI
class ObjectLostError(RayError):
"""Indicates that the object is lost from distributed memory, due to
node failure or system error.
@ -366,6 +382,7 @@ class ObjectLostError(RayError):
)
@PublicAPI
class ObjectFetchTimedOutError(ObjectLostError):
"""Indicates that an object fetch timed out.
@ -385,6 +402,7 @@ class ObjectFetchTimedOutError(ObjectLostError):
)
@DeveloperAPI
class ReferenceCountingAssertionError(ObjectLostError, AssertionError):
"""Indicates that an object has been deleted while there was still a
reference to it.
@ -404,6 +422,7 @@ class ReferenceCountingAssertionError(ObjectLostError, AssertionError):
)
@PublicAPI
class OwnerDiedError(ObjectLostError):
"""Indicates that the owner of the object has died while there is still a
reference to the object.
@ -442,6 +461,7 @@ class OwnerDiedError(ObjectLostError):
)
@PublicAPI
class ObjectReconstructionFailedError(ObjectLostError):
"""Indicates that the object cannot be reconstructed.
@ -461,6 +481,7 @@ class ObjectReconstructionFailedError(ObjectLostError):
)
@PublicAPI
class ObjectReconstructionFailedMaxAttemptsExceededError(ObjectLostError):
"""Indicates that the object cannot be reconstructed because the maximum
number of task retries has been exceeded.
@ -482,6 +503,7 @@ class ObjectReconstructionFailedMaxAttemptsExceededError(ObjectLostError):
)
@PublicAPI
class ObjectReconstructionFailedLineageEvictedError(ObjectLostError):
"""Indicates that the object cannot be reconstructed because its lineage
was evicted due to memory pressure.
@ -503,24 +525,28 @@ class ObjectReconstructionFailedLineageEvictedError(ObjectLostError):
)
@PublicAPI
class GetTimeoutError(RayError):
"""Indicates that a call to the worker timed out."""
pass
@PublicAPI
class PlasmaObjectNotAvailable(RayError):
"""Called when an object was not available within the given timeout."""
pass
@PublicAPI
class AsyncioActorExit(RayError):
"""Raised when an asyncio actor intentionally exits via exit_actor()."""
pass
@PublicAPI
class RuntimeEnvSetupError(RayError):
"""Raised when a runtime environment fails to be set up.
@ -539,6 +565,7 @@ class RuntimeEnvSetupError(RayError):
return "\n".join(msgs)
@PublicAPI
class TaskPlacementGroupRemoved(RayError):
"""Raised when the corresponding placement group was removed."""
@ -546,6 +573,7 @@ class TaskPlacementGroupRemoved(RayError):
return "The placement group corresponding to this task has been removed."
@PublicAPI
class ActorPlacementGroupRemoved(RayError):
"""Raised when the corresponding placement group was removed."""
@ -553,6 +581,7 @@ class ActorPlacementGroupRemoved(RayError):
return "The placement group corresponding to this Actor has been removed."
@PublicAPI
class PendingCallsLimitExceeded(RayError):
"""Raised when the pending actor calls exceeds `max_pending_calls` option.
@ -563,6 +592,7 @@ class PendingCallsLimitExceeded(RayError):
pass
@PublicAPI
class TaskUnschedulableError(RayError):
"""Raised when the task cannot be scheduled.
@ -577,6 +607,7 @@ class TaskUnschedulableError(RayError):
return f"The task is not schedulable: {self.error_message}"
@PublicAPI
class ActorUnschedulableError(RayError):
"""Raised when the actor cannot be scheduled.

View file

@ -15,12 +15,12 @@ class StepActor:
self.current_step = 1
self.total_steps = total_steps
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker_id = worker.core_worker.get_actor_id()
ray_kv._internal_kv_put(f"JOB:{worker_id}", self.current_step, overwrite=True)
def run(self):
worker = ray.worker.global_worker
worker = ray._private.worker.global_worker
worker_id = worker.core_worker.get_actor_id()
while self.current_step <= self.total_steps:

Some files were not shown because too many files have changed in this diff Show more