Example #1
0
def handle_universe_wrap(sock, uni, env):
    """
    Wrap a Universe environment.
    """
    wrapper_name = proto.read_field_str(sock)
    config_json = proto.read_field_str(sock)
    try:
        env = uni.wrap(env, wrapper_name, json.loads(config_json))
        proto.write_field_str(sock, '')
    except universe_plugin.UniverseException as exc:
        proto.write_field_str(sock, str(exc))
    sock.flush()
    return env
Example #2
0
def handle_retro_wrap(sock, retro, env):
    """
    Wrap a Retro environment.
    """
    wrapper_name = proto.read_field_str(sock)
    config_json = proto.read_field_str(sock)
    try:
        env = retro.wrap(env, wrapper_name, json.loads(config_json))
        proto.write_field_str(sock, '')
    except retro_plugin.RetroException as exc:
        proto.write_field_str(sock, str(exc))
    sock.flush()
    return env
Example #3
0
def handle_upload(sock):
    """
    Upload a monitor to the Gym website.
    """
    dir_path = proto.read_field_str(sock)
    api_key = proto.read_field_str(sock)
    alg_id = proto.read_field_str(sock)
    if alg_id == '':
        alg_id = None
    try:
        gym.upload(dir_path, api_key=api_key, algorithm_id=alg_id)
        proto.write_field_str(sock, '')
    except gym.error.Error as exc:
        proto.write_field_str(sock, str(exc))
    sock.flush()
Example #4
0
def handshake(sock):
    """
    Perform the initial handshake and return the resulting
    Gym environment.
    """
    flags = proto.read_flags(sock)
    if flags != 0:
        raise proto.ProtoException('unsupported flags: ' + str(flags))
    env_name = proto.read_field_str(sock)

    # Special no-environment mode.
    if env_name == '':
        proto.write_field_str(sock, '')
        sock.flush()
        return None

    try:
        env = gym.make(env_name)
        proto.write_field_str(sock, '')
        sock.flush()
        return env
    except gym.error.Error as gym_exc:
        proto.write_field_str(sock, str(gym_exc))
        sock.flush()
        raise gym_exc
Example #5
0
def handle_universe_configure(sock, uni, env):
    """
    Configure a Universe environment.
    """
    config_json = proto.read_field_str(sock)
    try:
        env = uni.configure(env, json.loads(config_json))
        proto.write_field_str(sock, '')
    except universe_plugin.UniverseException as exc:
        proto.write_field_str(sock, str(exc))
    sock.flush()
    return env
Example #6
0
def handle_retro_configure(sock, retro, env):
    """
    Configure a Retro environment.
    """
    config_json = proto.read_field_str(sock)
    try:
        env = retro.configure(env, json.loads(config_json))
        proto.write_field_str(sock, '')
    except retro_plugin.RetroException as exc:
        proto.write_field_str(sock, str(exc))
    sock.flush()
    return env
Example #7
0
def handle_monitor(sock, env):
    """
    Start a monitor and return the new environment.
    """
    resume = proto.read_bool(sock)
    force = proto.read_bool(sock)
    video = proto.read_bool(sock)
    dir_path = proto.read_field_str(sock)
    try:
        vid_call = None
        if not video:
            vid_call = lambda count: False
        res = wrappers.Monitor(env,
                               dir_path,
                               resume=resume,
                               force=force,
                               video_callable=vid_call)
        proto.write_field_str(sock, '')
        sock.flush()
        return res
    except gym.error.Error as exc:
        proto.write_field_str(sock, str(exc))
        sock.flush()
        return env