### Start SimpleRPyC Server Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Launches the SimpleRPyC server from the command line. The server will print an authentication token that should be set as an environment variable. ```bash python -m simplerpyc.server ``` -------------------------------- ### Starting the simplerpyc RPC Server Source: https://context7.com/milkclouds/simplerpyc/llms.txt Provides instructions on how to start the simplerpyc RPC server. It can be started programmatically or via the command line. The server generates a secure authentication token and supports auto-port selection. This example shows the command-line method. ```bash # Start server with default settings (localhost:8000) python -m simplerpyc.server # Output: # ⚠️ WARNING: SimpleRPyC uses unencrypted WebSocket connections! # 🔐 Authentication token: AbCdEfGhIjKlMnOpQrStUvWxYz0123456789 ``` -------------------------------- ### Install simplerpyc using pip Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Installs the SimpleRPyC library using pip. This is the first step to using the library on your client or server. ```bash pip install simplerpyc ``` -------------------------------- ### Start SimpleRPyC Server with Custom Host and Port Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates starting a SimpleRPyC server using command-line arguments with custom host and port configuration. Requires setting up environment variables for authentication. ```shell # Start with custom host and port python -m simplerpyc.server --host 0.0.0.0 --port 9000 ``` -------------------------------- ### SimpleRPyC Server Command Line Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Starts the SimpleRPyC server with optional host and port arguments. The server will output a token required for client authentication. ```bash python -m simplerpyc.server [--host HOST] [--port PORT] ``` -------------------------------- ### Programmatically Create and Run SimpleRPyC Server Source: https://context7.com/milkclouds/simplerpyc/llms.txt Shows how to create a SimpleRPyC server programmatically using the RPCServer class. Includes both blocking and asynchronous execution examples. Requires importing from simplerpyc.server.server module. ```python # Programmatic server usage from simplerpyc.server.server import RPCServer # Create server instance server = RPCServer(host="localhost", port=8000) # Get the generated token print(f"Server token: {server.token}") # Run server (blocking) server.run() # Alternative: use with asyncio import asyncio async def main(): server = RPCServer(host="localhost", port=-1) # Auto port selection print(f"Token: {server.token}") await server.serve() asyncio.run(main()) ``` -------------------------------- ### SimpleRPyC Transparent Proxies Example Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Demonstrates how SimpleRPyC uses transparent proxies to mimic remote objects. Operations like attribute access, method calls, and chaining are performed on the proxy, deferring network calls until materialization. ```python # Assuming remote_np is a proxy to the remote numpy module arr_proxy = remote_np.array([1, 2, 3]) # RPCProxy, not actual array # Proxy supports attribute access, method calls, indexing mean_proxy = arr_proxy.mean() # RPCProxy item_proxy = arr_proxy[0] # RPCProxy # Chain operations without network round-trips result_proxy = remote_np.array([1, 2, 3]).reshape(3, 1).mean() # Still proxy ``` -------------------------------- ### Start SimpleRPyC Server with Auto Port Selection Source: https://context7.com/milkclouds/simplerpyc/llms.txt Shows how to launch a SimpleRPyC server that automatically selects an available port within the range 8000-9000. Useful for avoiding port conflicts during development. ```shell # Start with auto port selection (tries ports 8000-9000) python -m simplerpyc.server --port -1 ``` -------------------------------- ### SimpleRPyC Explicit Materialization Example Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Shows how to use the `materialize()` function to transfer data from a remote proxy to the client's local Python environment. This is crucial for obtaining actual values from remote operations. ```python # Materialize when you need actual values arr = materialize(arr_proxy) # numpy array mean = materialize(mean_proxy) # float item = materialize(item_proxy) # int # Materialize complex structures env = simpler_env.make('...') # RPCProxy obs, reward, done, truncated, info = materialize(env.step(action)) # actual values ``` -------------------------------- ### Remote Code Evaluation and Execution Source: https://context7.com/milkclouds/simplerpyc/llms.txt Shows how to evaluate Python expressions and execute statements on a remote server using SimplerPyC's `eval` and `execute` methods. This allows for dynamic setup and computation on the remote environment. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) # Execute code to set up remote environment conn.execute(""" import random import math random.seed(42) data = [random.randint(1, 100) for _ in range(10)] threshold = 50 """) # Evaluate expressions to get results data = materialize(conn.eval("data")) print(f"Generated data: {data}") # [82, 15, 13, 67, 47, 86, 60, 40, 68, 45] threshold = materialize(conn.eval("threshold")) print(f"Threshold: {threshold}") # 50 # Perform complex calculation remotely conn.execute(""" filtered = [x for x in data if x > threshold] result = { 'filtered': filtered, 'count': len(filtered), 'mean': sum(filtered) / len(filtered) if filtered else 0 } """) result = materialize(conn.eval("result")) print(f"Filtered results: {result}") # {'filtered': [82, 67, 86, 60, 68], 'count': 5, 'mean': 72.6} # Evaluate arithmetic value = materialize(conn.eval("2 ** 10 + math.sqrt(144)")) print(f"Calculation result: {value}") # 1036.0 conn.disconnect() ``` -------------------------------- ### Access Remote Namespace Using SimpleRPyC Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates accessing the remote global namespace through the connection object. Shows how to execute code remotely and retrieve information about defined variables and their types. Uses materialization to get actual values. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) # Execute code to populate namespace conn.execute(""" import math import random x = 42 y = [1, 2, 3] z = {'key': 'value'} def my_function(a, b): return a + b """) # Get namespace (returns dict of name -> type string) namespace = conn.namespace print("Remote namespace:") for name, type_str in namespace.items(): print(f" {name}: {type_str}") # Output (example): # Remote namespace: # math: # random: # x: # y: # z: # my_function: # Access variables directly x_value = materialize(conn.eval("x")) print(f"Value of x: {x_value}") # 42 y_value = materialize(conn.eval("y")) print(f"Value of y: {y_value}") # [1, 2, 3] conn.disconnect() ``` -------------------------------- ### Msgpack Serialization Setup for NumPy Source: https://github.com/milkclouds/simplerpyc/blob/main/docs/SPEC.md Configures msgpack to correctly serialize and deserialize NumPy arrays. This is essential for efficient data transfer of numerical data between the client and server. ```python import msgpack import msgpack_numpy as m m.patch() ``` -------------------------------- ### SimpleRPyC Namespace Access API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Provides access to remote modules and built-in functions through the connection object. For example, `conn.modules.os` accesses the remote 'os' module, and `conn.builtins.len` accesses the remote 'len' function. ```python remote_os = conn.modules.os # Access remote module remote_len = conn.builtins.len # Access remote builtin ``` -------------------------------- ### Remote Attribute Access and Indexing with NumPy Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates accessing nested attributes and performing indexing operations on a remote NumPy array using SimplerPyC. It shows how to get a random integer and manipulate matrix elements remotely. ```python import simplerpyc from simplerpyc import materialize conn = simplerpyc.connect("localhost", 8000) remote_np = conn.modules.numpy # Access nested attributes path_join = remote_np.random.randint random_value = materialize(path_join(1, 100)) print(f"Random value: {random_value}") # e.g., 42 # Indexing operations matrix_proxy = remote_np.arange(20).reshape(4, 5) first_row = materialize(matrix_proxy[0]) # Get first row print(f"First row: {first_row}") # [0 1 2 3 4] element = materialize(matrix_proxy[2, 3]) # Get single element print(f"Element at [2,3]: {element}") # 13 conn.disconnect() ``` -------------------------------- ### Checking for simplerpyc Proxy Objects Source: https://context7.com/milkclouds/simplerpyc/llms.txt Introduces the `is_proxy` utility function in simplerpyc, which checks if an object is an RPCProxy. This is useful for implementing conditional logic that distinguishes between local and remote objects. Examples include processing data based on whether it's a proxy. ```python from simplerpyc import connect, materialize, is_proxy conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Create proxy object arr_proxy = remote_np.array([1, 2, 3]) print(f"Is proxy? {is_proxy(arr_proxy)}") # Materialize to local value arr_local = materialize(arr_proxy) print(f"Is proxy? {is_proxy(arr_local)}") print(f"Type: {type(arr_local)}") # Use in conditional logic def process_data(data): if is_proxy(data): print("Data is remote, materializing...") return materialize(data) else: print("Data is already local") return data result1 = process_data(arr_proxy) result2 = process_data(arr_local) # Non-proxy objects return False print(f"Is proxy? {is_proxy([1, 2, 3])}") print(f"Is proxy? {is_proxy(42)}") print(f"Is proxy? {is_proxy('string')}") conn.disconnect() ``` -------------------------------- ### Environment Interaction via Simplerpyc Client Source: https://github.com/milkclouds/simplerpyc/blob/main/docs/SPEC.md Illustrates how to use a patched remote module ('simpler_env') to interact with an environment. This includes creating an environment, resetting it, sampling actions, stepping through the environment, and retrieving observations and instructions. ```python import simpler_env from simpler_env.utils.env.observation_utils import get_image_from_maniskill2_obs_dict env = simpler_env.make('google_robot_pick_coke_can') obs, reset_info = env.reset() instruction = env.get_language_instruction() print("Reset info", reset_info) print("Instruction", instruction) done, truncated = False, False while not (done or truncated): # action[:3]: delta xyz; action[3:6]: delta rotation in axis-angle representation; # action[6:7]: gripper (the meaning of open / close depends on robot URDF) image = get_image_from_maniskill2_obs_dict(env, obs) action = env.action_space.sample() # replace this with your policy inference obs, reward, done, truncated, info = env.step(action) # for long horizon tasks, you can call env.advance_to_next_subtask() to advance to the next subtask; the environment might also autoadvance if env._elapsed_steps is larger than a threshold new_instruction = env.get_language_instruction() if new_instruction != instruction: # for long horizon tasks, we get a new instruction when robot proceeds to the next subtask instruction = new_instruction print("New Instruction", instruction) episode_stats = info.get('episode_stats', {}) print("Episode stats", episode_stats) ``` -------------------------------- ### Establish Connection to RPC Server - Python Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates how to establish a WebSocket connection to the RPC server using the connect function. It shows connecting with and without an authentication token, and accessing remote modules and builtins. ```python from simplerpyc import connect # Connect with auto-detected token from environment conn = connect(host="localhost", port=8000) # Connect with explicit token conn = connect(host="localhost", port=8000, token="your_token_here") # The connection provides access to remote modules and builtins remote_os = conn.modules.os remote_math = conn.modules.math remote_len = conn.builtins.len # Don't forget to disconnect when done conn.disconnect() ``` -------------------------------- ### Simplerpyc Client Connection and Module Patching Source: https://github.com/milkclouds/simplerpyc/blob/main/docs/SPEC.md Demonstrates how to connect a client to the Simplerpyc server, providing an authentication token. It also shows how to patch a remote module (e.g., 'simpler_env') to allow seamless access to its functions and objects via RPC. ```python import simplerpyc, atexit # token can be given as environmental variable or passed directly simplerpyc.connect("localhost", 8000, token="") # client does not have simpler_env installed, but it can access it via RPC patcher = simplerpyc.patch_module("simpler_env") # now simpler_env provides magic proxy atexit.register(simplerpyc.disconnect) ``` -------------------------------- ### SimpleRPyC Connection API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Establishes a connection to a SimpleRPyC server. The token can be provided directly or will be automatically detected from the SIMPLERPYC_TOKEN environment variable. ```python from simplerpyc import connect conn = connect(host="localhost", port=8000, token=None) # Token auto-detected from SIMPLERPYC_TOKEN env var if not provided ``` -------------------------------- ### Chaining Remote Operations - Python Source: https://context7.com/milkclouds/simplerpyc/llms.txt Illustrates chaining multiple remote operations before materializing the result to minimize network transfers. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Chain multiple operations - all executed on server result = materialize( remote_np.arange(12) # Create array [0, 1, 2, ..., 11] .reshape(3, 4) # Reshape to 3x4 matrix .mean(axis=0) # Mean along columns .sum() # Sum all means ) # Only the final scalar value is transferred to client print(f"Result: {result}") # 5.5 ``` -------------------------------- ### Set SimpleRPyC Token Environment Variable Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Sets the SIMPLERPYC_TOKEN environment variable, which is used by the SimpleRPyC client for authentication. Replace '' with the actual token printed by the server. ```bash export SIMPLERPYC_TOKEN='' ``` -------------------------------- ### Set Environment Variable for SimpleRPyC Token Source: https://context7.com/milkclouds/simplerpyc/llms.txt Illustrates setting the required authentication token as an environment variable for connecting to a SimpleRPyC server. This is necessary before establishing connections. ```shell # Set token in client environment export SIMPLERPYC_TOKEN='AbCdEfGhIjKlMnOpQrStUvWxYz0123456789' ``` -------------------------------- ### Remote Exception Handling with simplerpyc Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates how simplerpyc's RemoteException captures and preserves full tracebacks from the remote server. It shows how to catch and inspect these exceptions for various remote errors like attribute errors, module not found, and division by zero. Requires a simplerpyc server. ```python from simplerpyc import connect, materialize from simplerpyc.client.proxy import RemoteException conn = connect("localhost", 8000) remote_os = conn.modules.os try: # Try to access non-existent attribute result = materialize(remote_os.nonexistent_function()) except RemoteException as e: print(f"Caught RemoteException: {e.exception_type}") print(f"Message: {e}") print(f"Remote traceback:\n{e.remote_traceback}") try: # Try to import non-existent module bad_module = conn.modules.this_module_does_not_exist materialize(bad_module.some_function()) except RemoteException as e: print(f"Import error: {e.exception_type}") try: # Division by zero on remote result = materialize(conn.eval("1 / 0")) except RemoteException as e: print(f"Math error: {e.exception_type}") conn.disconnect() ``` -------------------------------- ### Function Teleportation to Remote Server Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates SimplerPyC's `teleport` method to send local Python functions to a remote server. This enables remote execution of custom logic, including functions with closures. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Define a local function def custom_transform(arr, factor=2): """Apply custom transformation to array.""" return arr * factor + 10 # Teleport function to remote server remote_transform = conn.teleport(custom_transform) # Use the remote function arr_proxy = remote_np.array([1, 2, 3, 4, 5]) result = materialize(remote_transform(arr_proxy, factor=3)) print(f"Transformed array: {result}") # [13 16 19 22 25] # Teleport function with closure multiplier = 5 def scale_and_sum(arr): """Function that captures 'multiplier' from outer scope.""" return (arr * multiplier).sum() remote_scale_sum = conn.teleport(scale_and_sum) total = materialize(remote_scale_sum(remote_np.array([1, 2, 3]))) print(f"Scaled sum: {total}") # 30 (5*1 + 5*2 + 5*3) # The function is now in remote namespace also_total = materialize(conn.eval("scale_and_sum(numpy.array([2, 3, 4]))")) print(f"Also total: {also_total}") # 45 conn.disconnect() ``` -------------------------------- ### Passing Proxy Objects as Function Arguments Source: https://context7.com/milkclouds/simplerpyc/llms.txt Explains and demonstrates how SimplerPyC allows passing proxy objects (like NumPy arrays) directly as arguments to remote functions. The server resolves these proxies automatically, avoiding unnecessary data transfer. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Create proxy arrays arr1_proxy = remote_np.array([1, 2, 3]) arr2_proxy = remote_np.array([4, 5, 6]) # Pass proxies as arguments to remote functions dot_product = materialize(remote_np.dot(arr1_proxy, arr2_proxy)) print(f"Dot product: {dot_product}") # 32 (1*4 + 2*5 + 3*6) ``` -------------------------------- ### Module Patching for Transparent Remote Usage Source: https://context7.com/milkclouds/simplerpyc/llms.txt Illustrates how to use SimplerPyC's module patching feature to transparently use remote modules like 'os' and 'numpy'. It covers patching, using patched modules, and unpatching to restore local modules. ```python import simplerpyc from simplerpyc import materialize conn = simplerpyc.connect("localhost", 8000) # Patch modules to use remote versions simplerpyc.patch_module(conn, "os") simplerpyc.patch_module(conn, "numpy") # Now import statements use remote modules import os import numpy as np # Use them as if they were local (all operations return proxies) cwd = materialize(os.getcwd()) print(f"Current working directory: {cwd}") arr = materialize(np.array([1, 2, 3, 4, 5])) mean = materialize(np.mean(arr)) print(f"Array: {arr}, Mean: {mean}") # Create 2D array with operations matrix = materialize(np.arange(12).reshape(3, 4)) print(f"Matrix shape: {matrix.shape}") # (3, 4) print(f"Matrix:\n{matrix}") # [[0 1 2 3] # [4 5 6 7] # [8 9 10 11]] # Unpatch to restore original modules conn.unpatch_module("os") conn.unpatch_module("numpy") # or unpatch all at once # conn.unpatch_all() conn.disconnect() ``` -------------------------------- ### Array Slicing and Indexing with simplerpyc Proxies Source: https://context7.com/milkclouds/simplerpyc/llms.txt Explains how simplerpyc's RPCProxy objects support Python's array indexing and slicing syntax for remote NumPy arrays. This includes basic slicing, 2D indexing, and negative indexing. Requires a running simplerpyc server and NumPy on the remote machine. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Create remote array arr = remote_np.arange(20) # Basic slicing first_five = materialize(arr[0:5]) print(f"First five: {first_five}") last_five = materialize(arr[-5:]) print(f"Last five: {last_five}") every_third = materialize(arr[::3]) print(f"Every third: {every_third}") # 2D array indexing matrix = remote_np.arange(20).reshape(4, 5) row = materialize(matrix[2]) print(f"Third row: {row}") column = materialize(matrix[:, 3]) print(f"Fourth column: {column}") submatrix = materialize(matrix[1:3, 2:4]) print(f"Submatrix:\n{submatrix}") single_element = materialize(matrix[2, 3]) print(f"Element at [2,3]: {single_element}") # Negative indexing last_row = materialize(matrix[-1]) print(f"Last row: {last_row}") conn.disconnect() ``` -------------------------------- ### Remote NumPy Operations with simplerpyc Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates matrix multiplication, concatenation, and stacking of remote NumPy arrays using simplerpyc proxies. It involves creating remote arrays, performing operations, and materializing the results to local values. Ensure the simplerpyc server is running. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # More complex example with multiple proxy arguments matrix1 = remote_np.array([[1, 2], [3, 4]]) matrix2 = remote_np.array([[5, 6], [7, 8]]) # Matrix multiplication using proxies result = materialize(remote_np.matmul(matrix1, matrix2)) print(f"Matrix multiplication result:\n{result}") # Concatenate proxy arrays # Assuming arr1_proxy and arr2_proxy are defined elsewhere and are remote arrays # For demonstration purposes, let's define them here: arr1_proxy = remote_np.array([1, 2, 3]) arr2_proxy = remote_np.array([4, 5, 6]) concatenated = materialize(remote_np.concatenate([arr1_proxy, arr2_proxy])) print(f"Concatenated: {concatenated}") # Stack proxy arrays stacked = materialize(remote_np.vstack([arr1_proxy, arr2_proxy])) print(f"Stacked:\n{stacked}") conn.disconnect() ``` -------------------------------- ### Materializing Proxy Objects to Actual Values - Python Source: https://context7.com/milkclouds/simplerpyc/llms.txt Demonstrates the materialize function, which converts RPCProxy objects to actual values. It handles simple values, numpy arrays, and nested data structures. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Simple value materialization value = materialize(remote_np.array([1, 2, 3])) # Result: numpy.ndarray([1, 2, 3]) # Nested structure materialization conn.execute(""" result = { 'metadata': {'name': 'experiment_1', 'version': 1.0}, 'arrays': [numpy.array([1.0, 2.0, 3.0]), numpy.array([[4, 5], [6, 7]])], 'coordinates': (numpy.array([10, 20, 30]), numpy.array([40, 50, 60])), 'scalar': 42 } """) nested = materialize(conn.eval("result")) # Result: dict with numpy arrays fully materialized print(f"Metadata: {nested['metadata']}") # {'name': 'experiment_1', 'version': 1.0} print(f"First array: {nested['arrays'][0]}") # [1.0 2.0 3.0] print(f"Scalar: {nested['scalar']}") # 42 conn.disconnect() ``` -------------------------------- ### Work with NumPy Arrays Across Different Versions Source: https://context7.com/milkclouds/simplerpyc/llms.txt Shows various ways to work with NumPy arrays using SimpleRPyC's cross-version compatibility. Covers basic array creation with different data types, multi-dimensional arrays, and mathematical operations. Leverages msgpack-numpy for serialization. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) remote_np = conn.modules.numpy # Various dtypes float_arr = materialize(remote_np.array([1.5, 2.7, 3.9], dtype='float64')) int_arr = materialize(remote_np.array([1, 2, 3], dtype='int32')) bool_arr = materialize(remote_np.array([True, False, True], dtype='bool')) complex_arr = materialize(remote_np.array([1+2j, 3+4j], dtype='complex128')) print(f"Float array: {float_arr}, dtype: {float_arr.dtype}") print(f"Int array: {int_arr}, dtype: {int_arr.dtype}") print(f"Bool array: {bool_arr}, dtype: {bool_arr.dtype}") print(f"Complex array: {complex_arr}, dtype: {complex_arr.dtype}") # Multi-dimensional arrays arr_2d = materialize(remote_np.array([[1, 2, 3], [4, 5, 6]])) arr_3d = materialize(remote_np.zeros((2, 3, 4))) print(f"2D shape: {arr_2d.shape}") # (2, 3) print(f"3D shape: {arr_3d.shape}") # (2, 3, 4) # Common array creation functions zeros = materialize(remote_np.zeros(5)) ones = materialize(remote_np.ones((3, 3))) arange = materialize(remote_np.arange(0, 10, 2)) linspace = materialize(remote_np.linspace(0, 1, 5)) print(f"Zeros: {zeros}") # [0. 0. 0. 0. 0.] print(f"Ones shape: {ones.shape}") # (3, 3) print(f"Arange: {arange}") # [0 2 4 6 8] print(f"Linspace: {linspace}") # [0. 0.25 0.5 0.75 1. ] # Array operations arr = remote_np.arange(20).reshape(4, 5) transposed = materialize(arr.T) mean_all = materialize(arr.mean()) sum_axis0 = materialize(arr.sum(axis=0)) print(f"Original shape: {materialize(arr).shape}") # (4, 5) print(f"Transposed shape: {transposed.shape}") # (5, 4) print(f"Mean: {mean_all}") # 9.5 print(f"Sum along axis 0: {sum_axis0}") # [30 34 38 42 46] conn.disconnect() ``` -------------------------------- ### Access Remote Modules via Connection - Python Source: https://context7.com/milkclouds/simplerpyc/llms.txt Shows how to access remote modules through the Connection object's modules namespace. It explains that operations on proxies are lazy and data isn't transferred until materialized. ```python from simplerpyc import connect, materialize conn = connect("localhost", 8000) # Access remote modules remote_os = conn.modules.os remote_numpy = conn.modules.numpy # All operations return proxies (no data transfer yet) cwd_proxy = remote_os.getcwd() arr_proxy = remote_numpy.array([1, 2, 3, 4, 5]) mean_proxy = arr_proxy.mean() # Materialize to get actual values cwd = materialize(cwd_proxy) # e.g., "/home/user/project" arr = materialize(arr_proxy) # numpy.ndarray([1, 2, 3, 4, 5]) mean = materialize(mean_proxy) # 3.0 print(f"Current directory: {cwd}") print(f"Array: {arr}") print(f"Mean: {mean}") conn.disconnect() ``` -------------------------------- ### Explicit Materialization of RPC Results Source: https://github.com/milkclouds/simplerpyc/blob/main/docs/SPEC.md Demonstrates the explicit materialization of objects returned from RPC calls. By default, objects are returned as RPCProxies. Users must call `materialize()` to fetch the actual values when needed, ensuring predictable data handling. ```python import simplerpyc from simplerpyc import materialize # Everything is proxy by default env = simpler_env.make('...') # RPCProxy result = env.step(action) # RPCProxy # Explicit materialization when needed obs, reward, done, truncated, info = materialize(result) # actual values instruction = materialize(env.get_language_instruction()) # str # Partial materialization also possible obs = materialize(result[0]) # only observation reward = materialize(result[1]) # only reward ``` -------------------------------- ### SimpleRPyC Connection Management API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Provides methods for managing the connection to the SimpleRPyC server. `disconnect()` closes the active connection. ```python conn.disconnect() # Close connection ``` -------------------------------- ### SimpleRPyC Client: Module Patching Style Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Connects to a SimpleRPyC server and patches specified modules (e.g., 'os', 'numpy') so they can be used remotely as if they were local. Results from remote operations can be materialized into local Python objects. ```python import simplerpyc from simplerpyc import materialize # Connect to server conn = simplerpyc.connect("localhost", 8000) # Patch modules to use remote versions simplerpyc.patch_module(conn, "os") simplerpyc.patch_module(conn, "numpy") # Import and use as if they were local import os import numpy as np cwd = materialize(os.getcwd()) arr = materialize(np.array([1, 2, 3])) conn.disconnect() ``` -------------------------------- ### SimpleRPyC Utility Functions API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Includes utility functions for working with SimpleRPyC. `materialize()` converts a remote proxy to a local value, and `is_proxy()` checks if an object is a remote proxy. ```python from simplerpyc import materialize, is_proxy value = materialize(proxy) # Convert proxy to actual value is_remote = is_proxy(obj) # Check if object is a proxy ``` -------------------------------- ### SimpleRPyC Remote Code Execution API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Allows execution of Python code on the remote server. `eval()` evaluates an expression and returns its result (materialized), while `execute()` runs code that does not return a value. ```python # Evaluate expression result = materialize(conn.eval("2 + 3")) # 5 # Execute code (no return value) conn.execute("x = 42") x = materialize(conn.eval("x")) # 42 ``` -------------------------------- ### SimpleRPyC Function Teleportation API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Enables sending a local Python function to the remote server to be executed there. The `teleport()` function returns a proxy that can be called remotely. ```python # Send local function to remote def square(x): return x ** 2 remote_square = conn.teleport(square) result = materialize(remote_square(5)) # 25 ``` -------------------------------- ### SimpleRPyC Module Patching API Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Patches a specified module on the client side to use the remote version provided by the SimpleRPyC server. This allows subsequent imports of the module to resolve to the remote implementation. ```python import simplerpyc simplerpyc.patch_module(conn, "os") # Patch sys.modules import os # Now uses remote version ``` -------------------------------- ### SimpleRPyC Client: Explicit Remote Access Style Source: https://github.com/milkclouds/simplerpyc/blob/main/README.md Connects to a SimpleRPyC server and accesses remote modules (e.g., 'os', 'numpy') explicitly through the connection object. This style also allows materializing remote results into local Python objects. ```python from simplerpyc import connect, materialize # Connect to server conn = connect("localhost", 8000) # Access remote modules explicitly remote_os = conn.modules.os remote_np = conn.modules.numpy # Everything returns proxies by default cwd = materialize(remote_os.getcwd()) arr = materialize(remote_np.array([1, 2, 3])) conn.disconnect() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.