def get_many(client: Client) -> List[Dict]:
    """Gets leagues that belong to an authenticated user.

    Parameters:
        client (Client): Authenticated client.
    
    Returns:
        List of leagues.

    """
    response = client.get(f"{LEAGUE_PREFIX}/")
    return response.json()
Example #2
0
def get_many(client: Client) -> List[Dict]:
    """Gets environments belonging to authenticated user.

    Parameters:
        client (Client): Authenticated client.
    
    Returns:
        List of environments.

    """
    response = client.get(f"{ENV_PREFIX}/")
    return response.json()
def get_many(client: Client) -> List[Dict]:
    """Gets agents belonging to authenticated user.

    Parameters:
        client (Client): Authenticated client.
    
    Returns:
        List of agents.

    """
    response = client.get(f'{AGENTS_PREFIX}/')
    response_raise_error_if_any(response)
    return response.json()
Example #4
0
def delete(client: Client, env_name: str) -> bool:
    """Deletes specified environment.

    Parameters:
        client (Client): Authenticated client.
        env_name (str): Name of the environment.

    Returns:
        Whether environment was delete. True if an environment was delete, False if there was no such environment.

    """
    response = client.delete(f'{ENV_PREFIX}/{env_name}')
    response_raise_error_if_any(response)
    return response.status_code == 202
Example #5
0
def get(client: Client, env_name: str) -> Dict:
    """Get indepth information about a specific environment.

    Parameters:
        client (Client): Authenticated client.
        env_name (str): Name of environment.
    
    Returns:
        Details of an environment.

    """
    response = client.get(f'{ENV_PREFIX}/{env_name}')
    response_raise_error_if_any(response)
    return response.json()
Example #6
0
def reset(client: Client, env_name: str) -> List[float]:
    """Resets the environment to starting position.

    Parameters:
        client (Client): Authenticated client.
        env_name (str): Name of the environment.
    
    Returns:
        Environment state in the starting position.

    """
    response = client.post(f"{ENV_PREFIX}/{env_name}/reset")
    response_raise_error_if_any(response)
    return response.json()
def get_loss(client: Client, agent_name: str) -> Dict:
    """Recent loss metrics.

    Parameters:
        client (Client): Authenticated client.
        agent_name (str): Name of agent.
    
    Returns:
        Loss metrics in a dictionary.

    """
    response = client.get(f'{AGENTS_PREFIX}/{agent_name}/loss')
    response_raise_error_if_any(response)
    return response.json()
def delete(client: Client, agent_name: str) -> bool:
    """Deletes specified agent.

    Parameters:
        client (Client): Authenticated client.
        agent_name (str): Name of agent to delete.

    Returns:
        Whether agent was delete. True if an agent was delete, False if there was no such agent.

    """
    response = client.delete(f'{AGENTS_PREFIX}/{agent_name}')
    response_raise_error_if_any(response)
    return response.status_code == 202
def get(client: Client, league_name: str) -> Dict:
    """Get indepth information about a specific league.

    Parameters:
        client (Client): Authenticated client.
        league_name (str): Name of league.
    
    Returns:
        Details of an league.

    """
    response = client.get(f'{LEAGUE_PREFIX}/{league_name}')
    response_raise_error_if_any(response)
    return response.json()
Example #10
0
def get(client: Client, agent_name: str) -> Dict:
    """Get indepth information about a specific agent.

    Parameters:
        client (Client): Authenticated client.
        agent_name (str): Name of agent.
    
    Returns:
        Details of an agent.

    """
    response = client.get(f'{AGENTS_PREFIX}/{agent_name}')
    response_raise_error_if_any(response)
    return response.json()
def delete(client: Client, league_name: str) -> bool:
    """Deletes specified league.

    Parameters:
        client (Client): Authenticated client.
        league_name (str): Name of the league.

    Returns:
        Whether league was delete. True if an league was delete, False otherwise.

    """
    response = client.delete(f'{LEAGUE_PREFIX}/{league_name}')
    response_raise_error_if_any(response)
    return response.status_code == 202
def create(client: Client, league_create: LeagueCreate) -> Dict:
    """Creates an league with specified configuration.

    Parameters:
        client (Client): Authenticated client.
        league_create (LeagueCreate): League create instance.
    
    Returns:
        Details of an league.

    """
    response = client.post(f'{LEAGUE_PREFIX}/', data=asdict(league_create))
    response_raise_error_if_any(response)
    return response.json()
def start(client: Client, league_name: str, config: Optional[Dict] = None) -> str:
    """Starts league, i.e. creates experiments with provided agents and environments.

    Parameters:
        client (Client): Authenticated client.
        league_name (str): Name of the league.
    
    Returns:
        Information about started league.
    
    """
    config = config or {}
    response = client.post(f"{LEAGUE_PREFIX}/{league_name}/start", data=config)
    response_raise_error_if_any(response)
    return "Started successfully" if response.ok else "Failed to start"
Example #14
0
def create(client: Client, env_create: EnvironmentCreate) -> Dict:
    """Creates an environment with specified configuration.

    Parameters:
        client (Client): Authenticated client.
        config (dict): Configuration of an environment.
    
    Returns:
        Details of an environment.

    """
    env_create_dict = asdict(env_create)
    response = client.post(f'{ENV_PREFIX}/', data=env_create_dict)
    response_raise_error_if_any(response)
    return response.json()
Example #15
0
def step(client: Client, env_name: str, step) -> Dict[str, Any]:
    """Steps the environment based on provided data.

    Parameters:
        client (Client): Authenticated client.
        env_name (str): Name of the environment.
        step (EnvStep): Step information for the environment. Consists of action details and whether to commit.
    
    Returns:
        Environment state after taking provided actions. Consists of "observation", "reward", "done" and "info".

    """
    response = client.post(f"{ENV_PREFIX}/{env_name}/step", data=step)
    response_raise_error_if_any(response)
    return response.json()
def reset(client: Client, league_name: str) -> str:
    """Resets the league to starting position.

    Doesn't affect Agent nor Environment. Only resets values related to the League.

    Parameters:
        client (Client): Authenticated client.
        league_name (str): Name of the league.
    
    Returns:
        Confirmation on reset league.

    """
    response = client.post(f"{LEAGUE_PREFIX}/{league_name}/reset")
    response_raise_error_if_any(response)
    return response.json()
Example #17
0
def commit(client: Client, env_name: str) -> Dict[str, Any]:
    """Commits last provided data. Must be proceeded by environment `step`.

    Useful when environment requires many agents or when agent is allowed to make mistakes.

    Parameters:
        client (Client): Authenticated client.
        env_name (str): Name of the environment
    
    Returns:
        Data about the state the environment has transtioned into.
        This should be the same as when using `step` with `commit=True`.
    
    """
    response = client.post(f"{ENV_PREFIX}/{env_name}/commit")
    response_raise_error_if_any(response)
    return response.json()
Example #18
0
def create(client: Client, agent_create: AgentCreate) -> Dict:
    """Creates an agent with specified configuration.

    Parameters:
        client (Client): Authenticated client.
        config (dict): Configuration of an agent.
    
    Returns:
        Details of an agent.

    """
    agent_create_dict = asdict(
        agent_create,
        dict_factory=lambda x: {k: v
                                for (k, v) in x if v is not None})
    response = client.post(f'{AGENTS_PREFIX}/', data=agent_create_dict)
    response_raise_error_if_any(response)
    return response.json()
def metrics(
    client: Client, league_name: str, metric_names: Optional[List[str]] = None, limit: int = 1,
) -> Dict[str, List[Tuple[int, float]]]:
    """Gets metrics obtained while running an league.

    Parameters:
        client (Client): Authenticated client.
        league_name (str): Name of the league.
        metric_names (Optional list of strings): List of metrics you are intrested in seeing.
            If None then it'll return all available. Defaults to None.
        limit (int): Number of last samples to return. Defaults to only the most recent metrics.
    
    Returns:
        Dictionary with keys being metric names and values in a list consisting of an index and value (tuple).
        For example:
            {
                "episode/score": [(10, -10), (9, -7), (8, 3)],
                "loss/actor": [(10, 1.5), (9, 4.1), (8, 0.99)]
            }
    
    """
    response = client.post(f"{LEAGUE_PREFIX}/{league_name}/metrics", data=metric_names, params=dict(limit=limit))
    response_raise_error_if_any(response)
    return response.json()
Example #20
0
def info(client: Client, env_name: str) -> Dict[str, Any]:
    response = client.get(f"{ENV_PREFIX}/{env_name}/info")
    response_raise_error_if_any(response)
    return response.json()