zero icon indicating copy to clipboard operation
zero copied to clipboard

Feature Request: allowing NoneType return, support multiple argument for RPC function

Open MilkClouds opened this issue 2 months ago • 1 comments

I'm trying to set up a clean separation between RL policy and RL environment execution using this project. My basic flow is:

  1. Open a new env on remote
  2. Run env.step until the episode ends
  3. Call env.close

I ran into some issues:

  1. No numpy support in zero.
    I solved this by writing a new encoder that handles numpy arrays:

    import asyncio
    import io
    from typing import Any, Type
    
    import numpy as np
    from zero import AsyncZeroClient
    from zero.encoder.generic import GenericEncoder
    from zero.encoder.msgspc import T
    
    class GenericEncoderWithNumpySupport(GenericEncoder):
        def encode(self, data) -> bytes:
            if isinstance(data, np.ndarray):
                buffer = io.BytesIO()
                np.save(buffer, data)
                return super().encode(buffer.getvalue())
            return super().encode(data)
    
        def decode(self, data: bytes) -> Any:
            decoded_data = super().decode(data)
            if decoded_data[1:6] == b"NUMPY":  # MAGIC string for numpy array
                buffer = io.BytesIO(decoded_data)
                return np.load(buffer)
            return decoded_data
    
        def decode_type(self, data: bytes, typ: Type[T]) -> T:
            if issubclass(typ, np.ndarray):
                decoded_data = self.decode(data)
                buffer = io.BytesIO(decoded_data)
                return np.load(buffer)
            return super().decode_type(data, typ)
    
        def is_allowed_type(self, typ: Type) -> bool:
            return super().is_allowed_type(typ) or typ is np.ndarray
    
  2. NoneType return disallowed.
    It's an annoying restriction—I just worked around this by returning a dummy value.

  3. No support for multiple arguments.
    This was a deal breaker for me. Not supporting multiple arguments made it pretty hard to proceed, so I stopped here.

Would be nice if these issues could get some attention. The numpy part is easily fixable, but the lack of multi-argument support is really limiting.

MilkClouds avatar Nov 11 '25 08:11 MilkClouds

Hi @MilkClouds Nice to see that you are putting some valuable feedback and suggestions, thanks for that.

  1. Supporting numpy is a custom choice, and you already made a customer encoder, this should be good.
  2. Returning None is by default anti-pattern (it's kind of opinionated). You could return "ok".
  3. This is something that needs attention, my initial thought was anything can be sent in a single argument by using pydantic or msgspec. Think of it like a request body. But I am also thinking now we could support multiple arguments, I will take a look.

Ananto30 avatar Nov 17 '25 11:11 Ananto30