diff --git a/api/cpp/include/yr/api/runtime.h b/api/cpp/include/yr/api/runtime.h index e2a69ab14ecceb1f5ddbf4de3ae8cf546cf9fa14..f149c1da8544a035612e350b821d75b3f925b17d 100644 --- a/api/cpp/include/yr/api/runtime.h +++ b/api/cpp/include/yr/api/runtime.h @@ -261,15 +261,6 @@ struct GetParams { * @brief Configure attributes for the object, such as whether reliability is needed. */ struct CreateParam { - /** - * @brief write mode - * @details Set the reliability of the data. - * When the server configuration supports a secondary cache to ensure reliability, - * such as the Redis service, this configuration can be used to guarantee data reliability. - * Defaults to YR::WriteMode::NONE_L2_CACHE . - */ - WriteMode writeMode = WriteMode::NONE_L2_CACHE; - /** * @brief consistency type * @details Data consistency configuration. In a distributed scenario, diff --git a/api/cpp/src/cluster_mode_runtime.cpp b/api/cpp/src/cluster_mode_runtime.cpp index 8c55ec3d67d04d27f121873419a389786ec6d08e..cc87422bba56909eddb0e96d85ef151db8d97a46 100644 --- a/api/cpp/src/cluster_mode_runtime.cpp +++ b/api/cpp/src/cluster_mode_runtime.cpp @@ -224,7 +224,6 @@ YR::Libruntime::GetParams BuildGetParam(const YR::GetParams ¶ms) YR::Libruntime::CreateParam BuildCreateParam(const YR::CreateParam &createParam) { YR::Libruntime::CreateParam dsCreateParam; - dsCreateParam.writeMode = static_cast(createParam.writeMode); dsCreateParam.consistencyType = static_cast(createParam.consistencyType); dsCreateParam.cacheType = static_cast(createParam.cacheType); return dsCreateParam; diff --git a/api/go/libruntime/cpplibruntime/cpplibruntime.cpp b/api/go/libruntime/cpplibruntime/cpplibruntime.cpp index 9fc9da9a73cbdc498a88e4a2f8faec483b67daa9..4d140b355566705b48c3a458d2e1501171f2a79d 100644 --- a/api/go/libruntime/cpplibruntime/cpplibruntime.cpp +++ b/api/go/libruntime/cpplibruntime/cpplibruntime.cpp @@ -214,7 +214,6 @@ MSetParam CMSetParamToMSetParam(CMSetParam param) CreateParam CCreateParamToCreateParam(CCreateParam param) { CreateParam createParam; - createParam.writeMode = static_cast(param.writeMode); createParam.consistencyType = static_cast(param.consistencyType); createParam.cacheType = static_cast(param.cacheType); return createParam; diff --git a/api/python/BUILD.bazel b/api/python/BUILD.bazel index a0a56d77db55ad04d5eb44208a9fd11048041965..07cf960fee0654dfea866dceb43721f2338b75aa 100644 --- a/api/python/BUILD.bazel +++ b/api/python/BUILD.bazel @@ -40,10 +40,10 @@ platform( pyx_library( name = "fnruntime", srcs = glob([ - "yr/__init__.py", - "yr/fnruntime.pyx", - "yr/includes/*.pxd", - "yr/includes/*.pxi", + "yuanrong/__init__.py", + "yuanrong/fnruntime.pyx", + "yuanrong/includes/*.pxd", + "yuanrong/includes/*.pxi", ]), cc_kwargs = dict( copts = COPTS, @@ -83,13 +83,13 @@ copy_file( filegroup( name = "python_sources", srcs = glob([ - "yr/**/*.py", + "yuanrong/**/*.py", ]), ) cc_strip( name = "py_strip", - srcs = ["yr/fnruntime.so"], + srcs = ["yuanrong/fnruntime.so"], ) genrule( @@ -118,28 +118,28 @@ genrule( echo $$PYTHON_VERSION > $@ ARCH=$$(uname -m) && if [[ "$$PYTHON_VERSION" =~ "3.6" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-36m-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-36m-$$ARCH-linux-gnu.so elif [[ $$PYTHON_VERSION =~ "3.7" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-37m-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-37m-$$ARCH-linux-gnu.so elif [[ $$PYTHON_VERSION =~ "3.8" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-38-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-38-$$ARCH-linux-gnu.so elif [[ $$PYTHON_VERSION =~ "3.9" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-39-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-39-$$ARCH-linux-gnu.so elif [[ $$PYTHON_VERSION =~ "3.10" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-310-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-310-$$ARCH-linux-gnu.so elif [[ $$PYTHON_VERSION =~ "3.11" ]]; then - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/fnruntime.cpython-311-$$ARCH-linux-gnu.so + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/fnruntime.cpython-311-$$ARCH-linux-gnu.so else - cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yr/ + cp -ar $(location py_strip) $$PYTHON_CODE_DIR/yuanrong/ fi - cp -ar $(location //:grpc_strip) $$PYTHON_CODE_DIR/yr/ - ln -f -s libssl.so.1.1 $$PYTHON_CODE_DIR/yr/libssl.so - ln -f -s libcrypto.so.1.1 $$PYTHON_CODE_DIR/yr/libcrypto.so - ln -f -s liblitebus.so.0.0.1 $$PYTHON_CODE_DIR/yr/liblitebus.so + cp -ar $(location //:grpc_strip) $$PYTHON_CODE_DIR/yuanrong/ + ln -f -s libssl.so.1.1 $$PYTHON_CODE_DIR/yuanrong/libssl.so + ln -f -s libcrypto.so.1.1 $$PYTHON_CODE_DIR/yuanrong/libcrypto.so + ln -f -s liblitebus.so.0.0.1 $$PYTHON_CODE_DIR/yuanrong/liblitebus.so - ln -f -s libspdlog.so.1.12.0 $$PYTHON_CODE_DIR/yr/libspdlog.so.1 - ln -f -s libspdlog.so.1 $$PYTHON_CODE_DIR/yr/libspdlog.so - ln -f -s libspdlog.so.1 $$PYTHON_CODE_DIR/yr/libspdlog.so + ln -f -s libspdlog.so.1.12.0 $$PYTHON_CODE_DIR/yuanrong/libspdlog.so.1 + ln -f -s libspdlog.so.1 $$PYTHON_CODE_DIR/yuanrong/libspdlog.so + ln -f -s libspdlog.so.1 $$PYTHON_CODE_DIR/yuanrong/libspdlog.so cd $$BASE_DIR echo "$$BASE_DIR" >> $@ @@ -152,7 +152,7 @@ genrule( srcs = [ "//src/proto:libruntime_py_proto", ], - outs = ["yr/libruntime_pb2.py"], + outs = ["yuanrong/libruntime_pb2.py"], cmd = """ cat "$(location //src/proto:libruntime_py_proto)" >$@ """, @@ -162,12 +162,12 @@ genrule( py_library( name = "yr_lib", srcs = glob( - ["yr/**/*.py"], - exclude = ["yr/tests/*.py"], + ["yuanrong/**/*.py"], + exclude = ["yuanrong/tests/*.py"], ), data = [ - "yr/fnruntime.so", - "yr/libruntime_pb2.py", + "yuanrong/fnruntime.so", + "yuanrong/libruntime_pb2.py", ], visibility = ["__subpackages__"], ) diff --git a/api/python/yr/__init__.py b/api/python/yuanrong/__init__.py similarity index 82% rename from api/python/yr/__init__.py rename to api/python/yuanrong/__init__.py index ee7c99479d3164f03250d89e46e206914df668e7..9293875eb35b16270fdd34e01ac172e607c663c8 100644 --- a/api/python/yr/__init__.py +++ b/api/python/yuanrong/__init__.py @@ -15,7 +15,7 @@ # limitations under the License. """ -yr api +yuanrong api """ import os import ctypes @@ -49,7 +49,7 @@ for so_path in [ # E402: import not at top of file # We must load so before import datasystem, so the lint is not really useful -from yr.apis import ( # noqa: E402 +from yuanrong.apis import ( # noqa: E402 init, finalize, put, get, invoke, instance, wait, cancel, method, exit, @@ -62,28 +62,29 @@ from yr.apis import ( # noqa: E402 list_named_instances ) -from yr.fcc import ( # noqa: E402 +from yuanrong.fcc import ( # noqa: E402 create_function_group, get_function_group_context ) -from yr.resource_group import ResourceGroup # noqa: E402 -from yr.runtime import ( # noqa: E402 +from yuanrong.resource_group import ResourceGroup # noqa: E402 +from yuanrong.runtime import ( # noqa: E402 ExistenceOpt, WriteMode, CacheType, SetParam, MSetParam, CreateParam, AlarmSeverity, AlarmInfo, ConsistencyType, GetParams, GetParam ) -from yr.config import ( # noqa: E402 +from yuanrong.config import ( # noqa: E402 Config, InvokeOptions, UserTLSConfig, FunctionGroupOptions, SchedulingAffinityType, FunctionGroupContext, ServerInfo, DeviceInfo, ResourceGroupOptions, GroupOptions, ) -from yr.group import Group -from yr.stream import ProducerConfig, SubscriptionConfig, Element # noqa: E402 -from yr.functionsdk.function import Function # noqa: E402 -from yr.functionsdk.context import Context # noqa: E402 -from yr.affinity import Affinity, AffinityType, AffinityKind, AffinityScope, LabelOperator, OperatorType # noqa: E402 -from yr.metrics import Gauge, Alarm, UInt64Counter, DoubleCounter # noqa: E402 +from yuanrong.group import Group +from yuanrong.stream import ProducerConfig, SubscriptionConfig, Element # noqa: E402 +from yuanrong.functionsdk.function import Function # noqa: E402 +from yuanrong.functionsdk.context import Context # noqa: E402 +from yuanrong.affinity import ( # noqa: E402 +Affinity, AffinityType, AffinityKind, AffinityScope, LabelOperator, OperatorType) +from yuanrong.metrics import Gauge, Alarm, UInt64Counter, DoubleCounter # noqa: E402 -from yr.decorator.function_proxy import FunctionProxy # noqa: E402 -from yr.decorator.instance_proxy import ( # noqa: E402 +from yuanrong.decorator.function_proxy import FunctionProxy # noqa: E402 +from yuanrong.decorator.instance_proxy import ( # noqa: E402 InstanceCreator, InstanceProxy, MethodProxy, FunctionGroupHandler, FunctionGroupMethodProxy) __all__ = [ diff --git a/api/python/yr/accelerate/__init__.py b/api/python/yuanrong/accelerate/__init__.py similarity index 100% rename from api/python/yr/accelerate/__init__.py rename to api/python/yuanrong/accelerate/__init__.py diff --git a/api/python/yr/accelerate/executor.py b/api/python/yuanrong/accelerate/executor.py similarity index 97% rename from api/python/yr/accelerate/executor.py rename to api/python/yuanrong/accelerate/executor.py index 904016bcbce601c5c9632b6ca74e8e8408eae3c7..b13427e153cc8ac697aa665a3481e7c8be1ee010 100644 --- a/api/python/yr/accelerate/executor.py +++ b/api/python/yuanrong/accelerate/executor.py @@ -19,9 +19,9 @@ import traceback import threading import asyncio from typing import Dict, Tuple, Optional -from yr import log -from yr.accelerate.shm_broadcast import MessageQueue, ResponseStatus, STOP_EVENT -from yr.executor.instance_manager import InstanceManager +from yuanrong import log +from yuanrong.accelerate.shm_broadcast import MessageQueue, ResponseStatus, STOP_EVENT +from yuanrong.executor.instance_manager import InstanceManager ACCELERATE_WORKER = None diff --git a/api/python/yr/accelerate/shm_broadcast.py b/api/python/yuanrong/accelerate/shm_broadcast.py similarity index 98% rename from api/python/yr/accelerate/shm_broadcast.py rename to api/python/yuanrong/accelerate/shm_broadcast.py index edcad1c62adb214739e837c5435710c5782d9c4b..7d98f82f149285dcd1e4fedde65f9ff1d77d72f6 100644 --- a/api/python/yr/accelerate/shm_broadcast.py +++ b/api/python/yuanrong/accelerate/shm_broadcast.py @@ -23,8 +23,8 @@ from contextlib import contextmanager, asynccontextmanager from typing import Optional from enum import IntEnum from dataclasses import dataclass -from yr import log -import yr +from yuanrong import log +import yuanrong STOP_EVENT = threading.Event() USE_SCHED_YIELD = ((sys.version_info[:3] >= (3, 11, 1)) @@ -67,14 +67,14 @@ class ShmRingBuffer: self.data_offset = 0 self.metadata_offset = self.max_chunk_bytes * self.max_chunks if name is None: - obj_id, shared_memory = yr.runtime_holder.global_runtime.get_runtime().create_buffer( + obj_id, shared_memory = yuanrong.runtime_holder.global_runtime.get_runtime().create_buffer( self.total_bytes_of_buffer) self.name = obj_id self.shared_memory = shared_memory self.shared_memory.get_buf()[:] = bytes(len(self.shared_memory.get_buf())) else: self.name = name - self.shared_memory = yr.runtime_holder.global_runtime.get_runtime().get_buffer(name) + self.shared_memory = yuanrong.runtime_holder.global_runtime.get_runtime().get_buffer(name) def handle(self): """message queue handle""" diff --git a/api/python/yr/affinity.py b/api/python/yuanrong/affinity.py similarity index 100% rename from api/python/yr/affinity.py rename to api/python/yuanrong/affinity.py diff --git a/api/python/yr/apis.py b/api/python/yuanrong/apis.py similarity index 85% rename from api/python/yr/apis.py rename to api/python/yuanrong/apis.py index e029809afdbd901db03f76dd3359f0707d89fb58..80379d2f8411251fb2c64e19d9638b9cfecbb4be 100644 --- a/api/python/yr/apis.py +++ b/api/python/yuanrong/apis.py @@ -22,26 +22,26 @@ import logging import os from typing import List, Dict, Optional, Tuple, Union -from yr.libruntime_pb2 import LanguageType - -from yr import log, runtime_holder -from yr.code_manager import CodeManager -from yr.common import constants, utils -from yr.config import ClientInfo, Config, InvokeOptions -from yr.config_manager import ConfigManager -from yr.decorator import function_proxy, instance_proxy -from yr.executor.executor import Executor -from yr.fnruntime import Consumer, Producer, auto_get_cluster_access_info -from yr.object_ref import ObjectRef -from yr.resource_group_ref import RgObjectRef -from yr.runtime import ExistenceOpt, WriteMode, CacheType, SetParam, MSetParam, CreateParam, GetParams -from yr.stream import ProducerConfig, SubscriptionConfig -from yr.decorator.function_proxy import FunctionProxy -from yr.decorator.instance_proxy import InstanceCreator, InstanceProxy -from yr.common.utils import CrossLanguageInfo -from yr.resource_group import ResourceGroup - -from yr.serialization import Serialization +from yuanrong.libruntime_pb2 import LanguageType + +from yuanrong import log, runtime_holder +from yuanrong.code_manager import CodeManager +from yuanrong.common import constants, utils +from yuanrong.config import ClientInfo, Config, InvokeOptions +from yuanrong.config_manager import ConfigManager +from yuanrong.decorator import function_proxy, instance_proxy +from yuanrong.executor.executor import Executor +from yuanrong.fnruntime import Consumer, Producer, auto_get_cluster_access_info +from yuanrong.object_ref import ObjectRef +from yuanrong.resource_group_ref import RgObjectRef +from yuanrong.runtime import ExistenceOpt, WriteMode, CacheType, SetParam, MSetParam, CreateParam, GetParams +from yuanrong.stream import ProducerConfig, SubscriptionConfig +from yuanrong.decorator.function_proxy import FunctionProxy +from yuanrong.decorator.instance_proxy import InstanceCreator, InstanceProxy +from yuanrong.common.utils import CrossLanguageInfo +from yuanrong.resource_group import ResourceGroup + +from yuanrong.serialization import Serialization __g_is_init = False _MAX_INT = 0x7FFFFFFF @@ -136,19 +136,19 @@ def init(conf: Config = None) -> ClientInfo: The context information of this invocation. Data type is ClientInfo. Raises: - RuntimeError: If yr.init is called more than once. + RuntimeError: If yuanrong.init is called more than once. TypeError: If the parameter type is incorrect. ValueError: If the parameter value is incorrect. Example: - >>> import yr + >>> import yuanrong >>> - >>> conf = yr.Config() - >>> yr.init(conf) + >>> conf = yuanrong.Config() + >>> yuanrong.init(conf) """ if is_initialized() and ConfigManager().is_driver: - raise RuntimeError("yr.init cannot be called twice") + raise RuntimeError("yuanrong.init cannot be called twice") conf = Config() if conf is None else conf @@ -184,16 +184,16 @@ def finalize() -> None: Raises: - RuntimeError: This exception will be thrown if ``finalize`` is called without initializing ``yr``. + RuntimeError: This exception will be thrown if ``finalize`` is called without initializing ``yuanrong``. Returns: None. Examples: - >>> import yr - >>> conf = yr.Config() - >>> yr.init(conf) - >>> yr.finalize() + >>> import yuanrong + >>> conf = yuanrong.Config() + >>> yuanrong.init(conf) + >>> yuanrong.finalize() """ global __g_is_init if not __g_is_init: @@ -218,7 +218,7 @@ def put(obj: object, create_param: CreateParam = CreateParam()) -> ObjectRef: Put an object to datasystem. Note: - 1. this method should be used after `yr.init()`. + 1. this method should be used after `yuanrong.init()`. 2. If the type of put is memoryview, bytearray or bytes, serialization is omitted at this time. 3. If the object passed to put() is of type memoryview, bytearray, or bytes, its length must not be ``0``. @@ -233,25 +233,25 @@ def put(obj: object, create_param: CreateParam = CreateParam()) -> ObjectRef: ValueError: If the input `obj` is `None` or a zero-length `bytes`, `bytearray`, or `memoryview` object. TypeError: If the input obj is already an `ObjectRef`. TypeError: If the input obj is not serializable, e.g. `thread.RLock`. - RuntimeError: Call `yr.put()` before `yr.init()`. + RuntimeError: Call `yuanrong.put()` before `yuanrong.init()`. RuntimeError: Failed to put to datasystem. Examples: - >>> import yr - >>> yr.init() - >>> param = yr.CreateParam() - >>> param.cache_type = yr.CacheType.DISK + >>> import yuanrong + >>> yuanrong.init() + >>> param = yuanrong.CreateParam() + >>> param.cache_type = yuanrong.CacheType.DISK >>> bs = bytes(0) >>> mem = memoryview(bytes(100)) - >>> obj_ref2 = yr.put(mem) - >>> print(yr.get(obj_ref2)) + >>> obj_ref2 = yuanrong.put(mem) + >>> print(yuanrong.get(obj_ref2)) >>> # The final print output is a memoryview pointer. >>> byte_array = bytearray(20) - >>> obj_ref3 = yr.put(byte_array) - >>> print(yr.get(obj_ref3)) + >>> obj_ref3 = yuanrong.put(byte_array) + >>> print(yuanrong.get(obj_ref3)) >>> # The final print output is a memoryview pointer. - >>> obj_ref4 = yr.put(100) - >>> print(yr.get(obj_ref4)) + >>> obj_ref4 = yuanrong.put(100) + >>> print(yuanrong.get(obj_ref4)) """ if obj is None or (isinstance(obj, (bytes, bytearray, memoryview)) and len(obj) == 0): raise ValueError("value is None or has zero length") @@ -271,7 +271,7 @@ def get(obj_refs: Union["ObjectRef", List, "RgObjectRef"], timeout: int = consta The interface call will block until the object's value is obtained or a timeout occurs. Note: - yr.get() uniformly returns a memoryview pointer for bytes, bytearray, and memoryview types. + yuanrong.get() uniformly returns a memoryview pointer for bytes, bytearray, and memoryview types. Args: obj_refs (ObjectRef, List[ObjectRef]): The object_ref of the object in the data system. @@ -292,17 +292,17 @@ def get(obj_refs: Union["ObjectRef", List, "RgObjectRef"], timeout: int = consta TimeoutError: If the results of all object references cannot be obtained within the specified timeout period. Examples: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.invoke() + >>> @yuanrong.invoke() >>> def add(a, b): ... return a + b >>> obj_ref_1 = add.invoke(1, 2) >>> obj_ref_2 = add.invoke(3, 4) - >>> result = yr.get([obj_ref_1, obj_ref_2], timeout=-1) + >>> result = yuanrong.get([obj_ref_1, obj_ref_2], timeout=-1) >>> print(result) - >>> yr.finalize() + >>> yuanrong.finalize() """ if timeout <= constants.MIN_TIMEOUT_LIMIT and timeout != constants.NO_LIMIT: @@ -355,12 +355,12 @@ def wait(obj_refs: Union[ObjectRef, List[ObjectRef]], wait_num: int = 1, ValueError: If the input parameter is incorrect. Examples: - >>> import yr + >>> import yuanrong >>> import time >>> - >>> yr.init() + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke ... def demo(a): ... time.sleep(a) ... return "sleep:", a @@ -369,12 +369,12 @@ def wait(obj_refs: Union[ObjectRef, List[ObjectRef]], wait_num: int = 1, >>> >>> wait_num = 3 >>> timeout = 10 - >>> result = yr.wait(res, wait_num, timeout) + >>> result = yuanrong.wait(res, wait_num, timeout) >>> print("ready_list = ", result[0], "unready_list = ", result[1]) - >>> print(yr.get(result[0])) + >>> print(yuanrong.get(result[0])) [('sleep:', 0), ('sleep:', 1)] >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ if timeout is None: timeout = -1 @@ -438,16 +438,16 @@ def cancel(obj_refs: Union[ObjectRef, List[ObjectRef]], allow_force: bool = _DEF Examples: >>> import time - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke >>> def func(): >>> time.sleep(100) >>> >>> ret = func.invoke() - >>> yr.cancel(ret) - >>> yr.finalize() + >>> yuanrong.cancel(ret) + >>> yuanrong.finalize() """ if isinstance(obj_refs, ObjectRef): obj_refs = [obj_refs] @@ -481,28 +481,28 @@ def invoke(*args, **kwargs) -> function_proxy.FunctionProxy: Examples: Simple invocation example: - >>> import yr - >>> yr.init() - >>> @yr.invoke + >>> import yuanrong + >>> yuanrong.init() + >>> @yuanrong.invoke ... def add(a, b): ... return a + b >>> ret = add.invoke(1, 2) - >>> print(yr.get(ret)) - >>> yr.finalize() + >>> print(yuanrong.get(ret)) + >>> yuanrong.finalize() Function invocation example: - >>> import yr - >>> yr.init() - >>> @yr.invoke + >>> import yuanrong + >>> yuanrong.init() + >>> @yuanrong.invoke ... def func1(a): ... return a + " func1" - >>> @yr.invoke + >>> @yuanrong.invoke ... def func2(a): - ... return yr.get(func1.invoke(a)) + " func2" + ... return yuanrong.get(func1.invoke(a)) + " func2" >>> ret = func2.invoke("hello") - >>> print(yr.get(ret)) - >>> yr.finalize() + >>> print(yuanrong.get(ret)) + >>> yuanrong.finalize() """ if len(args) == 1 and len(kwargs) == 0 and callable(args[0]): return function_proxy.make_decorator()(args[0]) @@ -518,7 +518,7 @@ def instance(*args, **kwargs) -> instance_proxy.InstanceCreator: Args: class (class): The class that needs to be remotely invoked. - invoke_options (yr.InvokeOptions): Invocation parameters. + invoke_options (yuanrong.InvokeOptions): Invocation parameters. Returns: The creator of the decorated class. @@ -529,10 +529,10 @@ def instance(*args, **kwargs) -> instance_proxy.InstanceCreator: Example: Simple invocation example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.instance + >>> @yuanrong.instance ... class Instance: ... sum = 0 ... def add(self, a): @@ -541,18 +541,18 @@ def instance(*args, **kwargs) -> instance_proxy.InstanceCreator: ... return self.sum >>> >>> ins = Instance.invoke() - >>> yr.get(ins.add.invoke(1)) - >>> print(yr.get(ins.get.invoke())) + >>> yuanrong.get(ins.add.invoke(1)) + >>> print(yuanrong.get(ins.get.invoke())) 1 >>> ins.terminate() >>> - >>> yr.finalize() + >>> yuanrong.finalize() Function invocation example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.instance + >>> @yuanrong.instance ... class Instance: ... def __init__(self): ... self.sum = 0 @@ -561,22 +561,22 @@ def instance(*args, **kwargs) -> instance_proxy.InstanceCreator: ... def get(self): ... return self.sum - >>> @yr.instance + >>> @yuanrong.instance ... class Instance2: ... def __init__(self): ... self.ins = Instance.invoke() ... def add(self, a): ... return self.ins.add.invoke(a) ... def get(self): - ... return yr.get(self.ins.get.invoke()) + ... return yuanrong.get(self.ins.get.invoke()) >>> >>> ins = Instance2.invoke() - >>> yr.get(ins.add.invoke(2)) - >>> print(yr.get(ins.get.invoke())) + >>> yuanrong.get(ins.add.invoke(2)) + >>> print(yuanrong.get(ins.get.invoke())) 2 >>> ins.terminate() >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ if len(args) == 1 and len(kwargs) == 0 and callable(args[0]): @@ -601,10 +601,10 @@ def method(*args, **kwargs): TypeError: If the type of the input parameters is incorrect. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.instance + >>> @yuanrong.instance ... class Instance: ... sum = 0 ... @@ -614,19 +614,19 @@ def method(*args, **kwargs): ... def get(self): ... return self.sum ... - ... @yr.method(return_nums=2) + ... @yuanrong.method(return_nums=2) ... def detail(self, a, b): ... return a, b ... >>> ins = Instance.invoke() >>> res1, res2 = ins.detail.invoke(0, 1) - >>> print("detail result1:", yr.get(res1)) + >>> print("detail result1:", yuanrong.get(res1)) detail result1: 0 - >>> print("detail result2:", yr.get(res2)) + >>> print("detail result2:", yuanrong.get(res2)) detail result2: 1 >>> ins.terminate() >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ if "concurrency_group" in kwargs and len(args) == 0: kwargs.pop("concurrency_group") @@ -821,12 +821,13 @@ def kv_write(key: str, value: bytes, existence: ExistenceOpt = ExistenceOpt.NONE RuntimeError: If the data fails to be written to the data system. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> yr.kv_write("kv-key", b"value1", yr.ExistenceOpt.NONE, yr.WriteMode.NONE_L2_CACHE, 0, yr.CacheType.MEMORY) + >>> yuanrong.kv_write("kv-key", b"value1", yuanrong.ExistenceOpt.NONE, + ... yuanrong.WriteMode.NONE_L2_CACHE, 0, yuanrong.CacheType.MEMORY) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ set_param = SetParam() set_param.existence = existence @@ -857,18 +858,18 @@ def kv_write_with_param(key: str, value: bytes, set_param: SetParam) -> None: RuntimeError: If the data fails to be written to the data system. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> # The worker startup parameters need to be configured with shared_disk_directory and shared_disk_size_mb; >>> # otherwise, this example will result in an error - >>> set_param = yr.SetParam() - >>> set_param.existence = yr.ExistenceOpt.NX - >>> set_param.write_mode = yr.WriteMode.NONE_L2_CACHE_EVICT + >>> set_param = yuanrong.SetParam() + >>> set_param.existence = yuanrong.ExistenceOpt.NX + >>> set_param.write_mode = yuanrong.WriteMode.NONE_L2_CACHE_EVICT >>> set_param.ttl_second = 10 - >>> set_param.cache_type = yr.CacheType.DISK - >>> yr.kv_write_with_param("kv-key", b"value1", set_param) + >>> set_param.cache_type = yuanrong.CacheType.DISK + >>> yuanrong.kv_write_with_param("kv-key", b"value1", set_param) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ runtime_holder.global_runtime.get_runtime().kv_write(key, value, set_param) @@ -895,18 +896,18 @@ def kv_m_write_tx(keys: List[str], values: List[bytes], m_set_param: MSetParam = If data writing to the data system fails. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> # The worker startup parameters need to be configured with shared_disk_directory and shared_disk_size_mb; >>> # otherwise, this example will result in an error - >>> mset_param = yr.MSetParam() - >>> mset_param.existence = yr.ExistenceOpt.NX - >>> mset_param.write_mode = yr.WriteMode.NONE_L2_CACHE_EVICT + >>> mset_param = yuanrong.MSetParam() + >>> mset_param.existence = yuanrong.ExistenceOpt.NX + >>> mset_param.write_mode = yuanrong.WriteMode.NONE_L2_CACHE_EVICT >>> mset_param.ttl_second = 100 - >>> mset_param.cache_type = yr.CacheType.DISK - >>> yr.kv_m_write_tx(["key1", "key2"], [b"value1", b"value2"], mset_param) + >>> mset_param.cache_type = yuanrong.CacheType.DISK + >>> yuanrong.kv_m_write_tx(["key1", "key2"], [b"value1", b"value2"], mset_param) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ if len(keys) != len(values): raise ValueError( @@ -938,7 +939,7 @@ def kv_read( RuntimeError: If data retrieval from the data system fails. Example: - >>> v1 = yr.kv_read("kv-key") + >>> v1 = yuanrong.kv_read("kv-key") """ is_single_obj = isinstance(key, str) rets = runtime_holder.global_runtime.get_runtime().kv_read(key, timeout) @@ -966,18 +967,18 @@ def kv_set(key: str, value: bytes, set_param: SetParam = SetParam()) -> None: RuntimeError: If the data writing to the data system fails. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> # The worker startup parameters need to be configured with shared_disk_directory and shared_disk_size_mb; >>> # otherwise, this example will result in an error - >>> set_param = yr.SetParam() - >>> set_param.existence = yr.ExistenceOpt.NX - >>> set_param.write_mode = yr.WriteMode.NONE_L2_CACHE_EVICT + >>> set_param = yuanrong.SetParam() + >>> set_param.existence = yuanrong.ExistenceOpt.NX + >>> set_param.write_mode = yuanrong.WriteMode.NONE_L2_CACHE_EVICT >>> set_param.ttl_second = 10 - >>> set_param.cache_type = yr.CacheType.DISK - >>> yr.kv_set("kv-key", b"value1", set_param) + >>> set_param.cache_type = yuanrong.CacheType.DISK + >>> yuanrong.kv_set("kv-key", b"value1", set_param) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ runtime_holder.global_runtime.get_runtime().kv_write(key, value, set_param) @@ -1004,7 +1005,7 @@ def kv_get( RuntimeError: If data retrieval from the data system fails. Example: - >>> v1 = yr.kv_get("kv-key") + >>> v1 = yuanrong.kv_get("kv-key") """ if timeout <= constants.MIN_TIMEOUT_LIMIT and timeout != constants.NO_LIMIT: raise ValueError( @@ -1040,12 +1041,12 @@ def kv_get_with_param(keys: List[str], get_params: GetParams, timeout: int = con RuntimeError: If data retrieval from the data system fails. Example: - >>> get_param = yr.GetParam() + >>> get_param = yuanrong.GetParam() >>> get_param.offset = 0 >>> get_param.size = 0 - >>> params = yr.GetParams() + >>> params = yuanrong.GetParams() >>> params.get_params = [get_param] - >>> v1 = yr.kv_get_with_param(["kv-key"], params, 10) + >>> v1 = yuanrong.kv_get_with_param(["kv-key"], params, 10) """ if timeout < constants.NO_LIMIT: raise ValueError( @@ -1074,8 +1075,9 @@ def kv_del(key: Union[str, List[str]]) -> None: RuntimeError: If data deletion from the data system fails. Example: - >>> yr.kv_write("kv-key", b"value1", yr.ExistenceOpt.NONE, yr.WriteMode.NONE_L2_CACHE, 0) # doctest: +SKIP - >>> yr.kv_del("kv-key") + >>> yuanrong.kv_write("kv-key", b"value1", yuanrong.ExistenceOpt.NONE, + ... yuanrong.WriteMode.NONE_L2_CACHE, 0) # doctest: +SKIP + >>> yuanrong.kv_del("kv-key") """ runtime_holder.global_runtime.get_runtime().kv_del(key) @@ -1101,7 +1103,7 @@ def save_state(timeout_sec: int = _DEFAULT_SAVE_LOAD_STATE_TIMEOUT) -> None: Example: - >>> @yr.instance + >>> @yuanrong.instance ... class Counter: ... def __init__(self): ... self.cnt = 0 @@ -1114,20 +1116,20 @@ def save_state(timeout_sec: int = _DEFAULT_SAVE_LOAD_STATE_TIMEOUT) -> None: ... return self.cnt ... ... def save(self, timeout=30): - ... yr.save_state(timeout) + ... yuanrong.save_state(timeout) ... ... def load(self, timeout=30): - ... yr.load_state(timeout) + ... yuanrong.load_state(timeout) ... >>> counter = Counter.invoke() - >>> print(f"member value before save state: {yr.get(counter.get.invoke())}") + >>> print(f"member value before save state: {yuanrong.get(counter.get.invoke())}") >>> counter.save.invoke() >>> >>> counter.add.invoke() - >>> print(f"member value after add one: {yr.get(counter.get.invoke())}") + >>> print(f"member value after add one: {yuanrong.get(counter.get.invoke())}") >>> >>> counter.load.invoke() - >>> print(f"member value after load state(back to 0): {yr.get(counter.get.invoke())}") + >>> print(f"member value after load state(back to 0): {yuanrong.get(counter.get.invoke())}") """ remote_runtime = ConfigManager().in_cluster and not ConfigManager().is_driver if not remote_runtime: @@ -1163,7 +1165,7 @@ def load_state(timeout_sec: int = _DEFAULT_SAVE_LOAD_STATE_TIMEOUT) -> None: Example: - >>> @yr.instance + >>> @yuanrong.instance ... class Counter: ... def __init__(self): ... self.cnt = 0 @@ -1176,22 +1178,22 @@ def load_state(timeout_sec: int = _DEFAULT_SAVE_LOAD_STATE_TIMEOUT) -> None: ... return self.cnt ... ... def save(self, timeout=30): - ... yr.save_state(timeout) + ... yuanrong.save_state(timeout) ... ... def load(self, timeout=30): - ... yr.load_state(timeout) + ... yuanrong.load_state(timeout) ... >>> counter = Counter.invoke() - >>> print(f"member value before save state: {yr.get(counter.get.invoke())}") + >>> print(f"member value before save state: {yuanrong.get(counter.get.invoke())}") member value before save state: 0 >>> counter.save.invoke() >>> >>> counter.add.invoke() - >>> print(f"member value after add one: {yr.get(counter.get.invoke())}") + >>> print(f"member value after add one: {yuanrong.get(counter.get.invoke())}") member value after add one: 1 >>> >>> counter.load.invoke() - >>> print(f"member value after load state(back to 0): {yr.get(counter.get.invoke())}") + >>> print(f"member value after load state(back to 0): {yuanrong.get(counter.get.invoke())}") member value after load state(back to 0): 0 """ remote_runtime = ConfigManager().in_cluster and not ConfigManager().is_driver @@ -1226,7 +1228,7 @@ def get_instance(name: str, namespace: str = "", timeout: int = 60) -> instance_ TimeoutError: If a timeout occurs. Examples: - >>> yr.get_instance("name") + >>> yuanrong.get_instance("name") """ if not isinstance(name, str): @@ -1261,7 +1263,7 @@ def resources() -> List[dict]: """ Get the resource information of nodes in the cluster. - When requesting resource information, you need to configure `master_addr_list` in `yr.Config`. + When requesting resource information, you need to configure `master_addr_list` in `yuanrong.Config`. Returns: list[dict], The resource information of nodes in the cluster. The dict contains the following keys, @@ -1275,15 +1277,15 @@ def resources() -> List[dict]: RuntimeError: If the information retrieval from the functionsystem master fails. Examples: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> res = yr.resources() + >>> res = yuanrong.resources() >>> print(res) [{'id': 'function-agent-172.17.0.2-25742','status': 0, 'capacity': {'CPU': 1000.0, 'Memory': 8192.0}, 'allocatable': {'CPU': 500.0, 'Memory': 4096.0}}] >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ if ConfigManager().local_mode: raise RuntimeError("resources is not supported in local mode") @@ -1295,11 +1297,11 @@ def get_node_ip_address(): """ Obtain the node ip. Examples: - >>> import yr - >>> yr.init() - >>> node_ip = yr.get_node_ip_address() + >>> import yuanrong + >>> yuanrong.init() + >>> node_ip = yuanrong.get_node_ip_address() >>> print(node_ip) - >>> yr.finalize() + >>> yuanrong.finalize() """ return runtime_holder.global_runtime.get_runtime().get_node_ip_address() @@ -1362,9 +1364,9 @@ def create_resource_group(bundles: List[Dict[str, float]], name: Optional[str] = RuntimeError: If the resource group name is invalid. Examples: - >>> rg1 = yr.create_resource_group([{"NPU/Ascend910B4/count":1},{"CPU":2000,"Memory":2000}]) + >>> rg1 = yuanrong.create_resource_group([{"NPU/Ascend910B4/count":1},{"CPU":2000,"Memory":2000}]) >>> - >>> rg2 = yr.create_resource_group([{"NPU/Ascend910B4/count":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> rg2 = yuanrong.create_resource_group([{"NPU/Ascend910B4/count":1},{"CPU":2000,"Memory":2000}], "rgname") """ if not isinstance(bundles, list): raise TypeError(f"invalid bundles type, actual: {type(bundles)}, expect: list.") @@ -1394,10 +1396,10 @@ def remove_resource_group(resource_group: Union[str, ResourceGroup]): RuntimeError: The ResourceGroup name is invalid. Examples: - >>> yr.remove_resource_group("rgname") + >>> yuanrong.remove_resource_group("rgname") >>> - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") - >>> yr.remove_resource_group(rg) + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> yuanrong.remove_resource_group(rg) """ name = resource_group if isinstance(resource_group, ResourceGroup): @@ -1424,7 +1426,7 @@ class cpp_instance_class: .. code-block:: cpp #include - #include "yr/yr.h" + #include "yuanrong/yuanrong.h" class Counter { public: int count; @@ -1450,19 +1452,19 @@ class cpp_instance_class: .. code:: python - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> cpp_function_urn = ( ... "sn:cn:yrk:12345678901234561234567890123456:" - ... "function:0-yr-defaultservice-cpp:$latest" + ... "function:0-yuanrong-defaultservice-cpp:$latest" ... ) - >>> counter_class = yr.cpp_instance_class("Counter", "Counter::FactoryCreate", cpp_function_urn) - >>> opt = yr.InvokeOptions(cpu=1000, memory=1024) + >>> counter_class = yuanrong.cpp_instance_class("Counter", "Counter::FactoryCreate", cpp_function_urn) + >>> opt = yuanrong.InvokeOptions(cpu=1000, memory=1024) >>> ins = counter_class.options(opt).invoke(11) >>> result = ins.Add.invoke(9) - >>> yr.get(result) + >>> yuanrong.get(result) >>> ins.terminate() - >>> yr.finalize() + >>> yuanrong.finalize() """ self.__class_name__ = class_name self.__factory_name__ = factory_name @@ -1531,7 +1533,7 @@ def cpp_function(function_name: str, function_urn: str) -> FunctionProxy: Examples: .. code-block:: cpp - #include "yr/yr.h" + #include "yuanrong/yuanrong.h" int Square(int x) { return x * x; @@ -1542,16 +1544,16 @@ def cpp_function(function_name: str, function_urn: str) -> FunctionProxy: .. code:: python - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> cpp_function_urn = ( ... "sn:cn:yrk:12345678901234561234567890123456:" - ... "function:0-yr-defaultservice-cpp:$latest" + ... "function:0-yuanrong-defaultservice-cpp:$latest" ... ) - >>> square_func = yr.cpp_function("Square", cpp_function_urn) + >>> square_func = yuanrong.cpp_function("Square", cpp_function_urn) >>> result = square_func.invoke(5) - >>> print(yr.get(result)) - >>> yr.finalize() + >>> print(yuanrong.get(result)) + >>> yuanrong.finalize() """ return function_proxy.make_cross_language_function_proxy(function_name, function_urn, LanguageType.Cpp) @@ -1594,15 +1596,15 @@ def java_function(class_name: str, function_name: str, function_urn: str) -> Fun .. code:: python - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> java_function_urn = ( ... "sn:cn:yrk:12345678901234561234567890123456:" - ... "function:0-yr-defaultservice-java:$latest" + ... "function:0-yuanrong-defaultservice-java:$latest" ... ) - >>> java_add = yr.java_function("com.yuanrong.demo.PlusOne", "PlusOne", java_function_urn) + >>> java_add = yuanrong.java_function("com.yuanrong.demo.PlusOne", "PlusOne", java_function_urn) >>> result = java_add.invoke(1) - >>> print(yr.get(result)) + >>> print(yuanrong.get(result)) """ function_key = utils.get_function_from_urn(function_urn) @@ -1650,22 +1652,22 @@ def java_instance_class(class_name: str, function_urn: str) -> InstanceCreator: .. code:: python - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> java_function_urn = ( ... "sn:cn:yrk:12345678901234561234567890123456:" - ... "function:0-yr-defaultservice-java:$latest" + ... "function:0-yuanrong-defaultservice-java:$latest" ... ) >>> - >>> java_instance = yr.java_instance_class("com.yuanrong.demo.Counter", java_function_urn).invoke(1) + >>> java_instance = yuanrong.java_instance_class("com.yuanrong.demo.Counter", java_function_urn).invoke(1) >>> res = java_instance.Add.invoke(5) - >>> print(yr.get(res)) + >>> print(yuanrong.get(res)) >>> >>> res = java_instance.Get.invoke() - >>> print(yr.get(res)) + >>> print(yuanrong.get(res)) >>> >>> java_instance.terminate() - >>> yr.finalize() + >>> yuanrong.finalize() """ function_key = utils.get_function_from_urn(function_urn) @@ -1701,11 +1703,11 @@ def list_named_instances(all_namespaces: bool = False): If an instance is configured with a namespace, the namespace and instance name will be connected using a `-`. Examples: - >>> import yr - >>> yr.init() - >>> named_instances = yr.list_named_instances() + >>> import yuanrong + >>> yuanrong.init() + >>> named_instances = yuanrong.list_named_instances() >>> print(named_instances) - >>> yr.finalize() + >>> yuanrong.finalize() """ all_actors = runtime_holder.global_runtime.get_runtime().query_named_instances() if all_namespaces: diff --git a/api/python/yr/cluster_mode_runtime.py b/api/python/yuanrong/cluster_mode_runtime.py similarity index 96% rename from api/python/yr/cluster_mode_runtime.py rename to api/python/yuanrong/cluster_mode_runtime.py index f16d791e0a988302e99a0b1804466e5046f348df..f81f5b3997827ff8c9bde0e220bacfbf18db0d77 100644 --- a/api/python/yr/cluster_mode_runtime.py +++ b/api/python/yuanrong/cluster_mode_runtime.py @@ -19,19 +19,19 @@ import logging from typing import Any, Dict, List, Tuple, Union, Callable -from yr.exception import YRInvokeError -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.common.types import InvokeArg, GroupInfo -from yr.config import InvokeOptions, GroupOptions -from yr.config_manager import ConfigManager -from yr.fnruntime import Consumer, Fnruntime, Producer, SharedBuffer -from yr.libruntime_pb2 import ApiType, FunctionMeta -from yr.common.utils import GaugeData, UInt64CounterData, DoubleCounterData -from yr.object_ref import ObjectRef -from yr.runtime import Runtime, AlarmInfo, SetParam, MSetParam, CreateParam, GetParams -from yr.serialization import Serialization -from yr.stream import ProducerConfig, SubscriptionConfig -from yr.accelerate.shm_broadcast import Handle +from yuanrong.exception import YRInvokeError +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.common.types import InvokeArg, GroupInfo +from yuanrong.config import InvokeOptions, GroupOptions +from yuanrong.config_manager import ConfigManager +from yuanrong.fnruntime import Consumer, Fnruntime, Producer, SharedBuffer +from yuanrong.libruntime_pb2 import ApiType, FunctionMeta +from yuanrong.common.utils import GaugeData, UInt64CounterData, DoubleCounterData +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime import Runtime, AlarmInfo, SetParam, MSetParam, CreateParam, GetParams +from yuanrong.serialization import Serialization +from yuanrong.stream import ProducerConfig, SubscriptionConfig +from yuanrong.accelerate.shm_broadcast import Handle _logger = logging.getLogger(__name__) diff --git a/api/python/yr/code_manager.py b/api/python/yuanrong/code_manager.py similarity index 97% rename from api/python/yr/code_manager.py rename to api/python/yuanrong/code_manager.py index c85afed46d8ab7e1a87a9d852fbe738de033ae62..a9fb45d72819b2c29127b3d40704f2ee0ee7e416 100644 --- a/api/python/yr/code_manager.py +++ b/api/python/yuanrong/code_manager.py @@ -23,12 +23,12 @@ import sys import threading from typing import Callable, List -from yr import log -from yr.common import constants, utils -from yr.common.singleton import Singleton -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.functionsdk.error_code import FaasErrorCode -from yr.libruntime_pb2 import LanguageType +from yuanrong import log +from yuanrong.common import constants, utils +from yuanrong.common.singleton import Singleton +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.functionsdk.error_code import FaasErrorCode +from yuanrong.libruntime_pb2 import LanguageType _DEFAULT_ADMIN_FUNC_PATH = "/adminfunc/" _MAX_FAAS_ENTRY_NUMS = 3 @@ -54,9 +54,7 @@ class CodeManager: """ def __init__(self): - # code_key : code self.code_map = {} - # code_key: code_path self.entry_map = {} self.module_cache = {} self.__lock = threading.Lock() diff --git a/api/python/yr/common/__init__.py b/api/python/yuanrong/common/__init__.py similarity index 100% rename from api/python/yr/common/__init__.py rename to api/python/yuanrong/common/__init__.py diff --git a/api/python/yr/common/constants.py b/api/python/yuanrong/common/constants.py similarity index 100% rename from api/python/yr/common/constants.py rename to api/python/yuanrong/common/constants.py diff --git a/api/python/yr/common/singleton.py b/api/python/yuanrong/common/singleton.py similarity index 100% rename from api/python/yr/common/singleton.py rename to api/python/yuanrong/common/singleton.py diff --git a/api/python/yr/common/types.py b/api/python/yuanrong/common/types.py similarity index 100% rename from api/python/yr/common/types.py rename to api/python/yuanrong/common/types.py diff --git a/api/python/yr/common/utils.py b/api/python/yuanrong/common/utils.py similarity index 99% rename from api/python/yr/common/utils.py rename to api/python/yuanrong/common/utils.py index e67a6a2bfac5ba69af595c42e601228c27b3d4ca..cd931a2bb506de1ed5d59418c1813043c63ab1cb 100644 --- a/api/python/yr/common/utils.py +++ b/api/python/yuanrong/common/utils.py @@ -33,9 +33,9 @@ from typing import Dict import asyncio import cloudpickle -from yr import log -from yr.common import constants -from yr.libruntime_pb2 import LanguageType, FunctionMeta +from yuanrong import log +from yuanrong.common import constants +from yuanrong.libruntime_pb2 import LanguageType, FunctionMeta try: import uvloop @@ -45,7 +45,7 @@ except ImportError: _URN_SEPARATOR = ":" _NO_ORDER_SUFFIX = "-x" -_OBJECT_ID_PREFIX = "yr-api-obj-" +_OBJECT_ID_PREFIX = "yuanrong-api-obj-" _TRACE_ID = "-trace-" _JOB_ID = "" _RGROUP_PREFIX = "rgroup-" diff --git a/api/python/yr/compiled_dag_ref.py b/api/python/yuanrong/compiled_dag_ref.py similarity index 92% rename from api/python/yr/compiled_dag_ref.py rename to api/python/yuanrong/compiled_dag_ref.py index 6893416c91e9bfaceb6cceb404be6a24262d2d5e..c69321f44faaa1a7146a1d7283ef85a1b3dfe8d1 100644 --- a/api/python/yr/compiled_dag_ref.py +++ b/api/python/yuanrong/compiled_dag_ref.py @@ -17,8 +17,8 @@ import asyncio from typing import Any, List, Optional -import yr -from yr.exception import ( +import yuanrong +from yuanrong.exception import ( GetTimeoutError, YRChannelError, YRChannelTimeoutError, @@ -54,17 +54,17 @@ class CompiledDAGRef: A reference to a compiled DAG execution result. This is a subclass of ObjectRef and resembles ObjectRef. For example, - similar to ObjectRef, yr.get() can be called on it to retrieve the result. + similar to ObjectRef, yuanrong.get() can be called on it to retrieve the result. However, there are several major differences: - 1. yr.get() can only be called once per CompiledDAGRef. - 2. yr.wait() is not supported. + 1. yuanrong.get() can only be called once per CompiledDAGRef. + 2. yuanrong.wait() is not supported. 3. CompiledDAGRef cannot be copied, deep copied, or pickled. 4. CompiledDAGRef cannot be passed as an argument to another task. """ def __init__( self, - dag: "yr.dag.CompiledDAG", + dag: "yuanrong.dag.CompiledDAG", execution_index: int, channel_index: Optional[int] = None, ): @@ -87,7 +87,7 @@ class CompiledDAGRef: self._dag = dag self._execution_index = execution_index self._channel_index = channel_index - # Whether yr.get() was called on this CompiledDAGRef. + # Whether yuanrong.get() was called on this CompiledDAGRef. self._yr_get_called = False self._dag_output_channels = dag.dag_output_channels @@ -116,7 +116,7 @@ class CompiledDAGRef: """ if self._yr_get_called: raise ValueError( - "yr.get() can only be called once " + "yuanrong.get() can only be called once " "on a CompiledDAGRef, and it was already called." ) @@ -131,7 +131,7 @@ class CompiledDAGRef: except YRChannelTimeoutError: raise except YRChannelError: - # If we get a channel error, we'd like to call yr.get() on + # If we get a channel error, we'd like to call yuanrong.get() on # the actor execution loop refs to check if this is a result # of task execution error which could not be passed down # (e.g., when a pure NCCL channel is used, it is only @@ -142,7 +142,7 @@ class CompiledDAGRef: # actor task refs have errors. actor_execution_loop_refs = list(self._dag.worker_task_refs.values()) try: - yr.get(actor_execution_loop_refs, timeout=10) + yuanrong.get(actor_execution_loop_refs, timeout=10) except GetTimeoutError as timeout_error: raise Exception( "Timed out when getting the actor execution loop exception. " @@ -161,20 +161,20 @@ class CompiledDAGFuture: """ A reference to a compiled DAG execution result, when executed with asyncio. This differs from CompiledDAGRef in that `await` must be called on the - future to get the result, instead of `yr.get()`. + future to get the result, instead of `yuanrong.get()`. This resembles async usage of ObjectRefs. For example, similar to ObjectRef, `await` can be called directly on the CompiledDAGFuture to retrieve the result. However, there are several major differences: 1. `await` can only be called once per CompiledDAGFuture. - 2. yr.wait() is not supported. + 2. yuanrong.wait() is not supported. 3. CompiledDAGFuture cannot be copied, deep copied, or pickled. 4. CompiledDAGFuture cannot be passed as an argument to another task. """ def __init__( self, - dag: "yr.dag.CompiledDAG", + dag: "yuanrong.dag.CompiledDAG", execution_index: int, fut: "asyncio.Future", channel_index: Optional[int] = None, diff --git a/api/python/yr/config.py b/api/python/yuanrong/config.py similarity index 95% rename from api/python/yr/config.py rename to api/python/yuanrong/config.py index 1b73779ef3f4078b26eaebba3383d7702f8f54db..80b05de25e9a886d707175c629c099137b42f681 100644 --- a/api/python/yr/config.py +++ b/api/python/yuanrong/config.py @@ -15,14 +15,14 @@ # limitations under the License. """ -yr api config for user +yuanrong api config for user """ import dataclasses import json from dataclasses import asdict, dataclass, field from typing import Dict, List, Union, Optional, get_origin, Any from enum import Enum, IntEnum -from yr.affinity import Affinity +from yuanrong.affinity import Affinity _DEFAULT_CONNECTION_NUMS = 100 _DEFAULT_ENABLE_METRICS = False @@ -113,7 +113,7 @@ class Config: job_id: str = "" #: For out cluster https ssl. tls_config: UserTLSConfig = None - #: Auto start distribute-executor when `yr.init`, and auto stop distribute-executor when `yr.finalize`. + #: Auto start distribute-executor when `yuanrong.init`, and auto stop distribute-executor when `yuanrong.finalize`. #: default is ``False``. auto: bool = False #: When `auto=True` needed, use to define deployment detail. @@ -190,9 +190,9 @@ class Config: @dataclass class ClientInfo: """ - Use to store yr client info. + Use to store yuanrong client info. """ - #: Automatically generated when `yr.init` is called, a unique identifier for a task. + #: Automatically generated when `yuanrong.init` is called, a unique identifier for a task. job_id: str @@ -332,17 +332,17 @@ class InvokeOptions: """Use to set the invoke options. Examples: - >>> import yr + >>> import yuanrong >>> import time - >>> yr.init() - >>> opt = yr.InvokeOptions() + >>> yuanrong.init() + >>> opt = yuanrong.InvokeOptions() >>> opt.pod_labels["k1"] = "v1" - >>> @yr.invoke(invoke_options=opt) + >>> @yuanrong.invoke(invoke_options=opt) ... def func(): ... time.sleep(100) >>> ret = func.invoke() - >>> yr.get(ret) - >>> yr.finalize() + >>> yuanrong.get(ret) + >>> yuanrong.finalize() """ #: The size of the CPU required. Value Range is [300, 16000] and unit is m (milli-core). cpu: int = 500 @@ -384,9 +384,9 @@ class InvokeOptions: When used as a user-defined tag for metrics: - >>> import yr - >>> yr.init() - >>> opt = yr.InvokeOptions() + >>> import yuanrong + >>> yuanrong.init() + >>> opt = yuanrong.InvokeOptions() >>> opt.custom_extensions["YR_Metrics"] = "{\'endpoint\':\'127.0.0.1\', \'project_id\':\'my_project_id\'}" In Prometheus, select `metrics name` as `yr_app_instance_billing_invoke_latency`, and you can find the custom tag @@ -517,18 +517,18 @@ class InvokeOptions: * `working_dir` configure the code path of the job. * `env_vars` configure process-level environment variables. ``runtime_env = {"env_vars":{"OMP_NUM_THREADS": "32", "TF_WARNINGS": "none"}}`` - * `shared_dir` supports configuring a shared directory for some instance, with yr managing the lifecycle of this - shared directory. `shared_dir` supports two fields: name and TTL. The name field only allows numbers, letters, - "-", and "_". The TTL supports integers greater than 0 and less than INTMAX. + * `shared_dir` supports configuring a shared directory for some instance, with yuanrong managing the lifecycle of + this shared directory. `shared_dir` supports two fields: name and TTL. The name field only allows numbers, + letters, "-", and "_". The TTL supports integers greater than 0 and less than INTMAX. ``runtime_env = {"shared_dir":{"name": "user_define", "TTL": 5}}`` * Constraints of `runtime_env`: * The keys supported by runtime_env are `conda`, `env_vars`, `pip`, `working_dir`. Other keys will not take effect and will not cause errors. - * Run the yr function with conda. The environment needs to have yr and its third-party dependencies. It is - recommended that users first create a conda environment and then specify it with `runtime_env`, for example: - ``runtime_env = {"conda":"pytorch_p39"}`` + * Run the yuanrong function with conda. The environment needs to have yuanrong and its third-party dependencies. + It is recommended that users first create a conda environment and then specify it with `runtime_env`, + for example: ``runtime_env = {"conda":"pytorch_p39"}`` * `runtime_env` supports creating and switching conda environments using configurations. The configuration needs - to install third-party dependencies for yr, for example: + to install third-party dependencies for yuanrong, for example: ``runtime_env["conda"] = {"name":"myenv","channels": ["conda-forge"], "dependencies": ["python=3.9", "msgpack-python=1.0.5", "protobuf", "libgcc-ng", "cloudpickle=2.0.0", "cython=3.0.10", "pyyaml=6.0.2"]}`` * The environment created using conda in `runtime_env` needs to be cleaned up by the user. @@ -545,7 +545,7 @@ class InvokeOptions: * `shared_dir` has the following constraints: 1. It is not recommended to configure different TTL for the same shared directory. 2. The minimum cleanup interval for shared directories is 5 seconds. - 3. When multiple yr Agents are deployed on the same node, each Agent must be configured with + 3. When multiple yuanrong Agents are deployed on the same node, each Agent must be configured with different root directory to prevent conflicts in shared directory management. """ diff --git a/api/python/yr/config/python-runtime-log.json b/api/python/yuanrong/config/python-runtime-log.json similarity index 100% rename from api/python/yr/config/python-runtime-log.json rename to api/python/yuanrong/config/python-runtime-log.json diff --git a/api/python/yr/config_manager.py b/api/python/yuanrong/config_manager.py similarity index 97% rename from api/python/yr/config_manager.py rename to api/python/yuanrong/config_manager.py index 186c51764d8a7d485cbbde683f28355901c39cc6..11544159bb9aaae07488ddadaaaf05e077194deb 100644 --- a/api/python/yr/config_manager.py +++ b/api/python/yuanrong/config_manager.py @@ -18,9 +18,9 @@ import logging -from yr.common import utils -from yr.common.singleton import Singleton -from yr.config import Config, DeploymentConfig, MetaConfig, MetaFunctionID +from yuanrong.common import utils +from yuanrong.common.singleton import Singleton +from yuanrong.config import Config, DeploymentConfig, MetaConfig, MetaFunctionID _DEFAULT_CLUSTER_PORT = "31222" _DEFAULT_IN_CLUSTER_CLUSTER_PORT = "21003" @@ -51,7 +51,7 @@ class ConfigManager: server_address: System cluster address. ds_address: DataSystem address. is_driver: only False when initialize in runtime - log_level: yr api log level, default: WARNING + log_level: yuanrong api log level, default: WARNING """ def __init__(self): @@ -230,7 +230,7 @@ class ConfigManager: Init the ConfigManager Args: - :param conf: The yr api config which set by user. + :param conf: The yuanrong api config which set by user. :param is_init: init state """ job_id = conf.job_id if conf.job_id != "" else utils.generate_job_id() diff --git a/api/python/yr/decorator/__init__.py b/api/python/yuanrong/decorator/__init__.py similarity index 100% rename from api/python/yr/decorator/__init__.py rename to api/python/yuanrong/decorator/__init__.py diff --git a/api/python/yr/decorator/function_proxy.py b/api/python/yuanrong/decorator/function_proxy.py similarity index 90% rename from api/python/yr/decorator/function_proxy.py rename to api/python/yuanrong/decorator/function_proxy.py index c2049cc7a38acd1cb175b1c41e24208cdebd8a5b..5f977a5d2acb28d72c72048c18a72ecac454bf37 100644 --- a/api/python/yr/decorator/function_proxy.py +++ b/api/python/yuanrong/decorator/function_proxy.py @@ -24,17 +24,17 @@ import types from functools import wraps from typing import List, Union -import yr -from yr import signature -from yr.config import function_group_enabled -from yr.common.types import GroupInfo -from yr.common import utils -from yr.common.utils import CrossLanguageInfo, ObjectDescriptor -from yr.config import InvokeOptions -from yr.libruntime_pb2 import FunctionMeta, LanguageType -from yr.object_ref import ObjectRef -from yr.runtime_holder import global_runtime -from yr.generator import ObjectRefGenerator +import yuanrong +from yuanrong import signature +from yuanrong.config import function_group_enabled +from yuanrong.common.types import GroupInfo +from yuanrong.common import utils +from yuanrong.common.utils import CrossLanguageInfo, ObjectDescriptor +from yuanrong.config import InvokeOptions +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime_holder import global_runtime +from yuanrong.generator import ObjectRefGenerator _logger = logging.getLogger(__name__) @@ -44,18 +44,18 @@ class FunctionProxy: Use to decorate user function. Examples: - >>> import yr + >>> import yuanrong >>> - >>> yr.init() + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke ... def add(a, b): ... return a + b >>> >>> ret = add.invoke(1, 2) - >>> print(yr.get(ret)) + >>> print(yuanrong.get(ret)) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ def __init__(self, func, cross_language_info=None, invoke_options=None, return_nums=None, initializer=None): @@ -141,19 +141,19 @@ class FunctionProxy: The FunctionProxy object itself. Data type is FunctionProxy. Examples: - >>> import yr + >>> import yuanrong >>> - >>> yr.init() + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke ... def add(a, b): ... return a + b >>> - >>> opt = yr.InvokeOptions(cpu=1000, memory=1024) + >>> opt = yuanrong.InvokeOptions(cpu=1000, memory=1024) >>> ret = add.options(opt).invoke(1, 2) - >>> print(yr.get(ret)) + >>> print(yuanrong.get(ret)) >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ for method in ("check_options_valid", "check_options_range"): @@ -210,7 +210,7 @@ class FunctionProxy: return self._options_wrapper(opts) def _invoke_function(self, opts: InvokeOptions, func, args=None, kwargs=None) -> Union[ - "yr.ObjectRef", List["yr.ObjectRef"]]: + "yuanrong.ObjectRef", List["yuanrong.ObjectRef"]]: """ The real realization of the invoke function @@ -232,12 +232,12 @@ class FunctionProxy: or not global_runtime.get_runtime().is_object_existing_in_local( self._code_ref.id )): - self._code_ref = yr.put(func) + self._code_ref = yuanrong.put(func) _logger.debug("[Reference Counting] put code with id = %s, functionName = %s", self._code_ref.id, func.__qualname__) with self._lock: if self._initializer and self._initializer_code_ref is None: - self._initializer_code_ref = yr.put(self._initializer) + self._initializer_code_ref = yuanrong.put(self._initializer) initializer_code_id = self._initializer_code_ref if self._initializer_code_ref is not None else "" func_meta = FunctionMeta(functionID=function_id, # if designated_urn is not set, @@ -305,7 +305,7 @@ def make_decorator(invoke_options=None, return_nums=None, initializer=None) -> c def decorator(func): if isinstance(func, types.FunctionType): return FunctionProxy(func, invoke_options=invoke_options, return_nums=return_nums, initializer=initializer) - raise RuntimeError("@yr.invoke decorator must be applied to a function") + raise RuntimeError("@yuanrong.invoke decorator must be applied to a function") return decorator diff --git a/api/python/yr/decorator/instance_proxy.py b/api/python/yuanrong/decorator/instance_proxy.py similarity index 96% rename from api/python/yr/decorator/instance_proxy.py rename to api/python/yuanrong/decorator/instance_proxy.py index 42ea8fefdc0fb77230f4d5f13bfbcff09c22250e..f277f3360d7e821a51e744f4679f8f10650fa096 100644 --- a/api/python/yr/decorator/instance_proxy.py +++ b/api/python/yuanrong/decorator/instance_proxy.py @@ -25,18 +25,18 @@ import threading import weakref import uuid from typing import List -import yr -from yr import signature -from yr.code_manager import CodeManager -from yr.generator import ObjectRefGenerator -from yr.common import constants, utils -from yr.common.types import GroupInfo -from yr.config import InvokeOptions, function_group_enabled -from yr.libruntime_pb2 import FunctionMeta, LanguageType -from yr.object_ref import ObjectRef -from yr.runtime_holder import global_runtime, save_real_instance_id -from yr.serialization import register_pack_hook, register_unpack_hook -from yr.accelerate.shm_broadcast import MessageQueue, STOP_EVENT +import yuanrong +from yuanrong import signature +from yuanrong.code_manager import CodeManager +from yuanrong.generator import ObjectRefGenerator +from yuanrong.common import constants, utils +from yuanrong.common.types import GroupInfo +from yuanrong.config import InvokeOptions, function_group_enabled +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime_holder import global_runtime, save_real_instance_id +from yuanrong.serialization import register_pack_hook, register_unpack_hook +from yuanrong.accelerate.shm_broadcast import MessageQueue, STOP_EVENT _logger = logging.getLogger(__name__) @@ -253,7 +253,7 @@ class InstanceCreator: self._code_ref is None or not global_runtime.get_runtime().is_object_existing_in_local(self._code_ref.id) ): - self._code_ref = yr.put(self.__user_class__) + self._code_ref = yuanrong.put(self.__user_class__) _logger.info("[Reference Counting] put code with id = %s, className = %s", self._code_ref.id, self.__user_class_descriptor__.class_name) # __init__ existed when user-defined @@ -601,7 +601,7 @@ class MethodProxy: raise RuntimeError(f"invalid return_nums: {return_nums}, should be an integer between 0 and 100") - def invoke(self, *args, **kwargs) -> "yr.ObjectRef": + def invoke(self, *args, **kwargs) -> "yuanrong.ObjectRef": """ Execute remote invoke to user functions. @@ -616,10 +616,10 @@ class MethodProxy: TypeError: If the parameter type is incorrect. Example: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.instance + >>> @yuanrong.instance ... class Instance: ... sum = 0 ... @@ -630,13 +630,13 @@ class MethodProxy: ... return self.sum ... >>> ins = Instance.invoke() - >>> yr.get(ins.add.invoke(1)) + >>> yuanrong.get(ins.add.invoke(1)) >>> - >>> print(yr.get(ins.get.invoke())) + >>> print(yuanrong.get(ins.get.invoke())) >>> >>> ins.terminate() >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ return self._invoke(args, kwargs) @@ -708,7 +708,7 @@ def make_decorator(invoke_options=None): def decorator(cls): if inspect.isclass(cls): return InstanceCreator.create_from_user_class(cls, invoke_options) - raise RuntimeError("@yr.instance decorator must be applied to a class") + raise RuntimeError("@yuanrong.instance decorator must be applied to a class") return decorator diff --git a/api/python/yr/device.py b/api/python/yuanrong/device.py similarity index 97% rename from api/python/yr/device.py rename to api/python/yuanrong/device.py index 67080c2606b39c34249b654e1219f8f9ad142354..5897d50a39f5c337784df077dcc7f399fc5e9f8d 100644 --- a/api/python/yr/device.py +++ b/api/python/yuanrong/device.py @@ -17,8 +17,8 @@ """device providing device buffer function.""" from enum import Enum from typing import List -from yr import runtime_holder -from yr.common.utils import Validator as validator +from yuanrong import runtime_holder +from yuanrong.common.utils import Validator as validator class DataType(Enum): diff --git a/api/python/yr/err_type.py b/api/python/yuanrong/err_type.py similarity index 100% rename from api/python/yr/err_type.py rename to api/python/yuanrong/err_type.py diff --git a/api/python/yr/exception.py b/api/python/yuanrong/exception.py similarity index 97% rename from api/python/yr/exception.py rename to api/python/yuanrong/exception.py index df571dc9b2bfe47dc9693a8e3b95902deb76955d..2b4bd6867048bcc9b065b644c285a10c2e9f8216 100644 --- a/api/python/yr/exception.py +++ b/api/python/yuanrong/exception.py @@ -14,10 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""yr exception type""" +"""yuanrong exception type""" import cloudpickle -from yr.common import utils +from yuanrong.common import utils class YRError(Exception): @@ -142,7 +142,7 @@ class GetTimeoutError(YRError, TimeoutError): class YRChannelError(YRError): """Indicates that encountered a system error related - to yr.dag.channel. + to yuanrong.dag.channel. """ pass @@ -170,7 +170,7 @@ class GeneratorFinished(Exception): def deal_with_yr_error(future, err): - """deal with yr invoke error""" + """deal with yuanrong invoke error""" if isinstance(err, YRInvokeError): future.set_exception(err.origin_error()) else: diff --git a/api/python/yr/executor/__init__.py b/api/python/yuanrong/executor/__init__.py similarity index 100% rename from api/python/yr/executor/__init__.py rename to api/python/yuanrong/executor/__init__.py diff --git a/api/python/yr/executor/executor.py b/api/python/yuanrong/executor/executor.py similarity index 89% rename from api/python/yr/executor/executor.py rename to api/python/yuanrong/executor/executor.py index eff61b0eed76275c6bf8a41aa98e998d1fbc4bcb..c36e9a762da431a83767655d54d0da090536662a 100644 --- a/api/python/yr/executor/executor.py +++ b/api/python/yuanrong/executor/executor.py @@ -19,14 +19,14 @@ import threading from typing import List, Tuple -from yr import log -from yr.common.utils import get_environment_variable -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.executor.function_handler import FunctionHandler -from yr.executor.faas_executor import faas_call_handler, faas_init_handler -from yr.executor.faas_handler import FaasHandler -from yr.executor.posix_handler import PosixHandler -from yr.libruntime_pb2 import ApiType, InvokeType +from yuanrong import log +from yuanrong.common.utils import get_environment_variable +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.executor.function_handler import FunctionHandler +from yuanrong.executor.faas_executor import faas_call_handler, faas_init_handler +from yuanrong.executor.faas_handler import FaasHandler +from yuanrong.executor.posix_handler import PosixHandler +from yuanrong.libruntime_pb2 import ApiType, InvokeType HANDLER = None _LOCK = threading.Lock() diff --git a/api/python/yr/executor/faas_executor.py b/api/python/yuanrong/executor/faas_executor.py similarity index 94% rename from api/python/yr/executor/faas_executor.py rename to api/python/yuanrong/executor/faas_executor.py index 08637743d3f7e868dc6382bad2703bd9b1ba73ea..2a6fa5580c30bf67a3d398e8c8310885c20d8900 100644 --- a/api/python/yr/executor/faas_executor.py +++ b/api/python/yuanrong/executor/faas_executor.py @@ -22,17 +22,17 @@ import traceback import queue from typing import Any, List -from yr.code_manager import CodeManager -from yr.common.utils import to_json_string -from yr.err_type import ErrorInfo, ModuleCode, ErrorCode -from yr.functionsdk.utils import encode_base64, timeout +from yuanrong.code_manager import CodeManager +from yuanrong.common.utils import to_json_string +from yuanrong.err_type import ErrorInfo, ModuleCode, ErrorCode +from yuanrong.functionsdk.utils import encode_base64, timeout -from yr import log -from yr.common import constants -from yr.common.constants import META_PREFIX, METALEN -from yr.functionsdk.context import init_context, init_context_invoke, load_context_meta -from yr.functionsdk.logger_manager import UserLogManager -from yr.functionsdk.error_code import FaasErrorCode +from yuanrong import log +from yuanrong.common import constants +from yuanrong.common.constants import META_PREFIX, METALEN +from yuanrong.functionsdk.context import init_context, init_context_invoke, load_context_meta +from yuanrong.functionsdk.logger_manager import UserLogManager +from yuanrong.functionsdk.error_code import FaasErrorCode _STAGE_INIT = "init" _STAGE_INVOKE = "invoke" diff --git a/api/python/yr/executor/faas_handler.py b/api/python/yuanrong/executor/faas_handler.py similarity index 83% rename from api/python/yr/executor/faas_handler.py rename to api/python/yuanrong/executor/faas_handler.py index 9fae2a0879d4c9992197c07cbab854b8980961a6..6eeadc7236a487b6d024815996e8f98235df8f3d 100644 --- a/api/python/yr/executor/faas_handler.py +++ b/api/python/yuanrong/executor/faas_handler.py @@ -18,11 +18,11 @@ from typing import List -from yr import log -from yr.common.utils import err_to_str -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.executor.faas_executor import faas_shutdown_handler -from yr.executor.handler_intf import HandlerIntf +from yuanrong import log +from yuanrong.common.utils import err_to_str +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.executor.faas_executor import faas_shutdown_handler +from yuanrong.executor.handler_intf import HandlerIntf class FaasHandler(HandlerIntf): diff --git a/api/python/yr/executor/function_handler.py b/api/python/yuanrong/executor/function_handler.py similarity index 92% rename from api/python/yr/executor/function_handler.py rename to api/python/yuanrong/executor/function_handler.py index 897f896ceb46d5f6d9485637edd866a6279fa180..4658dc408881351188276d296d863e3ebe1a743f 100644 --- a/api/python/yr/executor/function_handler.py +++ b/api/python/yuanrong/executor/function_handler.py @@ -20,17 +20,17 @@ import traceback import inspect from typing import List, Tuple -from yr.libruntime_pb2 import InvokeType - -import yr -from yr import log -from yr.code_manager import CodeManager -from yr.common.utils import err_to_str -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.exception import YRInvokeError -from yr.executor.handler_intf import HandlerIntf -from yr.executor.instance_manager import InstanceManager -from yr.signature import recover_args +from yuanrong.libruntime_pb2 import InvokeType + +import yuanrong +from yuanrong import log +from yuanrong.code_manager import CodeManager +from yuanrong.common.utils import err_to_str +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.exception import YRInvokeError +from yuanrong.executor.handler_intf import HandlerIntf +from yuanrong.executor.instance_manager import InstanceManager +from yuanrong.signature import recover_args USER_SHUTDOWN_FUNC_NAME = "__yr_shutdown__" @@ -155,7 +155,7 @@ class FunctionHandler(HandlerIntf): return result def __get_param(self, args: List) -> Tuple[object, object]: - params = yr.serialization.Serialization().deserialize(args) + params = yuanrong.serialization.Serialization().deserialize(args) args, kwargs = recover_args(params) return args, kwargs diff --git a/api/python/yr/executor/handler_intf.py b/api/python/yuanrong/executor/handler_intf.py similarity index 97% rename from api/python/yr/executor/handler_intf.py rename to api/python/yuanrong/executor/handler_intf.py index 2c18f59cd5615b4545b680576a0ee658c115c86b..e74f5105d9d192284552fc2d10fbf30c568b1bce 100644 --- a/api/python/yr/executor/handler_intf.py +++ b/api/python/yuanrong/executor/handler_intf.py @@ -19,7 +19,7 @@ from abc import ABC, abstractmethod from typing import List -from yr.err_type import ErrorInfo +from yuanrong.err_type import ErrorInfo class HandlerIntf(ABC): diff --git a/api/python/yr/executor/instance_manager.py b/api/python/yuanrong/executor/instance_manager.py similarity index 97% rename from api/python/yr/executor/instance_manager.py rename to api/python/yuanrong/executor/instance_manager.py index 72d9600f58c773bc115f338303a138df2bc102ac..0d7ce0a53ae5c17beac03659d998d79041b722c0 100644 --- a/api/python/yr/executor/instance_manager.py +++ b/api/python/yuanrong/executor/instance_manager.py @@ -16,8 +16,8 @@ """instance manager""" -from yr.common.singleton import Singleton -from yr.object_ref import ObjectRef +from yuanrong.common.singleton import Singleton +from yuanrong.object_ref import ObjectRef @Singleton diff --git a/api/python/yr/executor/posix_handler.py b/api/python/yuanrong/executor/posix_handler.py similarity index 95% rename from api/python/yr/executor/posix_handler.py rename to api/python/yuanrong/executor/posix_handler.py index c26319ebb0ce8a956752f7a620330e5f687638e6..95d99676b91c038d25b09e7ca8d5ead9826b5826 100644 --- a/api/python/yr/executor/posix_handler.py +++ b/api/python/yuanrong/executor/posix_handler.py @@ -18,7 +18,7 @@ from typing import List -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode class PosixHandler: diff --git a/api/python/yr/fcc.py b/api/python/yuanrong/fcc.py similarity index 79% rename from api/python/yr/fcc.py rename to api/python/yuanrong/fcc.py index 3e568e37dca20d12cc9ed4ea41396d7e6a778cd7..94ba1a52bf8c5138ad4b59d8f6be6f49ab7fbc9d 100644 --- a/api/python/yr/fcc.py +++ b/api/python/yuanrong/fcc.py @@ -14,10 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. from typing import Union, List -from yr.config import FunctionGroupOptions, FunctionGroupContext -from yr.decorator import function_proxy, instance_proxy -from yr.runtime_holder import global_runtime -import yr +from yuanrong.config import FunctionGroupOptions, FunctionGroupContext +from yuanrong.decorator import function_proxy, instance_proxy +from yuanrong.runtime_holder import global_runtime +import yuanrong def create_function_group( @@ -25,7 +25,7 @@ def create_function_group( args: tuple, group_size: int, options: FunctionGroupOptions, -) -> Union[List["yr.ObjectRef"], instance_proxy.FunctionGroupHandler]: +) -> Union[List["yuanrong.ObjectRef"], instance_proxy.FunctionGroupHandler]: """ Create function group instance. @@ -53,36 +53,37 @@ def create_function_group( Raises: ValueError: If the `FunctionGroupOptions` or `group_size` parameter is incorrectly filled, this exception will be thrown. - RuntimeError: If function is not wrapped by `@yr.invoke` or `@yr.instance`, this exception will be thrown. + RuntimeError: If function is not wrapped by `@yuanrong.invoke` or `@yuanrong.instance`, + this exception will be thrown. Examples: stateless function invoke example: - >>> import yr + >>> import yuanrong >>> - >>> yr.init() + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke ... def demo_func(name): ... return name >>> - >>> opts = yr.FunctionGroupOptions( + >>> opts = yuanrong.FunctionGroupOptions( ... cpu=1000, ... memory=1000, ... resources={ ... "NPU/Ascend910B4/count": 1, ... }, ... scheduling_affinity_each_bundle_size=2, - ... ) + >>> name = "function_demo" - >>> objs = yr.fcc.create_function_group(demo_func, args=(name,), group_size=8, options=opts) - >>> rets = yr.get(objs) + >>> objs = yuanrong.fcc.create_function_group(demo_func, args=(name,), group_size=8, options=opts) + >>> rets = yuanrong.get(objs) >>> assert rets == [name for i in range(1, 9)] - >>> yr.finalize() + >>> yuanrong.finalize() class invoke example: - >>> import yr + >>> import yuanrong >>> - >>> @yr.instance + >>> @yuanrong.instance ... class Demo(object): ... name = "" >>> @@ -92,7 +93,7 @@ def create_function_group( >>> def return_name(self): ... return self.name >>> - >>> opts = yr.FunctionGroupOptions( + >>> opts = yuanrong.FunctionGroupOptions( ... cpu=1000, ... memory=1000, ... resources={ @@ -101,13 +102,13 @@ def create_function_group( ... scheduling_affinity_each_bundle_size=2, ... ) >>> name = "class_demo" - >>> function_group_handler = yr.fcc.create_function_group(Demo, args=(name, ), group_size=8, options=opts) + >>> function_group_handler = yuanrong.fcc.create_function_group(Demo, args=(name, ), group_size=8, options=opts) >>> objs = function_group_handler.return_name.invoke() - >>> results = yr.get(objs) + >>> results = yuanrong.get(objs) >>> assert results == [name for i in range(1, 9)] >>> function_group_handler.terminate() >>> - >>> yr.finalize() + >>> yuanrong.finalize() """ bundle_size = options.scheduling_affinity_each_bundle_size if bundle_size is None or bundle_size <= 0: @@ -123,7 +124,7 @@ def create_function_group( options.timeout = -1 if options.timeout != -1 and options.timeout < 0 or options.timeout > 0x7FFFFFFF: raise ValueError(f"invalid timeout {options.timeout} in FunctionGroupOptions, expect:-1, [0, 0x7FFFFFFF]") - opts = yr.InvokeOptions() + opts = yuanrong.InvokeOptions() opts.function_group_options = options opts.cpu = opts.cpu if options.cpu is None else options.cpu opts.memory = opts.memory if options.memory is None else options.memory @@ -136,7 +137,7 @@ def create_function_group( return proxy.get_function_group_handler() if isinstance(wrapper, function_proxy.FunctionProxy): return wrapper.options(opts).set_function_group_size(group_size).invoke(*args) - raise RuntimeError("function is not wrapped by @yr.invoke or @yr.instance") + raise RuntimeError("function is not wrapped by @yuanrong.invoke or @yuanrong.instance") def get_function_group_context() -> FunctionGroupContext: @@ -153,16 +154,16 @@ def get_function_group_context() -> FunctionGroupContext: The function group context, i.e., FunctionGroupContext. Examples: - >>> import yr - >>> yr.init() + >>> import yuanrong + >>> yuanrong.init() >>> - >>> @yr.invoke + >>> @yuanrong.invoke ... def demo_func(name): - ... context = yr.fcc.get_function_group_context() + ... context = yuanrong.fcc.get_function_group_context() ... print(context) ... return name >>> - >>> opts = yr.FunctionGroupOptions( + >>> opts = yuanrong.FunctionGroupOptions( ... cpu=1000, ... memory=1000, ... resources={ @@ -171,9 +172,9 @@ def get_function_group_context() -> FunctionGroupContext: ... scheduling_affinity_each_bundle_size=2, ... ) >>> name = "function_demo" - >>> objs = yr.fcc.create_function_group(demo_func, args=(name,), group_size=8, options=opts) - >>> rets = yr.get(objs) + >>> objs = yuanrong.fcc.create_function_group(demo_func, args=(name,), group_size=8, options=opts) + >>> rets = yuanrong.get(objs) >>> assert rets == [name for i in range(1, 9)] - >>> yr.finalize() + >>> yuanrong.finalize() """ return global_runtime.get_runtime().get_function_group_context() diff --git a/api/python/yr/fnruntime.pyx b/api/python/yuanrong/fnruntime.pyx similarity index 95% rename from api/python/yr/fnruntime.pyx rename to api/python/yuanrong/fnruntime.pyx index 4c534b10eec824c81dc24ff64fd72d548ba0ce74..27122fdb6a98001c0b81369d0fc3b9eafc410b4b 100644 --- a/api/python/yr/fnruntime.pyx +++ b/api/python/yuanrong/fnruntime.pyx @@ -32,28 +32,28 @@ from typing import List, Tuple, Union, Callable from cython.operator import dereference, postincrement from cpython.exc cimport PyErr_CheckSignals -import yr -from yr.config import SchedulingAffinityType, FunctionGroupOptions, ResourceGroupOptions, GroupOptions -from yr.common.types import GroupInfo, CommonStatus, Resource, Resources, BundleInfo, Option, RgInfo, ResourceGroupUnit -from yr.common import constants -from yr.common.utils import generate_random_id, create_new_event_loop -from yr.config_manager import ConfigManager -from yr.err_type import ErrorCode, ModuleCode, ErrorInfo -from yr.executor.executor import Executor -from yr.executor.instance_manager import InstanceManager, InstancePackage -from yr.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType, Signal -from yr.object_ref import ObjectRef -from yr import log -from yr.common.utils import GaugeData, UInt64CounterData, DoubleCounterData -from yr.device import DataType, DeviceBufferParam, DataInfo -from yr.runtime import (ExistenceOpt, WriteMode, CacheType, ConsistencyType, SetParam, MSetParam, CreateParam, +import yuanrong +from yuanrong.config import SchedulingAffinityType, FunctionGroupOptions, ResourceGroupOptions +from yuanrong.common.types import GroupInfo, CommonStatus, Resource, Resources, BundleInfo, Option, RgInfo, ResourceGroupUnit +from yuanrong.common import constants +from yuanrong.common.utils import generate_random_id, create_new_event_loop +from yuanrong.config_manager import ConfigManager +from yuanrong.err_type import ErrorCode, ModuleCode, ErrorInfo +from yuanrong.executor.executor import Executor +from yuanrong.executor.instance_manager import InstanceManager, InstancePackage +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType, Signal +from yuanrong.object_ref import ObjectRef +from yuanrong import log +from yuanrong.common.utils import GaugeData, UInt64CounterData, DoubleCounterData +from yuanrong.device import DataType, DeviceBufferParam, DataInfo +from yuanrong.runtime import (ExistenceOpt, WriteMode, CacheType, ConsistencyType, SetParam, MSetParam, CreateParam, GetParam, GetParams, AlarmInfo, AlarmSeverity) -from yr import runtime_env -from yr.exception import YRInvokeError -from yr.stream import (Element, ProducerConfig, SubscriptionConfig, +from yuanrong import runtime_env +from yuanrong.exception import YRInvokeError +from yuanrong.stream import (Element, ProducerConfig, SubscriptionConfig, SubscriptionType) -from yr.accelerate.shm_broadcast import Handle, MessageQueue, decode, ResponseStatus -from yr.accelerate.executor import ACCELERATE_WORKER, Worker +from yuanrong.accelerate.shm_broadcast import Handle, MessageQueue, decode, ResponseStatus +from yuanrong.accelerate.executor import ACCELERATE_WORKER, Worker from cpython cimport PyBytes_FromStringAndSize from libc.stdint cimport uint64_t from libcpp cimport bool @@ -64,11 +64,11 @@ from libcpp.unordered_map cimport unordered_map from libcpp.unordered_set cimport unordered_set from libcpp.vector cimport vector -from yr.includes.libruntime cimport (CApiType, CSignal, CBuffer, CDataObject, CElement, +from yuanrong.includes.libruntime cimport (CApiType, CSignal, CBuffer, CDataObject, CElement, CErrorCode, CErrorInfo, CFunctionMeta, CInternalWaitResult, CInvokeArg, CInvokeOptions, CInvokeType, CModuleCode, CLanguageType, CLibruntimeConfig, -CLibruntimeManager,move,CLibruntime, CGroupOptions, +CLibruntimeManager,move,CLibruntime, CProducerConf, CStreamConsumer, CStreamProducer, CSubscriptionConfig, CSubscriptionType, @@ -272,17 +272,6 @@ cdef CSetParam set_param_from_py(set_param: SetParam): param.existence = CExistenceOpt.NONE else: param.existence = CExistenceOpt.NX - - if set_param.write_mode == WriteMode.NONE_L2_CACHE: - param.writeMode = CWriteMode.NONE_L2_CACHE - elif set_param.write_mode == WriteMode.WRITE_THROUGH_L2_CACHE: - param.writeMode = CWriteMode.WRITE_THROUGH_L2_CACHE - elif set_param.write_mode == WriteMode.WRITE_BACK_L2_CACHE: - param.writeMode = CWriteMode.WRITE_BACK_L2_CACHE - elif set_param.write_mode == WriteMode.NONE_L2_CACHE_EVICT: - param.writeMode = CWriteMode.NONE_L2_CACHE_EVICT - else: - param.writeMode = CWriteMode.NONE_L2_CACHE param.ttlSecond = set_param.ttl_second if set_param.cache_type == CacheType.MEMORY: @@ -352,15 +341,6 @@ cdef CGetParams get_params_from_py(params: GetParams): c_get_params.getParams.push_back(c_get_param) return c_get_params -cdef CGroupOptions group_options_from_py(group_name: str, group_opts: GroupOptions): - cdef: - CGroupOptions c_group_options - c_group_options.groupName = group_name.encode() - c_group_options.timeout = group_opts.timeout - c_group_options.sameLifecycle = group_opts.same_lifecycle - c_group_options.strategy = group_opts.strategy - return c_group_options - cdef CFunctionGroupOptions function_group_options_from_py(function_group_opts: FunctionGroupOptions, group_size: int): cdef: CFunctionGroupOptions c_function_group_options @@ -423,15 +403,15 @@ cdef function_meta_from_cpp(const CFunctionMeta & function): return func_meta cdef function_group_running_info_from_cpp(const CFunctionGroupRunningInfo & info): - context = yr.FunctionGroupContext() + context = yuanrong.FunctionGroupContext() context.rank_id = info.instanceRankId context.world_size = info.worldSize context.device_name = info.deviceName.decode() for i in range(info.serverList.size()): - server_info = yr.ServerInfo() + server_info = yuanrong.ServerInfo() server_info.server_id = info.serverList[i].serverId.decode() for j in range(info.serverList[i].devices.size()): - device_info = yr.DeviceInfo() + device_info = yuanrong.DeviceInfo() device_info.device_id = info.serverList[i].devices[j].deviceId device_info.device_ip = info.serverList[i].devices[j].deviceIp.decode() device_info.rank_id = info.serverList[i].devices[j].rankId @@ -559,7 +539,7 @@ def load_code_from_datasystem(code_id: str): f"failed to get object, " f"code: {ret.first.Code()}, module code {ret.first.MCode()}, msg: {ret.first.Msg().decode()}") it = ret.second.begin() - return yr.serialization.Serialization().deserialize(Buffer.make(dereference(it))) + return yuanrong.serialization.Serialization().deserialize(Buffer.make(dereference(it))) def write_to_cbuffer(serialized_object: SerializedObject): # This method is for unit test suite 'test_serialization' @@ -866,7 +846,7 @@ cdef CErrorInfo load_function_callback(const vector[string] & codePath) noexcept cdef CErrorInfo errorInfo with gil: code_paths = [codePath.at(i).decode() for i in range(codePath.size())] - error_info = yr.code_manager.CodeManager().load_functions(code_paths) + error_info = yuanrong.code_manager.CodeManager().load_functions(code_paths) errorInfo = error_info_from_py(error_info) return errorInfo @@ -916,7 +896,7 @@ def get_conda_bin_executable(executable_name: str) -> str: "please configure YR_CONDA_HOME environment variable which contain a bin subdirectory" ) -cdef parse_invoke_opts(CInvokeOptions & opts, opt: yr.InvokeOptions, group_info: GroupInfo = None): +cdef parse_invoke_opts(CInvokeOptions & opts, opt: yuanrong.InvokeOptions, group_info: GroupInfo = None): cdef: string concurrency_key = "Concurrency".encode() shared_ptr[CAffinity] c_affinity @@ -948,7 +928,6 @@ cdef parse_invoke_opts(CInvokeOptions & opts, opt: yr.InvokeOptions, group_info: opts.maxInstances = opt.max_instances opts.isDataAffinity = opt.is_data_affinity opts.resourceGroupOpts = resource_group_options_from_py(opt.resource_group_options) - opts.groupName = opt.group_name.encode() if group_info is not None: opts.functionGroupOpts = function_group_options_from_py(opt.function_group_options, group_info.group_size) opts.groupName = group_info.group_name.encode() @@ -977,7 +956,7 @@ cdef class Producer: ... delay_flush_time=5, ... auto_clean_up=True, ... ) - ... producer = yr.create_stream_producer("streamName", producer_config) + ... producer = yuanrong.create_stream_producer("streamName", producer_config) ... # ....... ... data = b"hello" ... element = Element(data=data, id=0) @@ -1322,7 +1301,7 @@ cdef class Fnruntime: def init(self, ctx): global _serialization_ctx _serialization_ctx = ctx - yr.code_manager.CodeManager().register_load_code_from_datasystem_func(load_code_from_datasystem) + yuanrong.code_manager.CodeManager().register_load_code_from_datasystem_func(load_code_from_datasystem) def receive_request_loop(self): with nogil: @@ -2492,7 +2471,7 @@ cdef class Fnruntime: ret = c_libruntime.get().GetNameSpace() return ret.decode() - def get_function_group_context(self) -> yr.FunctionGroupContext: + def get_function_group_context(self) -> yuanrong.FunctionGroupContext: cdef: CFunctionGroupRunningInfo info cdef shared_ptr[CLibruntime] c_libruntime = CLibruntimeManager.Instance().GetLibRuntime() @@ -2505,7 +2484,7 @@ cdef class Fnruntime: def get_instance_by_name(self, name, ns, timeout): cdef: pair[CFunctionMeta, CErrorInfo] ret - string cinstanceID + string cinstanceID = (ns + "-" + name if ns else name).encode() int sigNo = CSignal.KILLINSTANCESYNC string cname = name.encode() string cns = ns.encode() @@ -2513,8 +2492,6 @@ cdef class Fnruntime: cdef shared_ptr[CLibruntime] c_libruntime = CLibruntimeManager.Instance().GetLibRuntime() if c_libruntime == nullptr: raise RuntimeError("already finalized") - yr_ns = self.get_namespace() - cinstanceID = (ns + "-" + name if ns else yr_ns + "-" + name).encode() with nogil: c_libruntime.get().SetTenantIdWithPriority() ret = c_libruntime.get().GetInstance(cname, cns, ctimeout) @@ -2596,48 +2573,6 @@ cdef class Fnruntime: with nogil: ret = CLibruntimeManager.Instance().GetLibRuntime().get().AddReturnObject(c_obj_ids) return ret - - def create_group(self, group_name: str, group_opts: GroupOptions): - cdef: - string c_group_name = group_name.encode() - CGroupOptions c_group_options - c_group_options = group_options_from_py(group_name, group_opts) - with nogil: - ret = CLibruntimeManager.Instance().GetLibRuntime().get().GroupCreate(c_group_name, c_group_options) - if not ret.OK(): - raise RuntimeError( - f"failed to create group, code: {ret.Code()}, " - f"module code: {ret.MCode()}, msg: {ret.Msg().decode()}") - - def wait_group(self, group_name: str): - cdef: - string c_group_name = group_name.encode() - with nogil: - ret = CLibruntimeManager.Instance().GetLibRuntime().get().GroupWait(c_group_name) - if not ret.OK(): - raise RuntimeError( - f"failed to wait group, code: {ret.Code()}, " - f"module code: {ret.MCode()}, msg: {ret.Msg().decode()}") - - def suspend_group(self, group_name: str): - cdef: - string c_group_name = group_name.encode() - with nogil: - ret = CLibruntimeManager.Instance().GetLibRuntime().get().GroupSuspend(c_group_name) - if not ret.OK(): - raise RuntimeError( - f"failed to suspend group, code: {ret.Code()}, " - f"module code: {ret.MCode()}, msg: {ret.Msg().decode()}") - - def resume_group(self, group_name: str): - cdef: - string c_group_name = group_name.encode() - with nogil: - ret = CLibruntimeManager.Instance().GetLibRuntime().get().GroupResume(c_group_name) - if not ret.OK(): - raise RuntimeError( - f"failed to resume group, code: {ret.Code()}, " - f"module code: {ret.MCode()}, msg: {ret.Msg().decode()}") def notify_generator_result(generator_id, index, output, error_info): diff --git a/api/python/yr/functionsdk/__init__.py b/api/python/yuanrong/functionsdk/__init__.py similarity index 100% rename from api/python/yr/functionsdk/__init__.py rename to api/python/yuanrong/functionsdk/__init__.py diff --git a/api/python/yr/functionsdk/context.py b/api/python/yuanrong/functionsdk/context.py similarity index 99% rename from api/python/yr/functionsdk/context.py rename to api/python/yuanrong/functionsdk/context.py index 0f3646c798de650966b08a8e4087db7c0623813f..410a6d0e851192fdd397e8d2a50d611548084a2d 100644 --- a/api/python/yr/functionsdk/context.py +++ b/api/python/yuanrong/functionsdk/context.py @@ -22,9 +22,9 @@ import os import time from typing import Any, Dict -from yr import log -from yr.common import constants -from yr.functionsdk.utils import parse_json_data_to_dict, dump_data_to_json_str +from yuanrong import log +from yuanrong.common import constants +from yuanrong.functionsdk.utils import parse_json_data_to_dict, dump_data_to_json_str _RUNTIME_MAX_RESP_BODY_SIZE = 6 * 1024 * 1024 _RUNTIME_CODE_ROOT = "/opt/function/code" diff --git a/api/python/yr/functionsdk/error_code.py b/api/python/yuanrong/functionsdk/error_code.py similarity index 100% rename from api/python/yr/functionsdk/error_code.py rename to api/python/yuanrong/functionsdk/error_code.py diff --git a/api/python/yr/functionsdk/function.py b/api/python/yuanrong/functionsdk/function.py similarity index 96% rename from api/python/yr/functionsdk/function.py rename to api/python/yuanrong/functionsdk/function.py index 13df03c6671ac726ff4ac9fe61349c97e7ab9caf..d41d4c2fa5332ea5e92f4b1e97c28d936d33efa9 100644 --- a/api/python/yr/functionsdk/function.py +++ b/api/python/yuanrong/functionsdk/function.py @@ -22,14 +22,14 @@ import os import re from typing import Tuple, Union, Dict, List -from yr import log -from yr.config import InvokeOptions as YRInvokeOptions -from yr.common import constants -from yr.common.constants import META_PREFIX -from yr.libruntime_pb2 import ApiType, FunctionMeta, LanguageType -from yr.object_ref import ObjectRef -from yr.runtime_holder import global_runtime -from yr.functionsdk.context import Context +from yuanrong import log +from yuanrong.config import InvokeOptions as YRInvokeOptions +from yuanrong.common import constants +from yuanrong.common.constants import META_PREFIX +from yuanrong.libruntime_pb2 import ApiType, FunctionMeta, LanguageType +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime_holder import global_runtime +from yuanrong.functionsdk.context import Context DEFAULT_FUNCTION_VERSION = "latest" DEFAULT_INVOKE_TIMEOUT = 900 @@ -288,7 +288,7 @@ def _check_reg_length(name: str, pattern: str, length_limit: int): def _convert_invoke_options(options: InvokeOptions, context: Context) -> YRInvokeOptions: - """convert invoke options to yr options""" + """convert invoke options to yuanrong options""" if options.concurrency == 0: options.concurrency = 100 yr_options = YRInvokeOptions() diff --git a/api/python/yr/functionsdk/logger.py b/api/python/yuanrong/functionsdk/logger.py similarity index 98% rename from api/python/yr/functionsdk/logger.py rename to api/python/yuanrong/functionsdk/logger.py index 4b750f6483b1d21e217beb3039f8b935a067fd86..8f2a586305c594831861a4f21ee5402a3fc1e7b4 100644 --- a/api/python/yr/functionsdk/logger.py +++ b/api/python/yuanrong/functionsdk/logger.py @@ -22,7 +22,7 @@ import logging.handlers import os import shutil -from yr.log import CustomFilter, RuntimeLogger +from yuanrong.log import CustomFilter, RuntimeLogger LOG_DEFAULT_MAX_BYTES = 50 * 1024 * 1024 LOG_DEFAULT_BACKUP_COUNT = 3 diff --git a/api/python/yr/functionsdk/logger_manager.py b/api/python/yuanrong/functionsdk/logger_manager.py similarity index 98% rename from api/python/yr/functionsdk/logger_manager.py rename to api/python/yuanrong/functionsdk/logger_manager.py index a6b8a5ac6a5de0e6a371c461eea6349217cd990f..2729c9db77f34069811d01b47ca288b1834416e5 100644 --- a/api/python/yr/functionsdk/logger_manager.py +++ b/api/python/yuanrong/functionsdk/logger_manager.py @@ -21,8 +21,8 @@ import socket import threading from queue import Queue -from yr.common.singleton import Singleton -from yr.functionsdk import logger +from yuanrong.common.singleton import Singleton +from yuanrong.functionsdk import logger class Log: diff --git a/api/python/yr/functionsdk/utils.py b/api/python/yuanrong/functionsdk/utils.py similarity index 100% rename from api/python/yr/functionsdk/utils.py rename to api/python/yuanrong/functionsdk/utils.py diff --git a/api/python/yr/generator.py b/api/python/yuanrong/generator.py similarity index 96% rename from api/python/yr/generator.py rename to api/python/yuanrong/generator.py index 0ca6a32b27dba13f792dd682bcd383fc74d6cf64..1af7553e8b20bfd0aa667199a569100ad1a63a61 100644 --- a/api/python/yr/generator.py +++ b/api/python/yuanrong/generator.py @@ -18,10 +18,10 @@ import asyncio import logging from typing import Optional -from yr.object_ref import ObjectRef -from yr.runtime_holder import global_runtime -from yr.fnruntime import GeneratorEndError -from yr.exception import GeneratorFinished +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime_holder import global_runtime +from yuanrong.fnruntime import GeneratorEndError +from yuanrong.exception import GeneratorFinished _logger = logging.getLogger(__name__) diff --git a/api/python/yr/group.py b/api/python/yuanrong/group.py similarity index 94% rename from api/python/yr/group.py rename to api/python/yuanrong/group.py index 921e00b62e792cade18d5e8c583c07441b33f766..9350d1b92fa977b1993c3be2dea0063d8b9d2986 100644 --- a/api/python/yr/group.py +++ b/api/python/yuanrong/group.py @@ -15,8 +15,8 @@ # limitations under the License. from dataclasses import dataclass -from yr.config import GroupOptions -from yr import log, runtime_holder +from yuanrong.config import GroupOptions +from yuanrong import log, runtime_holder @dataclass diff --git a/api/python/yr/includes/__init__.pxd b/api/python/yuanrong/includes/__init__.pxd similarity index 100% rename from api/python/yr/includes/__init__.pxd rename to api/python/yuanrong/includes/__init__.pxd diff --git a/api/python/yr/includes/affinity.pxd b/api/python/yuanrong/includes/affinity.pxd similarity index 100% rename from api/python/yr/includes/affinity.pxd rename to api/python/yuanrong/includes/affinity.pxd diff --git a/api/python/yr/includes/affinity.pxi b/api/python/yuanrong/includes/affinity.pxi similarity index 100% rename from api/python/yr/includes/affinity.pxi rename to api/python/yuanrong/includes/affinity.pxi diff --git a/api/python/yr/includes/buffer.pxi b/api/python/yuanrong/includes/buffer.pxi similarity index 100% rename from api/python/yr/includes/buffer.pxi rename to api/python/yuanrong/includes/buffer.pxi diff --git a/api/python/yr/includes/libruntime.pxd b/api/python/yuanrong/includes/libruntime.pxd similarity index 99% rename from api/python/yr/includes/libruntime.pxd rename to api/python/yuanrong/includes/libruntime.pxd index 6a87ffdca42623813277a472fe3a3c6aa877d9dc..7273e133a0415628e9f7ca74f2afde07ae3f22d1 100644 --- a/api/python/yr/includes/libruntime.pxd +++ b/api/python/yuanrong/includes/libruntime.pxd @@ -24,7 +24,7 @@ from libcpp.memory cimport shared_ptr from libcpp.optional cimport optional from libcpp.unordered_set cimport unordered_set from libcpp.unordered_map cimport unordered_map -from yr.includes.affinity cimport CAffinity +from yuanrong.includes.affinity cimport CAffinity ctypedef void (*CWaitAsyncCallback) (const string & object_id, const CErrorInfo & error, void *userData) ctypedef void (*CGetAsyncCallback) (shared_ptr[CDataObject] data, const CErrorInfo & error, void *userData) diff --git a/api/python/yr/includes/libruntime.pxi b/api/python/yuanrong/includes/libruntime.pxi similarity index 100% rename from api/python/yr/includes/libruntime.pxi rename to api/python/yuanrong/includes/libruntime.pxi diff --git a/api/python/yr/includes/serialization.pxi b/api/python/yuanrong/includes/serialization.pxi similarity index 100% rename from api/python/yr/includes/serialization.pxi rename to api/python/yuanrong/includes/serialization.pxi diff --git a/api/python/yr/local_mode/__init__.py b/api/python/yuanrong/local_mode/__init__.py similarity index 100% rename from api/python/yr/local_mode/__init__.py rename to api/python/yuanrong/local_mode/__init__.py diff --git a/api/python/yr/local_mode/dependency_manager.py b/api/python/yuanrong/local_mode/dependency_manager.py similarity index 94% rename from api/python/yr/local_mode/dependency_manager.py rename to api/python/yuanrong/local_mode/dependency_manager.py index 39bdaf5a4428151eb4dd05894b5d1078b60666b4..bfa83bc26fd6b0cf6537ff42b96346b979af6b8a 100644 --- a/api/python/yr/local_mode/dependency_manager.py +++ b/api/python/yuanrong/local_mode/dependency_manager.py @@ -23,9 +23,9 @@ import logging from dataclasses import dataclass from typing import Union, List, Callable, Optional -from yr.local_mode.task_spec import TaskSpec -from yr.object_ref import ObjectRef -from yr.runtime_holder import global_runtime +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime_holder import global_runtime _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/instance.py b/api/python/yuanrong/local_mode/instance.py similarity index 100% rename from api/python/yr/local_mode/instance.py rename to api/python/yuanrong/local_mode/instance.py diff --git a/api/python/yr/local_mode/instance_manager.py b/api/python/yuanrong/local_mode/instance_manager.py similarity index 94% rename from api/python/yr/local_mode/instance_manager.py rename to api/python/yuanrong/local_mode/instance_manager.py index ba2c0f1791f7491dfd9911e64e30b63ed2fe4529..8ad6208304c6d6250e6eff6cea5b4ca2e1a12dbb 100644 --- a/api/python/yr/local_mode/instance_manager.py +++ b/api/python/yuanrong/local_mode/instance_manager.py @@ -23,16 +23,16 @@ from collections import OrderedDict, defaultdict from concurrent.futures import Future from typing import Optional, List, Tuple -from yr.common.utils import generate_task_id, generate_random_id +from yuanrong.common.utils import generate_task_id, generate_random_id -from yr.exception import YRInvokeError +from yuanrong.exception import YRInvokeError -from yr.libruntime_pb2 import InvokeType -from yr.local_mode.instance import Resource, Instance -from yr.local_mode.local_object_store import LocalObjectStore -from yr.local_mode.scheduler import Scheduler -from yr.local_mode.task_spec import TaskSpec -from yr.local_mode.timer import Timer +from yuanrong.libruntime_pb2 import InvokeType +from yuanrong.local_mode.instance import Resource, Instance +from yuanrong.local_mode.local_object_store import LocalObjectStore +from yuanrong.local_mode.scheduler import Scheduler +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.local_mode.timer import Timer _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/local_client.py b/api/python/yuanrong/local_mode/local_client.py similarity index 92% rename from api/python/yr/local_mode/local_client.py rename to api/python/yuanrong/local_mode/local_client.py index 958fa0d150a7aac58773b6a261ce1beaa1396585..a7e32a61aced02315e839f54d57ddb0ad5c816b9 100644 --- a/api/python/yr/local_mode/local_client.py +++ b/api/python/yuanrong/local_mode/local_client.py @@ -18,10 +18,10 @@ import logging import threading -from yr.common.utils import generate_random_id -from yr.local_mode.local_object_store import LocalObjectStore -from yr.local_mode.task_spec import TaskSpec -from yr.local_mode.worker import Worker +from yuanrong.common.utils import generate_random_id +from yuanrong.local_mode.local_object_store import LocalObjectStore +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.local_mode.worker import Worker _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/local_mode_runtime.py b/api/python/yuanrong/local_mode/local_mode_runtime.py similarity index 95% rename from api/python/yr/local_mode/local_mode_runtime.py rename to api/python/yuanrong/local_mode/local_mode_runtime.py index 962e0424b4d52b807b0d6aedd89bddee9f49ceef..b4af10e6264930a9e19d10d17061c817d80507c8 100644 --- a/api/python/yr/local_mode/local_mode_runtime.py +++ b/api/python/yuanrong/local_mode/local_mode_runtime.py @@ -21,23 +21,23 @@ from abc import ABC from concurrent import futures from concurrent.futures import Future from typing import Union, Dict, List, Any, Tuple, Callable -from yr.accelerate.shm_broadcast import Handle -from yr.common.types import GroupInfo -from yr.config import InvokeOptions, GroupOptions -from yr.exception import YRInvokeError -from yr.stream import ProducerConfig, SubscriptionConfig -from yr.common.utils import ( +from yuanrong.accelerate.shm_broadcast import Handle +from yuanrong.common.types import GroupInfo +from yuanrong.config import InvokeOptions, GroupOptions +from yuanrong.exception import YRInvokeError +from yuanrong.stream import ProducerConfig, SubscriptionConfig +from yuanrong.common.utils import ( generate_random_id, generate_task_id, GaugeData, UInt64CounterData, DoubleCounterData ) -from yr.fnruntime import Producer, Consumer -from yr.local_mode.local_client import LocalClient -from yr.local_mode.local_object_store import LocalObjectStore -from yr.local_mode.task_manager import TaskManager -from yr.libruntime_pb2 import FunctionMeta, InvokeType -from yr.local_mode.task_spec import TaskSpec +from yuanrong.fnruntime import Producer, Consumer +from yuanrong.local_mode.local_client import LocalClient +from yuanrong.local_mode.local_object_store import LocalObjectStore +from yuanrong.local_mode.task_manager import TaskManager +from yuanrong.libruntime_pb2 import FunctionMeta, InvokeType +from yuanrong.local_mode.task_spec import TaskSpec -from yr.runtime import Runtime, AlarmInfo, SetParam, MSetParam, CreateParam, GetParams -from yr.fnruntime import SharedBuffer +from yuanrong.runtime import Runtime, AlarmInfo, SetParam, MSetParam, CreateParam, GetParams +from yuanrong.fnruntime import SharedBuffer _logger = logging.getLogger(__name__) @@ -453,10 +453,10 @@ class LocalModeRuntime(Runtime, ABC): RuntimeError: The name of ResourceGroup is invalid. Examples: - >>> yr.remove_resource_group("rgname") + >>> yuanrong.remove_resource_group("rgname") >>> - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") - >>> yr.remove_resource_group(rg) + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> yuanrong.remove_resource_group(rg) """ raise RuntimeError("not support in local mode") diff --git a/api/python/yr/local_mode/local_object_store.py b/api/python/yuanrong/local_mode/local_object_store.py similarity index 99% rename from api/python/yr/local_mode/local_object_store.py rename to api/python/yuanrong/local_mode/local_object_store.py index 3d56aed46128d7b0a8f9a5c882ec23273f54c932..7343d34f4387178359adcf184a24c228aaa3a0d7 100644 --- a/api/python/yr/local_mode/local_object_store.py +++ b/api/python/yuanrong/local_mode/local_object_store.py @@ -19,7 +19,7 @@ import logging import threading from typing import List -from yr.common.singleton import Singleton +from yuanrong.common.singleton import Singleton _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/scheduler.py b/api/python/yuanrong/local_mode/scheduler.py similarity index 95% rename from api/python/yr/local_mode/scheduler.py rename to api/python/yuanrong/local_mode/scheduler.py index 33212211442e9cb445130ef331a01f921da3b0a4..5544e57ef7b85f01304802c8760179d3025a4a51 100644 --- a/api/python/yr/local_mode/scheduler.py +++ b/api/python/yuanrong/local_mode/scheduler.py @@ -19,8 +19,8 @@ from abc import abstractmethod, ABC from typing import Optional, Iterable, List -from yr.local_mode.instance import Instance -from yr.local_mode.task_spec import TaskSpec +from yuanrong.local_mode.instance import Instance +from yuanrong.local_mode.task_spec import TaskSpec class Scorer(ABC): diff --git a/api/python/yr/local_mode/task_manager.py b/api/python/yuanrong/local_mode/task_manager.py similarity index 93% rename from api/python/yr/local_mode/task_manager.py rename to api/python/yuanrong/local_mode/task_manager.py index adfc712733cc67ca9eefbde0781e9a96e0cb5745..8db2ee46b5282f9064ccdb8e2871e71f8b178286 100644 --- a/api/python/yr/local_mode/task_manager.py +++ b/api/python/yuanrong/local_mode/task_manager.py @@ -24,17 +24,17 @@ from threading import RLock, Lock, BoundedSemaphore, Thread from typing import List from typing import Optional -import yr.apis -from yr.exception import CancelError +import yuanrong.apis +from yuanrong.exception import CancelError -from yr.config import InvokeOptions -from yr.config_manager import ConfigManager -from yr.libruntime_pb2 import InvokeType -from yr.local_mode.instance import Resource, Instance -from yr.local_mode.instance_manager import InstanceManager -from yr.local_mode.scheduler import NormalScheduler, ConcurrencyScorer -from yr.local_mode.task_spec import TaskSpec -from yr.local_mode.timer import Timer +from yuanrong.config import InvokeOptions +from yuanrong.config_manager import ConfigManager +from yuanrong.libruntime_pb2 import InvokeType +from yuanrong.local_mode.instance import Resource, Instance +from yuanrong.local_mode.instance_manager import InstanceManager +from yuanrong.local_mode.scheduler import NormalScheduler, ConcurrencyScorer +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.local_mode.timer import Timer class TaskState(Enum): @@ -79,8 +79,8 @@ class TaskManager: def submit_task(self, task: TaskSpec): """submit task""" - if not yr.apis.is_initialized(): - _logger.warning("Can not submit task %s before yr.init", task.task_id) + if not yuanrong.apis.is_initialized(): + _logger.warning("Can not submit task %s before yuanrong.init", task.task_id) return if task.invoke_options: invoke_options = task.invoke_options diff --git a/api/python/yr/local_mode/task_spec.py b/api/python/yuanrong/local_mode/task_spec.py similarity index 91% rename from api/python/yr/local_mode/task_spec.py rename to api/python/yuanrong/local_mode/task_spec.py index e7ada53255955bfad1dc2d5b70a900f7092f7dd3..2f5278005084b96e83cbd8c3629061a82f5a69df 100644 --- a/api/python/yr/local_mode/task_spec.py +++ b/api/python/yuanrong/local_mode/task_spec.py @@ -21,8 +21,8 @@ from concurrent.futures import Future from dataclasses import dataclass, field from typing import List, Any -from yr.config import InvokeOptions -from yr.libruntime_pb2 import FunctionMeta, InvokeType +from yuanrong.config import InvokeOptions +from yuanrong.libruntime_pb2 import FunctionMeta, InvokeType _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/timer.py b/api/python/yuanrong/local_mode/timer.py similarity index 98% rename from api/python/yr/local_mode/timer.py rename to api/python/yuanrong/local_mode/timer.py index 47f23a22104b5bab505d71c3a822bb430c15d658..5d4d852e17733f4ed1234bd29207dfbe96eb3401 100644 --- a/api/python/yr/local_mode/timer.py +++ b/api/python/yuanrong/local_mode/timer.py @@ -21,7 +21,7 @@ import time from threading import Thread from typing import Callable -from yr.common.singleton import Singleton +from yuanrong.common.singleton import Singleton _logger = logging.getLogger(__name__) diff --git a/api/python/yr/local_mode/worker.py b/api/python/yuanrong/local_mode/worker.py similarity index 93% rename from api/python/yr/local_mode/worker.py rename to api/python/yuanrong/local_mode/worker.py index a52e2bfc8ad9b960db2941c365714f0ef1f829ca..4c47a0b83c1389d98b6e7b07e09544aab3ff1535 100644 --- a/api/python/yr/local_mode/worker.py +++ b/api/python/yuanrong/local_mode/worker.py @@ -22,14 +22,14 @@ import threading import traceback from typing import Iterable -import yr +import yuanrong -from yr import signature -from yr.exception import YRInvokeError, YRError -from yr.libruntime_pb2 import InvokeType -from yr.local_mode.local_object_store import LocalObjectStore -from yr.local_mode.task_spec import TaskSpec -from yr.object_ref import ObjectRef +from yuanrong import signature +from yuanrong.exception import YRInvokeError, YRError +from yuanrong.libruntime_pb2 import InvokeType +from yuanrong.local_mode.local_object_store import LocalObjectStore +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.object_ref import ObjectRef _logger = logging.getLogger(__name__) @@ -135,7 +135,7 @@ def _normal_function(task: TaskSpec, *args, **kwargs): def _process_args(args_list): def func(arg): if isinstance(arg, ObjectRef): - return yr.get(arg) + return yuanrong.get(arg) return arg return list(map(func, args_list)) diff --git a/api/python/yr/log.py b/api/python/yuanrong/log.py similarity index 98% rename from api/python/yr/log.py rename to api/python/yuanrong/log.py index 0838cac718ee8531cf773549cdd26883229ae306..928bbe18a207d379469d2c2d8ae972f0bcef6491 100644 --- a/api/python/yr/log.py +++ b/api/python/yuanrong/log.py @@ -25,12 +25,12 @@ import time from logging import Logger import logging.config -from yr.common.singleton import Singleton +from yuanrong.common.singleton import Singleton # MAX_ROW_SIZE max row size of a log _MAX_ROW_SIZE = 1024 * 1024 # python runtime log location -_BASE_LOG_NAME = "yr" +_BASE_LOG_NAME = "yuanrong" _LOG_SUFFIX = "_runtime.log" diff --git a/api/python/yr/main/__init__.py b/api/python/yuanrong/main/__init__.py similarity index 100% rename from api/python/yr/main/__init__.py rename to api/python/yuanrong/main/__init__.py diff --git a/api/python/yr/main/yr_runtime_main.py b/api/python/yuanrong/main/yr_runtime_main.py similarity index 94% rename from api/python/yr/main/yr_runtime_main.py rename to api/python/yuanrong/main/yr_runtime_main.py index df5d743a3fad748cf3a879abca178acbb5298091..805b31e4234f2cc9cd1c5a94ff1422ed16fc68d2 100644 --- a/api/python/yr/main/yr_runtime_main.py +++ b/api/python/yuanrong/main/yr_runtime_main.py @@ -14,17 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""yr runtime main""" +"""yuanrong runtime main""" import argparse import json import os import sys -from yr import init, log -from yr.apis import receive_request_loop -from yr.config import Config -from yr.common.utils import try_install_uvloop +from yuanrong import init, log +from yuanrong.apis import receive_request_loop +from yuanrong.config import Config +from yuanrong.common.utils import try_install_uvloop DEFAULT_LOG_DIR = "/home/snuser/log/" _ENV_KEY_FUNCTION_LIB_PATH = "YR_FUNCTION_LIB_PATH" diff --git a/api/python/yr/metrics.py b/api/python/yuanrong/metrics.py similarity index 88% rename from api/python/yr/metrics.py rename to api/python/yuanrong/metrics.py index b651b575654f73847c1dd75a0bf2af687e5ade8f..3c3df2be0ec14defee0b1b9bd53c699390f44445 100644 --- a/api/python/yr/metrics.py +++ b/api/python/yuanrong/metrics.py @@ -18,10 +18,10 @@ import re from dataclasses import field from typing import Dict -from yr.config_manager import ConfigManager -from yr.runtime import AlarmInfo -from yr.runtime_holder import global_runtime -from yr.common.utils import GaugeData, UInt64CounterData, DoubleCounterData +from yuanrong.config_manager import ConfigManager +from yuanrong.runtime import AlarmInfo +from yuanrong.runtime_holder import global_runtime +from yuanrong.common.utils import GaugeData, UInt64CounterData, DoubleCounterData _METRIC_NAME_RE = re.compile(r'^[a-zA-Z_:][a-zA-Z0-9_:]*$') _METRIC_LABEL_NAME_RE = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$') @@ -90,15 +90,15 @@ class Gauge(Metrics): ValueError: Labels are missing, or the data does not conform to Prometheus standard requirements. Example: - >>> import yr - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> import yuanrong + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) - >>> @yr.instance + >>> @yuanrong.instance ... class GaugeActor: ... def __init__(self): ... self.labels = {"key1": "value1"} - ... self.gauge = yr.Gauge( + ... self.gauge = yuanrong.Gauge( ... name="test", ... description="", ... unit="ms", @@ -116,7 +116,7 @@ class Gauge(Metrics): >>> >>> actor = GaugeActor.options(name="gauge_actor").invoke() >>> result = actor.set_value.invoke(75) - >>> print("Driver got:", yr.get(result)) + >>> print("Driver got:", yuanrong.get(result)) """ self._check_label(labels) @@ -137,15 +137,15 @@ class Gauge(Metrics): (such as reporting data types other than float). Example: - >>> import yr - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> import yuanrong + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) >>> - >>> @yr.instance + >>> @yuanrong.instance ... class GaugeActor: ... def __init__(self): ... self.labels = {"key1": "value1"} - ... self.gauge = yr.Gauge( + ... self.gauge = yuanrong.Gauge( ... name="test", ... description="", ... unit="ms", @@ -165,7 +165,7 @@ class Gauge(Metrics): >>> actor = GaugeActor.options(name="gauge_actor").invoke() >>> >>> result = actor.set_value.invoke(75) - >>> print(yr.get(result)) + >>> print(yuanrong.get(result)) """ fvalue = float(value) if ConfigManager().is_driver: @@ -210,16 +210,16 @@ class UInt64Counter(Metrics): ValueError: If the label is empty or does not meet the data type requirements. Example: - >>> import yr + >>> import yuanrong >>> - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) >>> - >>> @yr.instance + >>> @yuanrong.instance >>> class Actor: ... def __init__(self): ... labels = {"key1": "value1", "key2": "value2"} - ... self.data = yr.UInt64Counter( + ... self.data = yuanrong.UInt64Counter( ... name="test", ... description="", ... unit="ms", @@ -239,7 +239,7 @@ class UInt64Counter(Metrics): ... return msg >>> >>> actor1 = Actor.options(name="actor").invoke() - >>> print(yr.get(actor1.run.invoke())) + >>> print(yuanrong.get(actor1.run.invoke())) """ self._check_label(labels) @@ -259,14 +259,14 @@ class UInt64Counter(Metrics): ValueError: Invoked in the driver. Example: - >>> import yr - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> import yuanrong + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) >>> - >>> @yr.instance + >>> @yuanrong.instance ... class MyActor: ... def __init__(self): - ... self.data = yr.UInt64Counter( + ... self.data = yuanrong.UInt64Counter( ... "userFuncTime", ... "user function cost time", ... "ms", @@ -289,7 +289,7 @@ class UInt64Counter(Metrics): ... } >>> actor = MyActor.options(name="actor").invoke() >>> result = actor.add.invoke(5) - >>> print(yr.get(result)) + >>> print(yuanrong.get(result)) """ ivalue = int(value) if ConfigManager().is_driver: @@ -358,15 +358,15 @@ class DoubleCounter(Metrics): ValueError: If the labels are empty. Example: - >>> import yr + >>> import yuanrong >>> - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) >>> - >>> @yr.instance + >>> @yuanrong.instance >>> class Actor: >>> def __init__(self): - >>> self.data = yr.DoubleCounter( + >>> self.data = yuanrong.DoubleCounter( >>> "userFuncTime", >>> "user function cost time", >>> "ms", @@ -386,7 +386,7 @@ class DoubleCounter(Metrics): >>> return msg >>> actor1 = Actor.options(name="actor").invoke() >>> result = actor1.run.invoke() - >>> print("run result:", yr.get(result)) + >>> print("run result:", yuanrong.get(result)) """ self._check_label(labels) if len(labels) == 0: @@ -405,15 +405,15 @@ class DoubleCounter(Metrics): ValueError: Invoked in the driver. Example: - >>> import yr - >>> config = yr.Config(enable_metrics=True) - >>> yr.init(config) + >>> import yuanrong + >>> config = yuanrong.Config(enable_metrics=True) + >>> yuanrong.init(config) >>> - >>> @yr.instance + >>> @yuanrong.instance >>> class Actor: >>> def __init__(self): >>> try: - >>> self.data = yr.DoubleCounter( + >>> self.data = yuanrong.DoubleCounter( >>> "userFuncTime", >>> "user function cost time", >>> "ms", @@ -489,13 +489,13 @@ class Alarm(Metrics): ValueError: If alarm_name is None. Example: - >>> import yr + >>> import yuanrong >>> import time - >>> config = yr.Config(enable_metrics=True) + >>> config = yuanrong.Config(enable_metrics=True) >>> config.log_level="DEBUG":378 - >>> yr.init(config) + >>> yuanrong.init(config) - >>> @yr.instance + >>> @yuanrong.instance >>> class Actor: >>> def __init__(self): >>> self.state = 0 @@ -504,8 +504,8 @@ class Alarm(Metrics): >>> def add(self, value): >>> self.state += value >>> if self.state > 10: - >>> alarm_info = yr.AlarmInfo(alarm_name="aad") - >>> alarm = yr.Alarm(self.name, description="") + >>> alarm_info = yuanrong.AlarmInfo(alarm_name="aad") + >>> alarm = yuanrong.Alarm(self.name, description="") >>> alarm.set(alarm_info) >>> return self.state >>> @@ -514,9 +514,9 @@ class Alarm(Metrics): >>> >>> actor1 = Actor.options(name="actor1").invoke() >>> - >>> print("actor1 add 5:", yr.get(actor1.add.invoke(5))) - >>> print("actor1 add 7:", yr.get(actor1.add.invoke(7))) - >>> print("actor1 state:", yr.get(actor1.get.invoke())) + >>> print("actor1 add 5:", yuanrong.get(actor1.add.invoke(5))) + >>> print("actor1 add 7:", yuanrong.get(actor1.add.invoke(7))) + >>> print("actor1 state:", yuanrong.get(actor1.get.invoke())) """ if ConfigManager().is_driver: raise ValueError("alarm metrics set not support in driver") diff --git a/api/python/yr/object_ref.py b/api/python/yuanrong/object_ref.py similarity index 92% rename from api/python/yr/object_ref.py rename to api/python/yuanrong/object_ref.py index 83212de9fb56cc6e040c4426ac140798c34b0fbd..017630ef60f10cc088c9df98c32dd4e08f753eaf 100644 --- a/api/python/yr/object_ref.py +++ b/api/python/yuanrong/object_ref.py @@ -21,12 +21,12 @@ import json from concurrent.futures import Future from typing import Any, Union -from yr.exception import YRInvokeError, YRError, GeneratorFinished -from yr.err_type import ErrorInfo, ErrorCode +from yuanrong.exception import YRInvokeError, YRError, GeneratorFinished +from yuanrong.err_type import ErrorInfo, ErrorCode -import yr -from yr import log -from yr.common import constants +import yuanrong +from yuanrong import log +from yuanrong.common import constants def _set_future_helper( @@ -66,12 +66,12 @@ class ObjectRef: self._need_decre = need_decre self._exception = exception self._data = None - global_runtime = yr.runtime_holder.global_runtime.get_runtime() + global_runtime = yuanrong.runtime_holder.global_runtime.get_runtime() if need_incre and global_runtime and exception is None: global_runtime.increase_global_reference([self._id]) def __del__(self): - global_runtime = yr.runtime_holder.global_runtime.get_runtime() + global_runtime = yuanrong.runtime_holder.global_runtime.get_runtime() if self._need_decre and global_runtime: global_runtime.decrease_global_reference([self._id]) @@ -197,7 +197,7 @@ class ObjectRef: Args: callback (Callable): User callback. """ - yr.runtime_holder.global_runtime.get_runtime().set_get_callback(self.id, callback) + yuanrong.runtime_holder.global_runtime.get_runtime().set_get_callback(self.id, callback) def get(self, timeout: int = constants.DEFAULT_GET_TIMEOUT) -> Any: """This function is used to retrieve an object. @@ -217,7 +217,7 @@ class ObjectRef: if timeout <= constants.MIN_TIMEOUT_LIMIT and timeout != constants.NO_LIMIT: raise ValueError("Parameter 'timeout' should be greater than 0 or equal to -1 (no timeout)") - objects = yr.runtime_holder.global_runtime.get_runtime().get([self.id], timeout, False) + objects = yuanrong.runtime_holder.global_runtime.get_runtime().get([self.id], timeout, False) result_str = objects[0] try: diff --git a/api/python/yr/resource_group.py b/api/python/yuanrong/resource_group.py similarity index 81% rename from api/python/yr/resource_group.py rename to api/python/yuanrong/resource_group.py index 9bb12a7b7f8c1f3b8e7a2e593365db25f8669723..555f6d5a21aae4ba5bee1a0d8da64217a6b6aff0 100644 --- a/api/python/yr/resource_group.py +++ b/api/python/yuanrong/resource_group.py @@ -16,8 +16,8 @@ from dataclasses import dataclass from typing import Dict, List, Optional -from yr.common import constants -from yr.runtime_holder import global_runtime +from yuanrong.common import constants +from yuanrong.runtime_holder import global_runtime @dataclass @@ -26,7 +26,7 @@ class ResourceGroup: The handle returned after creating a ResourceGroup. Examples: - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") """ def __init__( @@ -49,7 +49,7 @@ class ResourceGroup: All bundles under the current resource group.Data type is List[Dict]. Examples: - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") >>> bundles = rg.bundle_specs """ return self.bundles @@ -63,9 +63,9 @@ class ResourceGroup: Number of bundles in the current resource group. Data type is int. Examples: - >>> import yr - >>> yr.init() - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> import yuanrong + >>> yuanrong.init() + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") >>> count = rg.bundle_count >>> print(count) """ @@ -80,9 +80,9 @@ class ResourceGroup: Name of the current resource group. Data type is str. Examples: - >>> import yr - >>> yr.init() - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> import yuanrong + >>> yuanrong.init() + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") >>> name = rg.resource_group_name >>> print(name) """ @@ -101,7 +101,7 @@ class ResourceGroup: ValueError: Timeout is less than ``-1``. Examples: - >>> rg = yr.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") + >>> rg = yuanrong.create_resource_group([{"NPU":1},{"CPU":2000,"Memory":2000}], "rgname") >>> rg.wait(60) """ if timeout_seconds is None: diff --git a/api/python/yr/resource_group_ref.py b/api/python/yuanrong/resource_group_ref.py similarity index 93% rename from api/python/yr/resource_group_ref.py rename to api/python/yuanrong/resource_group_ref.py index 3c777a2c850cf77fca60c4a4ed304244ec76c7f8..f20ee59787ba96e53943604fd044a7d0213d7e1a 100644 --- a/api/python/yr/resource_group_ref.py +++ b/api/python/yuanrong/resource_group_ref.py @@ -16,8 +16,8 @@ """ObjectRef""" from typing import Optional -from yr.resource_group import ResourceGroup -from yr.fnruntime import write_to_cbuffer +from yuanrong.resource_group import ResourceGroup +from yuanrong.fnruntime import write_to_cbuffer class RgObjectRef: diff --git a/api/python/yr/runtime.py b/api/python/yuanrong/runtime.py similarity index 98% rename from api/python/yr/runtime.py rename to api/python/yuanrong/runtime.py index 95c11ce7e13fa6bd7d865c8a8c3b19b23aaff917..8a257cbcf1a4d70a5d7ef15aeea098894a8c6be5 100644 --- a/api/python/yr/runtime.py +++ b/api/python/yuanrong/runtime.py @@ -21,13 +21,13 @@ from dataclasses import dataclass, field from enum import Enum from typing import List, Tuple, Union, Any, Callable, Dict -from yr.common.types import GroupInfo -from yr.config import InvokeOptions, GroupOptions -from yr.libruntime_pb2 import FunctionMeta -from yr.fnruntime import SharedBuffer -from yr.common.utils import GaugeData, UInt64CounterData, DoubleCounterData -from yr.common import constants -from yr.accelerate.shm_broadcast import Handle +from yuanrong.common.types import GroupInfo +from yuanrong.config import InvokeOptions, GroupOptions +from yuanrong.libruntime_pb2 import FunctionMeta +from yuanrong.fnruntime import SharedBuffer +from yuanrong.common.utils import GaugeData, UInt64CounterData, DoubleCounterData +from yuanrong.common import constants +from yuanrong.accelerate.shm_broadcast import Handle class ExistenceOpt(Enum): diff --git a/api/python/yr/runtime_env.py b/api/python/yuanrong/runtime_env.py similarity index 99% rename from api/python/yr/runtime_env.py rename to api/python/yuanrong/runtime_env.py index 7b27d9435ada0ec50eef6961e6796950b8ef1a04..ef59b96518e88f43643ed31befaba92ce909b92f 100644 --- a/api/python/yr/runtime_env.py +++ b/api/python/yuanrong/runtime_env.py @@ -20,7 +20,7 @@ import uuid from pathlib import Path from typing import Dict -from yr.config import InvokeOptions +from yuanrong.config import InvokeOptions WORKING_DIR_KEY = "WORKING_DIR" CONDA_PREFIX = "CONDA_PREFIX" diff --git a/api/python/yr/runtime_holder.py b/api/python/yuanrong/runtime_holder.py similarity index 86% rename from api/python/yr/runtime_holder.py rename to api/python/yuanrong/runtime_holder.py index edf43862c903c497410d8fc1f2e21c16c77bed02..1f309ed4293acd97fe73bde40d4e2b7c1c69e961 100644 --- a/api/python/yr/runtime_holder.py +++ b/api/python/yuanrong/runtime_holder.py @@ -18,10 +18,10 @@ runtime holder """ -from yr.config_manager import ConfigManager -from yr.cluster_mode_runtime import ClusterModeRuntime -from yr.local_mode.local_mode_runtime import LocalModeRuntime -from yr.runtime import Runtime +from yuanrong.config_manager import ConfigManager +from yuanrong.cluster_mode_runtime import ClusterModeRuntime +from yuanrong.local_mode.local_mode_runtime import LocalModeRuntime +from yuanrong.runtime import Runtime class RuntimeHolder: @@ -56,7 +56,7 @@ def save_real_instance_id(instance_id, need_order): def init(runtime=global_runtime) -> None: """ - init yr + init yuanrong :param runtime: RuntimeHolder :return: None """ diff --git a/api/python/yr/serialization/__init__.py b/api/python/yuanrong/serialization/__init__.py similarity index 87% rename from api/python/yr/serialization/__init__.py rename to api/python/yuanrong/serialization/__init__.py index fd9f265cbb06ac9c41ae6ee7d17ad775384b7f62..49526800139b6b880d672a2e4194c84e75636f89 100644 --- a/api/python/yr/serialization/__init__.py +++ b/api/python/yuanrong/serialization/__init__.py @@ -15,6 +15,6 @@ # limitations under the License. """serialization""" -from yr.serialization.serialization import Serialization, register_pack_hook, register_unpack_hook +from yuanrong.serialization.serialization import Serialization, register_pack_hook, register_unpack_hook __all__ = ["Serialization", "register_pack_hook", "register_unpack_hook"] diff --git a/api/python/yr/serialization/serialization.py b/api/python/yuanrong/serialization/serialization.py similarity index 93% rename from api/python/yr/serialization/serialization.py rename to api/python/yuanrong/serialization/serialization.py index 8d9ba67b5bf6b3eb36559d3c73acb4a255fb4e2c..ef9f7f9f7ec21b599ce2b34d6db6b7a7169b6893 100644 --- a/api/python/yr/serialization/serialization.py +++ b/api/python/yuanrong/serialization/serialization.py @@ -18,11 +18,11 @@ import threading from typing import Any, List, Union -import yr -from yr.common import constants -from yr.common.singleton import Singleton -from yr.fnruntime import SerializedObject, split_buffer, Buffer -from yr.serialization.serializers import MessagePackSerializer, PySerializer, pop_local_object_refs +import yuanrong +from yuanrong.common import constants +from yuanrong.common.singleton import Singleton +from yuanrong.fnruntime import SerializedObject, split_buffer, Buffer +from yuanrong.serialization.serializers import MessagePackSerializer, PySerializer, pop_local_object_refs @Singleton @@ -109,7 +109,7 @@ class Serialization: object_refs = pop_local_object_refs() if len(object_refs) != 0: object_ref_ids = [ref.id for ref in object_refs] - yr.runtime_holder.global_runtime.get_runtime().increase_global_reference(object_ref_ids) + yuanrong.runtime_holder.global_runtime.get_runtime().increase_global_reference(object_ref_ids) return result[0] if is_buffer else result def register_pack_hook(self, hook): diff --git a/api/python/yr/serialization/serializers.py b/api/python/yuanrong/serialization/serializers.py similarity index 96% rename from api/python/yr/serialization/serializers.py rename to api/python/yuanrong/serialization/serializers.py index 72e3021dedcfd0fad02418ed63c747627c3b3cb2..33e512bd07b20020d01103ac3f604e7fdcf5369c 100644 --- a/api/python/yr/serialization/serializers.py +++ b/api/python/yuanrong/serialization/serializers.py @@ -22,17 +22,17 @@ import pickle import cloudpickle import msgpack -import yr -from yr import log -from yr.common.utils import NoGC, err_to_str -from yr.fnruntime import ( +import yuanrong +from yuanrong import log +from yuanrong.common.utils import NoGC, err_to_str +from yuanrong.fnruntime import ( Pickle5Writer, unpack_pickle5_buffers, Pickle5SerializedObject, RawSerializedObject, SerializedInterface ) -from yr.object_ref import ObjectRef +from yuanrong.object_ref import ObjectRef _EXT_TYPE_CODE = 101 _DEFAULT_PROTOCAL = 4 @@ -167,7 +167,7 @@ class PySerializer: obj = PySerializer._deserialize_to_pickle4(serialized_data) nested_refs = pop_local_object_refs() if len(nested_refs) != 0: - yr.runtime_holder.global_runtime.get_runtime().increase_global_reference([ref.id for ref in nested_refs]) + yuanrong.runtime_holder.global_runtime.get_runtime().increase_global_reference([ref.id for ref in nested_refs]) return obj @staticmethod diff --git a/api/python/yr/signature.py b/api/python/yuanrong/signature.py similarity index 100% rename from api/python/yr/signature.py rename to api/python/yuanrong/signature.py diff --git a/api/python/yr/stream.py b/api/python/yuanrong/stream.py similarity index 100% rename from api/python/yr/stream.py rename to api/python/yuanrong/stream.py diff --git a/api/python/yr/tests/BUILD.bazel b/api/python/yuanrong/tests/BUILD.bazel similarity index 100% rename from api/python/yr/tests/BUILD.bazel rename to api/python/yuanrong/tests/BUILD.bazel diff --git a/api/python/yr/tests/test_InvokeOptions.py b/api/python/yuanrong/tests/test_InvokeOptions.py similarity index 97% rename from api/python/yr/tests/test_InvokeOptions.py rename to api/python/yuanrong/tests/test_InvokeOptions.py index fc966126e8eba42852d786cc6ce74d100cd918f4..b91860baec6cdc560989cd50d37ff8f93c89512a 100644 --- a/api/python/yr/tests/test_InvokeOptions.py +++ b/api/python/yuanrong/tests/test_InvokeOptions.py @@ -15,16 +15,16 @@ # limitations under the License. import unittest -import yr +import yuanrong class TestInvokeOptions(unittest.TestCase): def setUp(self): - @yr.invoke + @yuanrong.invoke def add(x): return x + 1 self.add = add - self.opts = yr.InvokeOptions() + self.opts = yuanrong.InvokeOptions() def test_option_function_name(self): self.opts.name = 999 diff --git a/api/python/yr/tests/test_apis.py b/api/python/yuanrong/tests/test_apis.py similarity index 70% rename from api/python/yr/tests/test_apis.py rename to api/python/yuanrong/tests/test_apis.py index 6b0a23ce2f748e68122b2d1ac6bd43753f808dbd..f7f36d2b531297a063ecdbb77acbf820b60bc778 100644 --- a/api/python/yr/tests/test_apis.py +++ b/api/python/yuanrong/tests/test_apis.py @@ -20,27 +20,27 @@ from concurrent.futures import Future import cloudpickle import pytest -import yr -from yr import exception -from yr import fcc -from yr.config_manager import ConfigManager -from yr.config import FunctionGroupOptions -from yr.decorator import function_proxy, instance_proxy -from yr.runtime import AlarmInfo -from yr.object_ref import ObjectRef -from yr.config import InvokeOptions - - -@yr.invoke(return_nums=0) +import yuanrong +from yuanrong import exception +from yuanrong import fcc +from yuanrong.config_manager import ConfigManager +from yuanrong.config import FunctionGroupOptions +from yuanrong.decorator import function_proxy, instance_proxy +from yuanrong.runtime import AlarmInfo +from yuanrong.object_ref import ObjectRef +from yuanrong.config import InvokeOptions + + +@yuanrong.invoke(return_nums=0) def get(): """get""" return 1 -@yr.instance +@yuanrong.instance class Counter: """Counter""" - @yr.method(return_nums=0) + @yuanrong.method(return_nums=0) def get(self): """get""" return 1 @@ -51,15 +51,15 @@ class TestApi(unittest.TestCase): pass def test_yr_init_failed_when_input_invalid_address(self): - conf = yr.Config() - conf.function_id = "sn:cn:yrk:12345678901234561234567890123456:function:0-yr-test-config-init:$latest" + conf = yuanrong.Config() + conf.function_id = "sn:cn:yrk:12345678901234561234567890123456:function:0-yuanrong-test-config-init:$latest" conf.server_address = "127.0.0.1:11111" conf.in_cluster = False with self.assertRaises(ValueError): - yr.init(conf) + yuanrong.init(conf) - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_wait_when_input_list_return_in_order(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.wait.return_value = (["3", "2", "1"], []) @@ -67,12 +67,13 @@ class TestApi(unittest.TestCase): mock_runtime.decrease_global_reference.return_value = None get_runtime.return_value = mock_runtime is_initialized.return_value = True - refs = [yr.object_ref.ObjectRef("1"), yr.object_ref.ObjectRef("2"), yr.object_ref.ObjectRef("3")] - ready_refs, _ = yr.wait(refs) + refs = [yuanrong.object_ref.ObjectRef("1"), yuanrong.object_ref.ObjectRef("2"), + yuanrong.object_ref.ObjectRef("3")] + ready_refs, _ = yuanrong.wait(refs) assert ready_refs == refs - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_invoke_when_return_nums_is_0(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.invoke_by_name.return_value = ["1"] @@ -90,130 +91,130 @@ class TestApi(unittest.TestCase): assert c.get.invoke() is None def test_yr_init_failed_when_input_invaild_function_id(self): - conf = yr.Config() + conf = yuanrong.Config() conf.function_id = "111" conf.in_cluster = False with pytest.raises(ValueError): - yr.init(conf) + yuanrong.init(conf) def test_affinity(self): """ Test the init method of Affinity class. """ - affinity_kind = yr.AffinityKind.INSTANCE - affinity_type = yr.AffinityType.PREFERRED + affinity_kind = yuanrong.AffinityKind.INSTANCE + affinity_type = yuanrong.AffinityType.PREFERRED label_operators = [ - yr.LabelOperator(yr.OperatorType.LABEL_IN, "key", ["value1", "value2"]) + yuanrong.LabelOperator(yuanrong.OperatorType.LABEL_IN, "key", ["value1", "value2"]) ] - affinity = yr.Affinity(affinity_kind, affinity_type, label_operators) + affinity = yuanrong.Affinity(affinity_kind, affinity_type, label_operators) assert affinity_kind == affinity.affinity_kind assert affinity_type == affinity.affinity_type assert label_operators == affinity.label_operators - affinity_scope = yr.AffinityScope.NODE - affinity2 = yr.Affinity(affinity_kind, affinity_type, label_operators, affinity_scope) + affinity_scope = yuanrong.AffinityScope.NODE + affinity2 = yuanrong.Affinity(affinity_kind, affinity_type, label_operators, affinity_scope) assert affinity_scope == affinity2.affinity_scope - @patch("yr.apis.is_initialized") + @patch("yuanrong.apis.is_initialized") def test_cancel_with_invalid_value(self, is_initialized): is_initialized.return_value = True with pytest.raises(TypeError) as e: - yr.cancel("aaa") + yuanrong.cancel("aaa") print(e) assert e.value.__str__() == "obj_refs type error, actual: [], element expect: " with pytest.raises(TypeError) as e: - yr.cancel(["aaa"]) + yuanrong.cancel(["aaa"]) assert e.value.__str__() == "obj_refs type error, actual: [], element expect: " def test_double_counter(self): with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=True)) + yuanrong.init(yuanrong.Config(is_driver=True)) labels = {"key1": "value1", "key2": "value2"} - d = yr.DoubleCounter(name="test", description='', unit="ms", labels=labels) + d = yuanrong.DoubleCounter(name="test", description='', unit="ms", labels=labels) d.add_labels({"key3": "value3"}) with pytest.raises(ValueError) as e: d.set(100) assert e.value.__str__() == "double counter metrics set not support in driver" with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=False)) + yuanrong.init(yuanrong.Config(is_driver=False)) with pytest.raises(ValueError) as e: name = "*test" - d = yr.DoubleCounter(name=name, description='', unit="ms", labels=labels) + d = yuanrong.DoubleCounter(name=name, description='', unit="ms", labels=labels) d.set(100) assert e.value.__str__() == "invalid metric name: *test" with pytest.raises(ValueError) as e: - d = yr.DoubleCounter(name="test", description='', unit="ms", labels=labels) + d = yuanrong.DoubleCounter(name="test", description='', unit="ms", labels=labels) d.set("abc") assert e.value.__str__() == "could not convert string to float: 'abc'" def test_uint64_counter(self): with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=True)) + yuanrong.init(yuanrong.Config(is_driver=True)) labels = {"key1": "value1", "key2": "value2"} - u = yr.UInt64Counter(name="test", description='', unit="ms", labels=labels) + u = yuanrong.UInt64Counter(name="test", description='', unit="ms", labels=labels) u.add_labels({"key3": "value3"}) with pytest.raises(ValueError) as e: u.set(100) assert e.value.__str__() == "uint64 counter metrics set not support in driver" with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=False)) + yuanrong.init(yuanrong.Config(is_driver=False)) with pytest.raises(ValueError) as e: name = "*test" - u = yr.UInt64Counter(name=name, description='', unit="ms", labels=labels) + u = yuanrong.UInt64Counter(name=name, description='', unit="ms", labels=labels) u.set(100) assert e.value.__str__() == "invalid metric name: *test" with pytest.raises(ValueError) as e: - u = yr.UInt64Counter(name="test", description='', unit="ms", labels=labels) + u = yuanrong.UInt64Counter(name="test", description='', unit="ms", labels=labels) u.set("abc") assert e.value.__str__() == "invalid literal for int() with base 10: 'abc'" def test_gauge(self): with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=True)) + yuanrong.init(yuanrong.Config(is_driver=True)) labels = {"key1": "value1", "key2": "value2"} - g = yr.Gauge(name="test", description='', unit="ms", labels=labels) + g = yuanrong.Gauge(name="test", description='', unit="ms", labels=labels) g.add_labels({"key3": "value3"}) with pytest.raises(ValueError) as e: g.set(100) assert e.value.__str__() == "gauge metrics report not support in driver" with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=False)) + yuanrong.init(yuanrong.Config(is_driver=False)) with pytest.raises(ValueError) as e: name = "*test" - g = yr.Gauge(name=name, description='', unit="ms", labels=labels) + g = yuanrong.Gauge(name=name, description='', unit="ms", labels=labels) g.set(100) assert e.value.__str__() == "invalid metric name: *test" with pytest.raises(ValueError) as e: - g = yr.Gauge(name="test", description='', unit="ms", labels=labels) + g = yuanrong.Gauge(name="test", description='', unit="ms", labels=labels) g.set("abc") assert e.value.__str__() == "could not convert string to float: 'abc'" def test_alarm(self): with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=True)) + yuanrong.init(yuanrong.Config(is_driver=True)) alarm_info = AlarmInfo() - a = yr.Alarm(name="test", description='') + a = yuanrong.Alarm(name="test", description='') with pytest.raises(ValueError) as e: a.set(alarm_info) assert e.value.__str__() == "alarm metrics set not support in driver" with self.assertRaises(ValueError): - yr.init(yr.Config(is_driver=False)) + yuanrong.init(yuanrong.Config(is_driver=False)) with pytest.raises(ValueError) as e: name = "*test" - a = yr.Alarm(name=name, description='') + a = yuanrong.Alarm(name=name, description='') assert e.value.__str__() == "invalid metric name: *test" def test_serialize_instance_ok(self): - @yr.instance + @yuanrong.instance class Counter1: pass @@ -222,25 +223,25 @@ class TestApi(unittest.TestCase): assert type(b) == type(Counter1) assert type(b.__user_class__) == type(Counter1.__user_class__) - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_finalize(self, get_runtime): mock_runtime = Mock() mock_runtime.finalize.return_value = None mock_runtime.receive_request_loop.return_value = None mock_runtime.exit().return_value = None get_runtime.return_value = mock_runtime - yr.apis.set_initialized() - self.assertTrue(yr.apis.is_initialized()) - yr.finalize() - self.assertFalse(yr.apis.is_initialized()) - yr.apis.set_initialized() - yr.exit() - yr.finalize() - yr.apis.receive_request_loop() - self.assertFalse(yr.apis.is_initialized()) - - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + yuanrong.apis.set_initialized() + self.assertTrue(yuanrong.apis.is_initialized()) + yuanrong.finalize() + self.assertFalse(yuanrong.apis.is_initialized()) + yuanrong.apis.set_initialized() + yuanrong.exit() + yuanrong.finalize() + yuanrong.apis.receive_request_loop() + self.assertFalse(yuanrong.apis.is_initialized()) + + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_get_put_wait(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.get.return_value = [1, 2] @@ -249,55 +250,55 @@ class TestApi(unittest.TestCase): is_initialized.return_value = True v = ObjectRef("test") with self.assertRaises(TypeError): - yr.put(v) + yuanrong.put(v) with self.assertRaises(ValueError): - yr.get(v, -2, True) - self.assertFalse(yr.get([])) + yuanrong.get(v, -2, True) + self.assertFalse(yuanrong.get([])) - res = yr.get([v, v]) + res = yuanrong.get([v, v]) self.assertEqual(len(res), 2, len(res)) with self.assertRaises(ValueError): - yr.wait([v, v], 2) + yuanrong.wait([v, v], 2) with self.assertRaises(ValueError): - yr.wait([v], -1) + yuanrong.wait([v], -1) with self.assertRaises(TypeError): - yr.wait([v], "") + yuanrong.wait([v], "") with self.assertRaises(TypeError): - yr.wait([v], 1, "") + yuanrong.wait([v], 1, "") with self.assertRaises(ValueError): - yr.wait([v], 1, -2) + yuanrong.wait([v], 1, -2) with self.assertRaises(ValueError): - yr.wait([v], 1) + yuanrong.wait([v], 1) def test_instance(self): with self.assertRaises(RuntimeError): - @yr.instance(invoke_options=InvokeOptions()) + @yuanrong.instance(invoke_options=InvokeOptions()) def hello(): return "" hello() with self.assertRaises(ValueError): - @yr.method() + @yuanrong.method() def hi(): return "" hi() with self.assertRaises(TypeError): - @yr.method(return_nums="") + @yuanrong.method(return_nums="") def hi(): return "" hi() - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_stream(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.create_stream_producer.return_value = "producer" @@ -311,25 +312,25 @@ class TestApi(unittest.TestCase): get_runtime.return_value = mock_runtime is_initialized.return_value = True - self.assertEqual(yr.create_stream_producer("", None), "producer") + self.assertEqual(yuanrong.create_stream_producer("", None), "producer") - self.assertEqual(yr.create_stream_consumer("", None), "consummer") - self.assertEqual(yr.query_global_producers_num(""), 10) - self.assertEqual(yr.query_global_consumers_num(""), 10) + self.assertEqual(yuanrong.create_stream_consumer("", None), "consummer") + self.assertEqual(yuanrong.query_global_producers_num(""), 10) + self.assertEqual(yuanrong.query_global_consumers_num(""), 10) with self.assertRaises(RuntimeError): - yr.delete_stream("") + yuanrong.delete_stream("") with self.assertRaises(RuntimeError): - yr.kv_write("key", b"abc") + yuanrong.kv_write("key", b"abc") - self.assertEqual(yr.kv_read(""), "value") + self.assertEqual(yuanrong.kv_read(""), "value") with self.assertRaises(RuntimeError): - yr.kv_del("key") + yuanrong.kv_del("key") - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_state(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.save_state.side_effect = RuntimeError("mock exception") @@ -339,14 +340,14 @@ class TestApi(unittest.TestCase): with self.assertRaises(RuntimeError): ConfigManager().local_mode = True - yr.save_state() + yuanrong.save_state() with self.assertRaises(RuntimeError): ConfigManager().local_mode = False - yr.save_state() + yuanrong.save_state() - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_save_and_load_state(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.save_state.return_value = None @@ -356,35 +357,35 @@ class TestApi(unittest.TestCase): ConfigManager()._ConfigManager__in_cluster = True ConfigManager()._ConfigManager__is_driver = False ConfigManager().local_mode = False - yr.save_state() - self.assertEqual(yr.load_state(), None) + yuanrong.save_state() + self.assertEqual(yuanrong.load_state(), None) - @patch("yr.decorator.instance_proxy.get_instance_by_name") + @patch("yuanrong.decorator.instance_proxy.get_instance_by_name") def test_get_instance(self, get_instance_by_name): get_instance_by_name.side_effect = RuntimeError("mock exception") with self.assertRaises(TypeError): - yr.get_instance(1) + yuanrong.get_instance(1) with self.assertRaises(TypeError): - yr.get_instance("instance1", 1, 1) + yuanrong.get_instance("instance1", 1, 1) with self.assertRaises(TypeError): - yr.get_instance("instance1", "namespace", -2) + yuanrong.get_instance("instance1", "namespace", -2) with self.assertRaises(Exception): - yr.get_instance("instance1", "namespace", 1) + yuanrong.get_instance("instance1", "namespace", 1) def tets_resources(self): with self.assertRaises(RuntimeError): ConfigManager().local_mode = True - yr.resources() + yuanrong.resources() - @patch("yr.decorator.instance_proxy.make_cpp_instance_creator") + @patch("yuanrong.decorator.instance_proxy.make_cpp_instance_creator") def test_class_cross_instance(self, make_cpp_instance_creator): make_cpp_instance_creator.return_value = "" - urn = "sn:cn:yrk:12345678901234561234567890123456:function:0-yr-test-config-init:$latest" - cpp_class = yr.apis.cpp_instance_class( + urn = "sn:cn:yrk:12345678901234561234567890123456:function:0-yuanrong-test-config-init:$latest" + cpp_class = yuanrong.apis.cpp_instance_class( "class", "factory", urn) with self.assertRaises(Exception): @@ -397,21 +398,21 @@ class TestApi(unittest.TestCase): self.assertEqual(cpp_class.get_factory_name(), "factory") self.assertTrue("test" in cpp_class.get_function_key()) - cp = yr.apis.cpp_function("class", urn) + cp = yuanrong.apis.cpp_function("class", urn) self.assertEqual(cp.cross_language_info.function_name, "class", cp.cross_language_info) with self.assertRaises(AttributeError): - yr.apis.go_function("class", urn) + yuanrong.apis.go_function("class", urn) - jp = yr.apis.java_function("class", "factory", urn) + jp = yuanrong.apis.java_function("class", "factory", urn) self.assertEqual(jp.cross_language_info.function_name, "factory", jp.cross_language_info) - cp = yr.apis.cpp_instance_class_new( + cp = yuanrong.apis.cpp_instance_class_new( "class", "factory", urn) self.assertTrue(cp) - @patch.object(yr.decorator.instance_proxy.InstanceCreator, "options") - @patch.object(yr.decorator.function_proxy.FunctionProxy, "options") + @patch.object(yuanrong.decorator.instance_proxy.InstanceCreator, "options") + @patch.object(yuanrong.decorator.function_proxy.FunctionProxy, "options") def test_create_function_group(self, mock_function_proxy_options, mock_instance_proxy_options): opt = FunctionGroupOptions() with self.assertRaises(ValueError): @@ -462,8 +463,8 @@ class TestApi(unittest.TestCase): res = fcc.create_function_group(fp, (1, 2), 10, opt) self.assertEqual(res, "function", res) - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.apis.is_initialized") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.apis.is_initialized") def test_resource_group(self, is_initialized, get_runtime): mock_runtime = Mock() mock_runtime.create_resource_group.return_value = None @@ -471,20 +472,20 @@ class TestApi(unittest.TestCase): mock_runtime.wait_resource_group.return_value = None get_runtime.return_value = mock_runtime is_initialized.return_value = True - rg = yr.create_resource_group([{"NPU": 1}, {"CPU": 2000, "Memory": 2000}], "rgname") + rg = yuanrong.create_resource_group([{"NPU": 1}, {"CPU": 2000, "Memory": 2000}], "rgname") self.assertTrue(rg) rg.wait() bundles = rg.bundle_specs assert bundles == [{"NPU": 1}, {"CPU": 2000, "Memory": 2000}] count = rg.bundle_count assert count == 2 - yr.remove_resource_group("rgname") + yuanrong.remove_resource_group("rgname") with self.assertRaises(TypeError): - rg = yr.create_resource_group(None, "rgname") + rg = yuanrong.create_resource_group(None, "rgname") with self.assertRaises(ValueError): - rg = yr.create_resource_group([], "rgname") + rg = yuanrong.create_resource_group([], "rgname") with self.assertRaises(TypeError): - rg = yr.create_resource_group([{"NPU": 1}, {"CPU": 2000, "Memory": 2000}], []) + rg = yuanrong.create_resource_group([{"NPU": 1}, {"CPU": 2000, "Memory": 2000}], []) class TestException(unittest.TestCase): diff --git a/api/python/yr/tests/test_apis_get.py b/api/python/yuanrong/tests/test_apis_get.py similarity index 64% rename from api/python/yr/tests/test_apis_get.py rename to api/python/yuanrong/tests/test_apis_get.py index 03a61b7468591f310d4fecc507b7d323ab4d73a9..dafa667633000d5e8e16992268c71be094c53694 100644 --- a/api/python/yr/tests/test_apis_get.py +++ b/api/python/yuanrong/tests/test_apis_get.py @@ -15,22 +15,23 @@ # limitations under the License. import unittest -import yr +import yuanrong from unittest.mock import patch, Mock -from yr.object_ref import ObjectRef +from yuanrong.object_ref import ObjectRef + class TestGet(unittest.TestCase): - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_get_invalid_timeout(self, mock_get_runtime): - obj_ref = yr.object_ref.ObjectRef(123) + obj_ref = yuanrong.object_ref.ObjectRef(123) time = -10 - mock_get_runtime =Mock() - mock_get_runtime.get.return_value="Parameter 'timeout' should be greater than 0 or equal to -1 (no timeout)" - mock_get_runtime.return_value=mock_get_runtime - yr.apis.set_initialized() + mock_get_runtime = Mock() + mock_get_runtime.get.return_value = "Parameter 'timeout' should be greater than 0 or equal to -1 (no timeout)" + mock_get_runtime.return_value = mock_get_runtime + yuanrong.apis.set_initialized() with self.assertRaises(ValueError): - yr.apis.get(obj_ref,time) + yuanrong.apis.get(obj_ref, time) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/api/python/yr/tests/test_apis_put.py b/api/python/yuanrong/tests/test_apis_put.py similarity index 64% rename from api/python/yr/tests/test_apis_put.py rename to api/python/yuanrong/tests/test_apis_put.py index 6be6cca661ac82d945f9cfd9b184809e3e152586..241e72aa5f98093c82c4e941ce3dfad7ac64f719 100644 --- a/api/python/yr/tests/test_apis_put.py +++ b/api/python/yuanrong/tests/test_apis_put.py @@ -15,92 +15,89 @@ # limitations under the License. import unittest -import yr -from yr.object_ref import ObjectRef +import yuanrong +from yuanrong.object_ref import ObjectRef from unittest.mock import patch, Mock class TestPut(unittest.TestCase): - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_with_memoryview(self, mock_get_runtime): obj_refs = memoryview(bytearray(10 * 1024 * 1024)) mock_runtime = Mock() mock_runtime.put.return_value = 1 mock_get_runtime.return_value = mock_runtime - yr.apis.set_initialized() - result = yr.apis.put(obj_refs) + yuanrong.apis.set_initialized() + result = yuanrong.apis.put(obj_refs) self.assertIsInstance(result, ObjectRef) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_with_bytes(self, mock_get_runtime): obj_refs = bytes(10 * 1024 * 1024) mock_runtime = Mock() mock_runtime.put.return_value = 10 mock_get_runtime.return_value = mock_runtime - yr.apis.set_initialized() - result = yr.apis.put(obj_refs) + yuanrong.apis.set_initialized() + result = yuanrong.apis.put(obj_refs) self.assertIsInstance(result, ObjectRef) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_with_bytearray(self, mock_get_runtime): obj_refs = bytearray(10 * 1024 * 1024) mock_runtime = Mock() mock_runtime.put.return_value = 1 mock_get_runtime.return_value = mock_runtime - yr.apis.set_initialized() - result = yr.apis.put(obj_refs) + yuanrong.apis.set_initialized() + result = yuanrong.apis.put(obj_refs) self.assertIsInstance(result, ObjectRef) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_with_object_ref(self, mock_rt): mock_rt.return_value.put.side_effect = TypeError obj = ObjectRef(1) - yr.apis.set_initialized() + yuanrong.apis.set_initialized() with self.assertRaises(TypeError): - yr.put(obj) + yuanrong.put(obj) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_fail(self, mock_rt): mock_rt.return_value.put.side_effect = RuntimeError("mock error") with self.assertRaises(RuntimeError): - yr.put(1) + yuanrong.put(1) - @patch('yr.runtime_holder.global_runtime.get_runtime') - def test_put_null_ptr(self,mock_rt): + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') + def test_put_null_ptr(self, mock_rt): mock_rt.return_value.put.side_effect = ValueError("value is None or has zero length") obj = None - yr.apis.set_initialized() + yuanrong.apis.set_initialized() with self.assertRaises(ValueError): - yr.put(obj) + yuanrong.put(obj) - - @patch('yr.runtime_holder.global_runtime.get_runtime') - def test_put_len_zero_bytes(self,mock_rt): + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') + def test_put_len_zero_bytes(self, mock_rt): mock_rt.return_value.put.side_effect = ValueError obj = bytes(0) - yr.apis.set_initialized() + yuanrong.apis.set_initialized() with self.assertRaises(ValueError): - yr.put(obj) + yuanrong.put(obj) - @patch('yr.runtime_holder.global_runtime.get_runtime') - def test_put_len_zero_bytearray(self,mock_rt): + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') + def test_put_len_zero_bytearray(self, mock_rt): mock_rt.return_value.put.side_effect = ValueError obj = bytearray(0) - yr.apis.set_initialized() + yuanrong.apis.set_initialized() with self.assertRaises(ValueError): - yr.put(obj) + yuanrong.put(obj) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_put_len_zero_memoryview(self, mock_rt): mock_rt.return_value.put.side_effect = ValueError o = bytes(0) obj = memoryview(o) - yr.apis.set_initialized() + yuanrong.apis.set_initialized() with self.assertRaises(ValueError): - yr.put(obj) - - + yuanrong.put(obj) if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main() diff --git a/api/python/yr/tests/test_cluster_mode_runtime.py b/api/python/yuanrong/tests/test_cluster_mode_runtime.py similarity index 94% rename from api/python/yr/tests/test_cluster_mode_runtime.py rename to api/python/yuanrong/tests/test_cluster_mode_runtime.py index ce6c63de7968dec1b2866ddcbb506331d21eee49..ca764a31e5da7606474d88aaa81d726d43ba01cf 100644 --- a/api/python/yr/tests/test_cluster_mode_runtime.py +++ b/api/python/yuanrong/tests/test_cluster_mode_runtime.py @@ -16,13 +16,13 @@ import unittest from unittest.mock import Mock -import yr -from yr.config_manager import ConfigManager -from yr.err_type import ErrorCode, ErrorInfo, ModuleCode -from yr.serialization import Serialization -from yr.libruntime_pb2 import ApiType, FunctionMeta -from yr.object_ref import ObjectRef -from yr.runtime import CreateParam +import yuanrong +from yuanrong.config_manager import ConfigManager +from yuanrong.err_type import ErrorCode, ErrorInfo, ModuleCode +from yuanrong.serialization import Serialization +from yuanrong.libruntime_pb2 import ApiType, FunctionMeta +from yuanrong.object_ref import ObjectRef +from yuanrong.runtime import CreateParam class TestClusterModeRuntime(unittest.TestCase): @@ -30,7 +30,7 @@ class TestClusterModeRuntime(unittest.TestCase): def setUp(self): ConfigManager().rt_server_address = "127.0.0.1:1122" - self.runtime = yr.cluster_mode_runtime.ClusterModeRuntime() + self.runtime = yuanrong.cluster_mode_runtime.ClusterModeRuntime() self.runtime.set_initialized() def mock_get_async(obj_id, callback_wrapper): @@ -128,20 +128,20 @@ class TestClusterModeRuntime(unittest.TestCase): def test_stream(self): with self.assertRaises(RuntimeError): - cfg = yr.ProducerConfig() + cfg = yuanrong.ProducerConfig() cfg.max_stream_size = -1 self.runtime.create_stream_producer("stream", cfg) with self.assertRaises(RuntimeError): - cfg = yr.ProducerConfig() + cfg = yuanrong.ProducerConfig() cfg.retain_for_num_consumers = -1 self.runtime.create_stream_producer("stream", cfg) with self.assertRaises(RuntimeError): - cfg = yr.ProducerConfig() + cfg = yuanrong.ProducerConfig() cfg.reserve_size = -1 self.runtime.create_stream_producer("stream", cfg) - self.assertEqual(self.runtime.create_stream_producer("", yr.ProducerConfig()), "producer") - self.assertEqual(self.runtime.create_stream_consumer("", yr.ProducerConfig()), "consumer") + self.assertEqual(self.runtime.create_stream_producer("", yuanrong.ProducerConfig()), "producer") + self.assertEqual(self.runtime.create_stream_consumer("", yuanrong.ProducerConfig()), "consumer") self.assertEqual(self.runtime.query_global_producers_num(""), 10) self.assertEqual(self.runtime.query_global_consumers_num(""), 10) diff --git a/api/python/yr/tests/test_code_manager.py b/api/python/yuanrong/tests/test_code_manager.py similarity index 93% rename from api/python/yr/tests/test_code_manager.py rename to api/python/yuanrong/tests/test_code_manager.py index 82b8e034267533d7ef157f3176c9357e198ba996..c7cef40b77088107dfa430a95eda2d944859254c 100644 --- a/api/python/yr/tests/test_code_manager.py +++ b/api/python/yuanrong/tests/test_code_manager.py @@ -19,9 +19,9 @@ import sys from unittest import mock, TestCase, main -from yr.code_manager import CodeManager -from yr.err_type import ErrorCode -from yr.libruntime_pb2 import FunctionMeta +from yuanrong.code_manager import CodeManager +from yuanrong.err_type import ErrorCode +from yuanrong.libruntime_pb2 import FunctionMeta logger = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class TestCodeManager(TestCase): self.cm.load_functions([path]) mock_sys_path.insert.assert_called_once_with(0, path) - @mock.patch("yr.log.get_logger") + @mock.patch("yuanrong.log.get_logger") def test_load_functions_when_input_invalid_faas_entry(self, mock_logger): mock_logger.return_value = logger self.cm.custom_handler = "/tmp" @@ -49,14 +49,14 @@ class TestCodeManager(TestCase): assert err.error_code == ErrorCode.ERR_USER_CODE_LOAD @mock.patch.object(CodeManager(), 'load_code_from_local') - @mock.patch("yr.log.get_logger") + @mock.patch("yuanrong.log.get_logger") def test_load_functions_when_user_code_syntax_err(self, mock_logger, mock_load_code_from_local): mock_logger.return_value = logger mock_load_code_from_local.side_effect = SyntaxError("a syntax error in user code") err = CodeManager().load_functions(["test.init", "test.handler"]) assert err.error_code == ErrorCode.ERR_USER_CODE_LOAD - @mock.patch("yr.log.get_logger") + @mock.patch("yuanrong.log.get_logger") def test_entry_load(self, mock_logger): mock_logger.return_value = logger self.assertFalse(self.cm.get_code_path("none")) @@ -102,7 +102,7 @@ class TestCodeManager(TestCase): @mock.patch("os.path.exists") @mock.patch("importlib.util.spec_from_file_location") @mock.patch("importlib.util.module_from_spec") - @mock.patch("yr.log.get_logger") + @mock.patch("yuanrong.log.get_logger") def test_load_module(self, mock_logger, mock_module_from_spec, mock_spec_from_file_location, mock_exists): mock_logger.return_value = logger mock_exists.return_value = True diff --git a/api/python/yr/tests/test_common.py b/api/python/yuanrong/tests/test_common.py similarity index 99% rename from api/python/yr/tests/test_common.py rename to api/python/yuanrong/tests/test_common.py index 938b181a8d2bb9e17896784b27b02286e0f2bc14..a143fb30b79590495ff4811cc26f6bb3a202640d 100644 --- a/api/python/yr/tests/test_common.py +++ b/api/python/yuanrong/tests/test_common.py @@ -18,7 +18,7 @@ import logging import json from unittest import TestCase, main -from yr.common import utils +from yuanrong.common import utils logger = logging.getLogger(__name__) diff --git a/api/python/yr/tests/test_decorator.py b/api/python/yuanrong/tests/test_decorator.py similarity index 92% rename from api/python/yr/tests/test_decorator.py rename to api/python/yuanrong/tests/test_decorator.py index a702fec175d3bec928a498422007552b7a86e583..408e37302093cd2e56ffff2fdbe13cd8a2bfa098 100644 --- a/api/python/yr/tests/test_decorator.py +++ b/api/python/yuanrong/tests/test_decorator.py @@ -18,11 +18,11 @@ import logging from unittest import TestCase, main from unittest.mock import Mock, patch -from yr.decorator import instance_proxy, function_proxy -from yr.object_ref import ObjectRef -from yr.config import InvokeOptions -from yr.common.utils import CrossLanguageInfo -from yr.libruntime_pb2 import LanguageType, FunctionMeta +from yuanrong.decorator import instance_proxy, function_proxy +from yuanrong.object_ref import ObjectRef +from yuanrong.config import InvokeOptions +from yuanrong.common.utils import CrossLanguageInfo +from yuanrong.libruntime_pb2 import LanguageType, FunctionMeta logger = logging.getLogger(__name__) @@ -30,8 +30,8 @@ logger = logging.getLogger(__name__) class TestDecorator(TestCase): - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.log.get_logger") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.log.get_logger") def test_instance_proxy(self, mock_logger, get_runtime): mock_logger.return_value = logger mock_runtime = Mock() @@ -116,8 +116,8 @@ class TestDecorator(TestCase): decorator = instance_proxy.make_decorator() decorator("test") - @patch("yr.runtime_holder.global_runtime.get_runtime") - @patch("yr.log.get_logger") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.log.get_logger") def test_function_proxy(self, mock_logger, get_runtime): mock_logger.return_value = logger mock_runtime = Mock() diff --git a/api/python/yr/tests/test_executor.py b/api/python/yuanrong/tests/test_executor.py similarity index 82% rename from api/python/yr/tests/test_executor.py rename to api/python/yuanrong/tests/test_executor.py index 3fcfa4ce73633c3208d7ceaa96a5690e601905c4..26cf65f92cd8f5bfdd5a701e78863579ba9a43ee 100644 --- a/api/python/yr/tests/test_executor.py +++ b/api/python/yuanrong/tests/test_executor.py @@ -19,20 +19,20 @@ import os from unittest import TestCase, main from unittest.mock import Mock, patch -import yr -from yr.executor.posix_handler import PosixHandler -from yr.executor.faas_handler import FaasHandler -from yr.executor.function_handler import FunctionHandler -from yr.executor.executor import INIT_HANDLER, Executor -import yr.executor.faas_executor as faas -from yr.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType +import yuanrong +from yuanrong.executor.posix_handler import PosixHandler +from yuanrong.executor.faas_handler import FaasHandler +from yuanrong.executor.function_handler import FunctionHandler +from yuanrong.executor.executor import INIT_HANDLER, Executor +import yuanrong.executor.faas_executor as faas +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType logger = logging.getLogger(__name__) class TestExecutor(TestCase): def setUp(self) -> None: - self.runtime = yr.cluster_mode_runtime.ClusterModeRuntime() + self.runtime = yuanrong.cluster_mode_runtime.ClusterModeRuntime() mock_fnruntime = Mock() mock_fnruntime.get.return_value = [b"data1", b"data2"] mock_fnruntime.config.libruntimeOptions.functionExecuteCallback = Mock() @@ -53,25 +53,25 @@ class TestExecutor(TestCase): isAsync=False) - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") def test_load_excutor(self, mock_logger): mock_logger.return_value = logger os.environ[INIT_HANDLER] = "yrlib_handler.init" Executor.load_handler() - from yr.executor.executor import HANDLER + from yuanrong.executor.executor import HANDLER self.assertTrue(isinstance(HANDLER, FunctionHandler), f"Failed to load executor, HANDLER type is {type(HANDLER)}") os.environ[INIT_HANDLER] = "faas_executor.init" Executor.load_handler() - from yr.executor.executor import HANDLER + from yuanrong.executor.executor import HANDLER self.assertTrue(isinstance(HANDLER, FaasHandler), f"Failed to load executor, HANDLER type is {type(HANDLER)}") os.environ[INIT_HANDLER] = "posix.init" Executor.load_handler() - from yr.executor.executor import HANDLER + from yuanrong.executor.executor import HANDLER self.assertTrue(isinstance(HANDLER, PosixHandler), f"Failed to load executor, HANDLER type is {type(HANDLER)}") - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") def test_executor(self, mock_logger): mock_logger.return_value = logger e = Executor(self.function_meta, [], InvokeType.CreateInstanceStateless, 1, None, False) diff --git a/api/python/yr/tests/test_faas_handler.py b/api/python/yuanrong/tests/test_faas_handler.py similarity index 89% rename from api/python/yr/tests/test_faas_handler.py rename to api/python/yuanrong/tests/test_faas_handler.py index aa58e8a4f7d9e6671a03491fad51ecd689706696..d15630aa3d74c484f9b37bdd4fadd92132640b00 100644 --- a/api/python/yr/tests/test_faas_handler.py +++ b/api/python/yuanrong/tests/test_faas_handler.py @@ -18,20 +18,20 @@ import logging import json from unittest import TestCase, main from unittest.mock import Mock, patch -import yr.executor.faas_executor as faas -from yr.code_manager import CodeManager +import yuanrong.executor.faas_executor as faas +from yuanrong.code_manager import CodeManager -from yr.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType -from yr.functionsdk.context import load_context_meta -from yr.err_type import ErrorCode +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType +from yuanrong.functionsdk.context import load_context_meta +from yuanrong.err_type import ErrorCode logger = logging.getLogger(__name__) class TestFaasExecutor(TestCase): - @patch("yr.log.get_logger") - @patch("yr.executor.faas_executor.parse_faas_param") + @patch("yuanrong.log.get_logger") + @patch("yuanrong.executor.faas_executor.parse_faas_param") @patch.object(CodeManager(), 'get_code_path') @patch.object(CodeManager(), 'load') def test_parse_faas_param(self, mock_load, mock_get_code_path, parse_faas_param, mock_logger): @@ -74,9 +74,9 @@ class TestFaasExecutor(TestCase): self.assertTrue("faas init request args json decode error" in str(e), str(e)) parse_faas_param.reset_mock() - @patch("yr.log.get_logger") - @patch("yr.executor.faas_executor.parse_faas_param") - @patch("yr.executor.faas_executor.get_trace_id_from_params") + @patch("yuanrong.log.get_logger") + @patch("yuanrong.executor.faas_executor.parse_faas_param") + @patch("yuanrong.executor.faas_executor.get_trace_id_from_params") @patch.object(CodeManager(), 'load') def test_faas_call_handler(self, mock_load, get_trace_id_from_params, mock_parse_faas_param, mock_logger): mock_logger.return_value = logger @@ -117,7 +117,7 @@ class TestFaasExecutor(TestCase): res = faas.faas_call_handler(["arg0", "arg1"]) self.assertTrue("failed to convert the result to a JSON string" in res, res) - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") @patch.object(CodeManager(), 'load') def test_faas_shutdown_handler(self, mock_load, mock_logger): mock_logger.return_value = logger diff --git a/api/python/yr/tests/test_fcc.py b/api/python/yuanrong/tests/test_fcc.py similarity index 87% rename from api/python/yr/tests/test_fcc.py rename to api/python/yuanrong/tests/test_fcc.py index fe5e2ef24fe7fdd601a815d36165c04c0e45ae3b..90f712b4b94b9d9a036bda50bbfa59f00e5b5841 100644 --- a/api/python/yr/tests/test_fcc.py +++ b/api/python/yuanrong/tests/test_fcc.py @@ -20,15 +20,15 @@ import logging import time import asyncio from dataclasses import asdict -from yr.decorator.instance_proxy import FunctionGroupHandler +from yuanrong.decorator.instance_proxy import FunctionGroupHandler from unittest import TestCase, main from unittest.mock import patch, Mock, AsyncMock -from yr.fnruntime import SharedBuffer -from yr.accelerate.shm_broadcast import Handle -from yr.accelerate.executor import Worker -from yr.executor.instance_manager import InstanceManager -from yr.accelerate.shm_broadcast import STOP_EVENT, MessageQueue -import yr +from yuanrong.fnruntime import SharedBuffer +from yuanrong.accelerate.shm_broadcast import Handle +from yuanrong.accelerate.executor import Worker +from yuanrong.executor.instance_manager import InstanceManager +from yuanrong.accelerate.shm_broadcast import STOP_EVENT, MessageQueue +import yuanrong import threading logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) @@ -63,7 +63,7 @@ class TestFcc(unittest.TestCase): def setUp(self) -> None: pass - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_accelerate(self, get_runtime): data = bytearray(10 * 1024 * 1024) shared_buffer = SharedBuffer() @@ -84,7 +84,7 @@ class TestFcc(unittest.TestCase): self.assertIsNone(handler.terminate()) def test_worker_sync(self): - yr.log.get_logger = get_new_logger + yuanrong.log.get_logger = get_new_logger InstanceManager().instance = new_instance mock_queue = Mock() mock_queue.dequeue.return_value = ("obj", "get", (1, 2), {}) @@ -103,7 +103,7 @@ class TestFcc(unittest.TestCase): self.assertIsNone(worker.worker_busy_loop_sync()) def test_worker_async(self): - yr.log.get_logger = get_new_logger + yuanrong.log.get_logger = get_new_logger mock_queue = AsyncMock() InstanceManager().instance = new_instance mock_queue.dequeue_async.return_value = ("obj", "get", (1, 2), {}) @@ -121,10 +121,10 @@ class TestFcc(unittest.TestCase): thread.start() self.assertIsNone(asyncio.run(worker.worker_busy_loop_async())) - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_message_queue_sync(self, get_runtime): STOP_EVENT.clear() - yr.log.get_logger = get_new_logger + yuanrong.log.get_logger = get_new_logger logger.info("==========================") data = bytearray((10 * 1024 * 1024 + 2) * 10) shared_buffer = MockSharedMemory(data) @@ -143,10 +143,10 @@ class TestFcc(unittest.TestCase): r_queue = MessageQueue.create_from_handle(handle) self.assertIsNotNone(r_queue.dequeue()) - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_message_queue_async(self, get_runtime): STOP_EVENT.clear() - yr.log.get_logger = get_new_logger + yuanrong.log.get_logger = get_new_logger data = bytearray((10 * 1024 * 1024 + 2) * 10) shared_buffer = MockSharedMemory(data) mock_runtime = Mock() diff --git a/api/python/yr/tests/test_function_handler.py b/api/python/yuanrong/tests/test_function_handler.py similarity index 95% rename from api/python/yr/tests/test_function_handler.py rename to api/python/yuanrong/tests/test_function_handler.py index 864a260bd15696e74a6fb33cbca383e8d2732c73..ef7fcea7a43f547c8f4d2734546cf969a0b6df86 100644 --- a/api/python/yr/tests/test_function_handler.py +++ b/api/python/yuanrong/tests/test_function_handler.py @@ -19,11 +19,11 @@ import logging import inspect from unittest import TestCase, main from unittest.mock import Mock, patch -from yr.executor.function_handler import FunctionHandler -from yr.code_manager import CodeManager -from yr.serialization import Serialization -from yr.err_type import ErrorCode -from yr.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType +from yuanrong.executor.function_handler import FunctionHandler +from yuanrong.code_manager import CodeManager +from yuanrong.serialization import Serialization +from yuanrong.err_type import ErrorCode +from yuanrong.libruntime_pb2 import FunctionMeta, LanguageType, InvokeType, ApiType logger = logging.getLogger(__name__) @@ -45,7 +45,7 @@ class TestFunctionExecutor(TestCase): isGenerator=False, isAsync=False) - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") @patch.object(CodeManager(), 'load_code') def test_execute_function(self, mock_load_code, mock_logger): mock_logger.return_value = logger @@ -128,7 +128,7 @@ class TestFunctionExecutor(TestCase): err = self.handler.shutdown(10) self.assertTrue(err.error_code == ErrorCode.ERR_OK, err.error_code) - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") @patch.object(CodeManager(), 'load_code') def test_execute_async_function(self, mock_load_code, mock_logger): mock_logger.return_value = logger diff --git a/api/python/yr/tests/test_functionsdk.py b/api/python/yuanrong/tests/test_functionsdk.py similarity index 95% rename from api/python/yr/tests/test_functionsdk.py rename to api/python/yuanrong/tests/test_functionsdk.py index 0514894b9365fc077796bed9a56006aec4d1f649..45540f6d114c1c73d268162435389fa0abf6a8ea 100644 --- a/api/python/yr/tests/test_functionsdk.py +++ b/api/python/yuanrong/tests/test_functionsdk.py @@ -18,11 +18,11 @@ import os import json import logging from logging import handlers -from yr.functionsdk import context -from yr.functionsdk import function -from yr.functionsdk import utils -from yr.functionsdk import logger as sdklogger -from yr.functionsdk import logger_manager +from yuanrong.functionsdk import context +from yuanrong.functionsdk import function +from yuanrong.functionsdk import utils +from yuanrong.functionsdk import logger as sdklogger +from yuanrong.functionsdk import logger_manager from unittest import TestCase, main from unittest.mock import Mock, patch import os @@ -36,7 +36,7 @@ logger = logging.getLogger(__name__) class TestFunctionSdk(TestCase): - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") def test_context(self, mock_logger): mock_logger.return_value = logger @@ -57,8 +57,8 @@ class TestFunctionSdk(TestCase): self.assertEqual(invoke_context.get_trace_id(), "12345") self.assertEqual(invoke_context.getUserData("TEST_ENV_KEY"), "test_env_value") - @patch("yr.log.get_logger") - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.log.get_logger") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_invoke(self, get_runtime, mock_logger): mock_logger.return_value = logger @@ -96,8 +96,8 @@ class TestFunctionSdk(TestCase): with self.assertRaises(TypeError): function.Function(func_name) - @patch("yr.log.get_logger") - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.log.get_logger") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_invoke_alias(self, get_runtime, mock_logger): mock_logger.return_value = logger @@ -135,7 +135,7 @@ class TestFunctionSdk(TestCase): with self.assertRaises(TypeError): function.Function(func_name) - @patch("yr.log.get_logger") + @patch("yuanrong.log.get_logger") def test_private_function(self, mock_logger): mock_logger.return_value = logger diff --git a/api/python/yr/tests/test_generator.py b/api/python/yuanrong/tests/test_generator.py similarity index 90% rename from api/python/yr/tests/test_generator.py rename to api/python/yuanrong/tests/test_generator.py index ffd7273eae51e0e8dc29e10f5720f1b14519000c..36c4bc2619acad5431ca1ff88f785da54832038d 100644 --- a/api/python/yr/tests/test_generator.py +++ b/api/python/yuanrong/tests/test_generator.py @@ -20,10 +20,10 @@ import logging from unittest.mock import Mock, patch from concurrent.futures import Future -import yr -from yr.fnruntime import GeneratorEndError -from yr.generator import ObjectRefGenerator -from yr.object_ref import ObjectRef +import yuanrong +from yuanrong.fnruntime import GeneratorEndError +from yuanrong.generator import ObjectRefGenerator +from yuanrong.object_ref import ObjectRef logger = logging.getLogger(__name__) @@ -78,8 +78,8 @@ class testObjectRef(unittest.TestCase): obj.set_data("data") self.assertEqual(obj.get_future().result(), "data") - @patch('yr.runtime_holder.global_runtime.get_runtime') - @patch("yr.log.get_logger") + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') + @patch("yuanrong.log.get_logger") def test_get(self, mock_logger, get_runtime): mock_logger.return_value = logger mock_runtime = Mock() @@ -98,7 +98,7 @@ class TestObjectRefGenerator(unittest.TestCase): def setUp(self): pass - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_iter(self, get_runtime): mock_runtime = Mock() mock_runtime.peek_object_ref_stream.return_value = 'test_object_id' @@ -108,7 +108,7 @@ class TestObjectRefGenerator(unittest.TestCase): ObjectRef(generator_id, need_incre=False)) self.assertEqual(iter(generator), generator) - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_next_sync(self, get_runtime): mock_runtime = Mock() mock_runtime.peek_object_ref_stream.return_value = 'test_object_id' @@ -119,7 +119,7 @@ class TestObjectRefGenerator(unittest.TestCase): self.assertEqual(generator._next_sync().id, 'test_object_id') print("finished test_next_sync") - @patch('yr.runtime_holder.global_runtime.get_runtime') + @patch('yuanrong.runtime_holder.global_runtime.get_runtime') def test_next_sync_with_exception(self, get_runtime): mock_runtime = Mock() mock_runtime.peek_object_ref_stream.side_effect = GeneratorEndError("failed") diff --git a/api/python/yr/tests/test_instance_manager.py b/api/python/yuanrong/tests/test_instance_manager.py similarity index 95% rename from api/python/yr/tests/test_instance_manager.py rename to api/python/yuanrong/tests/test_instance_manager.py index a8a3a139ec926d8b7dcb2e6458648be4949b7eba..ed90f1faa8e068d192993dffdb42b194715b67eb 100644 --- a/api/python/yr/tests/test_instance_manager.py +++ b/api/python/yuanrong/tests/test_instance_manager.py @@ -15,7 +15,7 @@ # limitations under the License. import unittest -from yr.executor.instance_manager import InstanceManager, InstancePackage +from yuanrong.executor.instance_manager import InstanceManager, InstancePackage class TestInstanceManager(unittest.TestCase): def setUp(self) -> None: diff --git a/api/python/yr/tests/test_local_mode.py b/api/python/yuanrong/tests/test_local_mode.py similarity index 88% rename from api/python/yr/tests/test_local_mode.py rename to api/python/yuanrong/tests/test_local_mode.py index f18713df4e23dec37f8ab472b2cfe9153d151903..899b34d56e824fa991a0bec3347cb7743a681deb 100644 --- a/api/python/yr/tests/test_local_mode.py +++ b/api/python/yuanrong/tests/test_local_mode.py @@ -17,15 +17,15 @@ from unittest import TestCase, main import time import concurrent.futures -import yr -from yr.object_ref import ObjectRef -from yr.exception import YRInvokeError -from yr.local_mode.local_mode_runtime import LocalModeRuntime -from yr.local_mode import local_client, instance_manager -from yr.local_mode.instance import Resource, Instance -from yr.local_mode.task_spec import TaskSpec -from yr.local_mode.local_object_store import LocalObjectStore -from yr.runtime import SetParam +import yuanrong +from yuanrong.object_ref import ObjectRef +from yuanrong.exception import YRInvokeError +from yuanrong.local_mode.local_mode_runtime import LocalModeRuntime +from yuanrong.local_mode import local_client, instance_manager +from yuanrong.local_mode.instance import Resource, Instance +from yuanrong.local_mode.task_spec import TaskSpec +from yuanrong.local_mode.local_object_store import LocalObjectStore +from yuanrong.runtime import SetParam class Mock(object): @@ -37,15 +37,15 @@ class TestApi(TestCase): pass def test_local_mode_base(self): - @yr.invoke + @yuanrong.invoke def func(x): return x - yr.init(yr.Config(local_mode=True, log_level="DEBUG")) - assert yr.get(func.invoke(1)) == 1 - assert yr.get(func.invoke(func.invoke(1))) == 1 + yuanrong.init(yuanrong.Config(local_mode=True, log_level="DEBUG")) + assert yuanrong.get(func.invoke(1)) == 1 + assert yuanrong.get(func.invoke(func.invoke(1))) == 1 - @yr.instance + @yuanrong.instance class Counter: cnt = 0 @@ -61,28 +61,28 @@ class TestApi(TestCase): return self.cnt c = Counter.invoke() - assert yr.get(c.get.invoke()) == 0 - assert yr.get(c.add.invoke()) == 1 + assert yuanrong.get(c.get.invoke()) == 0 + assert yuanrong.get(c.add.invoke()) == 1 obj_id = c.add.invoke() - ready, _ = yr.wait(obj_id, 1, 2) + ready, _ = yuanrong.wait(obj_id, 1, 2) self.assertTrue(len(ready) == 1, len(ready)) - assert yr.get(ready[0]) == 2 + assert yuanrong.get(ready[0]) == 2 obj_id = c.delay.invoke() - yr.cancel(obj_id) + yuanrong.cancel(obj_id) obj_id = ObjectRef(object_id="noid") with self.assertRaises(RuntimeError): - yr.cancel(obj_id) + yuanrong.cancel(obj_id) obj = func.invoke(1) def cb(): return obj.on_complete(cb) - self.assertEqual(yr.get(obj), 1) + self.assertEqual(yuanrong.get(obj), 1) def test_local_mode_runtime(self): lr = LocalModeRuntime() @@ -281,7 +281,7 @@ class TestApi(TestCase): trace_id="trace1234", ) instance_id, _ = ins_mgr.scale_out(task, res) - self.assertIn("yr-api-obj", instance_id) + self.assertIn("yuanrong-api-obj", instance_id) get_ins = ins_mgr.get_instances(res) self.assertEqual(len(get_ins), 1, len(get_ins)) diff --git a/api/python/yr/tests/test_metrics.py b/api/python/yuanrong/tests/test_metrics.py similarity index 93% rename from api/python/yr/tests/test_metrics.py rename to api/python/yuanrong/tests/test_metrics.py index 9a829e58dc7212873018a5f57deed87bf5cf0363..4e8e4f0528e4e8fba7a6c404f77925d361f03c2d 100644 --- a/api/python/yr/tests/test_metrics.py +++ b/api/python/yuanrong/tests/test_metrics.py @@ -17,13 +17,13 @@ from unittest import TestCase, main from unittest.mock import Mock, patch -from yr.config_manager import ConfigManager -from yr.config import Config -from yr import Gauge, UInt64Counter, DoubleCounter +from yuanrong.config_manager import ConfigManager +from yuanrong.config import Config +from yuanrong import Gauge, UInt64Counter, DoubleCounter class TestMetrics(TestCase): - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_gauge(self, get_runtime): mock_runtime = Mock() mock_runtime.report_gauge.side_effect = RuntimeError("mock exception") @@ -56,7 +56,7 @@ class TestMetrics(TestCase): ConfigManager().init(Config(is_driver=False, ds_address="127.0.0.1:31222")) data.set(1) - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_uint64_counter(self, get_runtime): mock_runtime = Mock() mock_runtime.set_uint64_counter.side_effect = RuntimeError("mock exception") @@ -97,7 +97,7 @@ class TestMetrics(TestCase): ConfigManager().init(Config(is_driver=False, ds_address="127.0.0.1:31222")) self.assertEqual(data.get_value(), 10) - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_double_counter(self, get_runtime): mock_runtime = Mock() mock_runtime.set_double_counter.side_effect = RuntimeError("mock exception") diff --git a/api/python/yr/tests/test_runtime_env.py b/api/python/yuanrong/tests/test_runtime_env.py similarity index 99% rename from api/python/yr/tests/test_runtime_env.py rename to api/python/yuanrong/tests/test_runtime_env.py index 76363705e64aa1de05b9cd6b9034cb60c10c4dc8..7ae7a04db70554308d934fb6dc471cb08b723f24 100644 --- a/api/python/yr/tests/test_runtime_env.py +++ b/api/python/yuanrong/tests/test_runtime_env.py @@ -20,7 +20,7 @@ import tempfile import unittest from unittest.mock import patch, Mock -from yr import runtime_env, InvokeOptions +from yuanrong import runtime_env, InvokeOptions class TestPut(unittest.TestCase): diff --git a/api/python/yr/tests/test_serialization.py b/api/python/yuanrong/tests/test_serialization.py similarity index 93% rename from api/python/yr/tests/test_serialization.py rename to api/python/yuanrong/tests/test_serialization.py index 68d66d16959354d7bf1432c8baab9d4332757d3b..e278ff9863f394f13778c5f5dec989eba235fc9a 100644 --- a/api/python/yr/tests/test_serialization.py +++ b/api/python/yuanrong/tests/test_serialization.py @@ -17,9 +17,9 @@ import unittest import pickle from unittest.mock import patch, Mock -from yr.common import constants -from yr.serialization import Serialization -from yr.fnruntime import write_to_cbuffer +from yuanrong.common import constants +from yuanrong.serialization import Serialization +from yuanrong.fnruntime import write_to_cbuffer import numpy as np @@ -27,7 +27,7 @@ class TestApi(unittest.TestCase): def setUp(self) -> None: pass - @patch("yr.runtime_holder.global_runtime.get_runtime") + @patch("yuanrong.runtime_holder.global_runtime.get_runtime") def test_serialize_base(self, get_runtime): mock_runtime = Mock() mock_runtime.increase_global_reference.return_value = None diff --git a/build.sh b/build.sh index 5cc3a5d6019673d1ac727675841622e5b49d58b4..dda013cf3a6f0eea62b8eae07c040925f0643b4a 100644 --- a/build.sh +++ b/build.sh @@ -166,7 +166,7 @@ function run_java_coverage_report() { } function run_python_coverage_report() { - coverage_files=$(find bazel-out/k8-opt/testlogs/api/python/yr/tests/ -name coverage.dat) + coverage_files=$(find bazel-out/k8-opt/testlogs/api/python/yuanrong/tests/ -name coverage.dat) for i in $coverage_files; do MODULE_NAME=$(basename $(dirname $i)) lcov -q -r $i 'src/*' '*pb2.py' '*tests*' 'apis*' 'cluster_mode*' 'code_manager*' -o ${BASE_DIR}/bazel-bin/api/python/${MODULE_NAME}_coverage.txt @@ -260,7 +260,7 @@ while getopts 'athr:v:S:DcCgPET:p:bm:j:gG' opt; do ;; t) BAZEL_COMMAND="test" - BAZEL_TARGETS="//test/... //api/python/yr/tests/... //api/java:java_tests" + BAZEL_TARGETS="//test/... //api/python/yuanrong/tests/... //api/java:java_tests" install_python_requirements ;; T) @@ -293,7 +293,7 @@ while getopts 'athr:v:S:DcCgPET:p:bm:j:gG' opt; do ;; c) BAZEL_COMMAND="coverage" - BAZEL_TARGETS="//api/go:yr_go_test //test/... //api/python/yr/tests/..." + BAZEL_TARGETS="//api/go:yr_go_test //test/... //api/python/yuanrong/tests/..." BAZEL_OPTIONS="$BAZEL_OPTIONS --combined_report=lcov --nocache_test_results --instrumentation_filter=^//.*[/:] --test_tag_filters=-cgo" install_python_requirements ;; diff --git a/build/build.sh b/build/build.sh index 196238f84659a964541078ae33850fb0aae02186..58b1f8ff5f2c7c55857bd4c8cb8e5d67a5070715 100644 --- a/build/build.sh +++ b/build/build.sh @@ -133,7 +133,7 @@ function run_java_coverage_report() { } function run_python_coverage_report() { - coverage_files=$(find bazel-out/k8-opt/testlogs/api/python/yr/tests/ -name coverage.dat) + coverage_files=$(find bazel-out/k8-opt/testlogs/api/python/yuanrong/tests/ -name coverage.dat) for i in $coverage_files; do MODULE_NAME=$(basename $(dirname $i)) lcov -q -r $i 'src/*' '*pb2.py' '*tests*' 'apis*' 'cluster_mode*' 'code_manager*' -o ${BASE_DIR}/bazel-bin/api/python/${MODULE_NAME}_coverage.txt @@ -224,7 +224,7 @@ while getopts 'thr:v:S:DcCgPET:p:bm:j:g' opt; do case "$opt" in t) BAZEL_COMMAND="test" - BAZEL_TARGETS="//test/... //api/python/yr/tests/... //api/java:java_tests" + BAZEL_TARGETS="//test/... //api/python/yuanrong/tests/... //api/java:java_tests" install_python_requirements ;; T) @@ -257,7 +257,7 @@ while getopts 'thr:v:S:DcCgPET:p:bm:j:g' opt; do ;; c) BAZEL_COMMAND="coverage" - BAZEL_TARGETS="//test/... //api/python/yr/tests/... //api/java:java_tests" + BAZEL_TARGETS="//test/... //api/python/yuanrong/tests/... //api/java:java_tests" BAZEL_OPTIONS="$BAZEL_OPTIONS --combined_report=lcov --nocache_test_results --instrumentation_filter=^//.*[/:]" install_python_requirements ;; diff --git a/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.flush.rst b/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.flush.rst deleted file mode 100644 index b5bdef4a5750b1a70b8385004be1f9772a5c5978..0000000000000000000000000000000000000000 --- a/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.flush.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. _flush: - -yr.fnruntime.Producer.flush --------------------------------- - -.. py:method:: Producer.flush(self) -> None - - 手动刷新缓冲区,确保所有数据都发送到流中。 \ No newline at end of file diff --git a/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.rst b/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.rst index 28affbde427e2225b21bee828af6acf138be70c1..bd3ece58bd065d064daa614da78c96fd221cfefd 100644 --- a/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.rst +++ b/docs/multi_language_function_programming_interface/api/distributed_programming/zh_cn/Python/yr.fnruntime.Producer.rst @@ -31,8 +31,6 @@ yr.fnruntime.Producer +------------------------+------------------------------------------------------------------+ | :ref:`close ` | 关闭生产者将触发数据缓冲区的自动刷新,并表明数据缓冲区不再使用。 | +------------------------+------------------------------------------------------------------+ - | :ref:`flush ` | 手动刷缓冲数据使得消费者可见。 | - +------------------------+------------------------------------------------------------------+ | :ref:`send ` | 生产者发送数据时,会先将数据存入缓冲区。 | +------------------------+------------------------------------------------------------------+ @@ -42,5 +40,4 @@ yr.fnruntime.Producer yr.fnruntime.Producer.__init__ yr.fnruntime.Producer.close - yr.fnruntime.Producer.flush yr.fnruntime.Producer.send diff --git a/src/libruntime/gwclient/gw_client.cpp b/src/libruntime/gwclient/gw_client.cpp index bcde9467bd393317b4888a317e56e707b8f74cba..331122a41ad674de6309ee2045228e94ebb1fbf0 100644 --- a/src/libruntime/gwclient/gw_client.cpp +++ b/src/libruntime/gwclient/gw_client.cpp @@ -43,7 +43,6 @@ ErrorInfo ClientBuffer::Seal(const std::unordered_set &nestedIds) for (const auto &id : nestedIds) { req.add_nestedobjectids(id); } - req.set_writemode(static_cast(this->createParam_.writeMode)); req.set_consistencytype(static_cast(this->createParam_.consistencyType)); req.set_cachetype(static_cast(this->createParam_.cacheType)); return gwClient->PosixObjPut(req); @@ -885,7 +884,6 @@ PutRequest GwClient::BuildObjPutRequest(std::shared_ptr data, const std: for (const auto &id : nestedID) { req.add_nestedobjectids(id); } - req.set_writemode(static_cast(createParam.writeMode)); req.set_consistencytype(static_cast(createParam.consistencyType)); req.set_cachetype(static_cast(createParam.cacheType)); return req; diff --git a/src/libruntime/objectstore/object_store.h b/src/libruntime/objectstore/object_store.h index b72e6f8006bed9f4a2f5c2bd9620a00a64cc4f59..24a28b83c3da08c0cd3290eedeb788089b0057a1 100644 --- a/src/libruntime/objectstore/object_store.h +++ b/src/libruntime/objectstore/object_store.h @@ -48,7 +48,6 @@ struct RetryInfo { }; struct CreateParam { - WriteMode writeMode = WriteMode::NONE_L2_CACHE; ConsistencyType consistencyType = ConsistencyType::PRAM; CacheType cacheType = CacheType::MEMORY; };