Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a naming convention for Jumanji envs #248

Open
1 task done
WiemKhlifi opened this issue Oct 22, 2024 · 2 comments
Open
1 task done

Create a naming convention for Jumanji envs #248

WiemKhlifi opened this issue Oct 22, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@WiemKhlifi
Copy link
Contributor

Is your feature request related to a problem? Please describe

Configuring environments in Jumanji involves manually setting different parameters such as grid size, number of agents etc. This manual setup is not only time consuming but complicates the integration of Jumanji envs with RL frameworks like MAVA. Each new scenario addition currently requires a distinct YAML configuration, as seen here in the MAVA repo.

Describe the solution you'd like

I propose implementing a standardised naming convention for Jumanji envs that succinctly encodes all necessary parameters into the environment's name. This approach would mimic the simplicity of classical Gym envs. For example:

# Initialize the Level-Based Foraging environment with concise identifiers.
env = gym.make("Foraging-2s-8x8-2p-2f-coop-v3")

A function to extract and apply this naming convention could look like this:

def get_lbf_config(scenario):
    # Example format: "2s-10x10-3p-3f-coop"
    parts = scenario.split('-')
    grid_size = int(parts[1].split('x')[0])
    fov = int(parts[0].rstrip('s')) if 's' in parts[0] else grid_size
    num_agents = int(parts[2].rstrip('p'))
    num_food = int(parts[3].rstrip('f'))
    force_coop = 'coop' in parts

    return {
        "grid_size": grid_size,
        "fov": fov,
        "num_agents": num_agents,
        "num_food": num_food,
        "force_coop": force_coop,
        "max_agent_level": 2,  # Set as default
    }

Describe alternatives you've considered

An alternative could involve establishing a registration system akin to Gym's, where we can register environments with predefined attributes:

from gymnasium import register

# Example permutations for environment registration
for s, p, f, coop, po in itertools.product(
    range(5, 20), range(2, 10), range(1, 10), [True, False], [True, False]
):
    register(
        id=f"Foraging-{'2s' if po else ''}{s}x{s}-{p}p-{f}f{'-coop' if coop else ''}-v3",
        entry_point="lbforaging.foraging:ForagingEnv",
        kwargs={
            "field_size": (s, s),
            "num_agents": p,
            "num_food": f,
            "sight": 2 if po else s,
            "force_coop": coop,
            "max_episode_steps": 50,
            "grid_observation": not po,
        },
    )

Misc

  • Check for duplicate requests.
@WiemKhlifi WiemKhlifi added the enhancement New feature or request label Oct 22, 2024
@sash-a
Copy link
Collaborator

sash-a commented Oct 29, 2024

I think this would be very nice, but how would jumanji.make pick it up if it's not registered? I think make would then need to call this method, register the env if it's valid and then make the env? I'd be interested to a POC for this if you have some capacity to implement it?

@WiemKhlifi
Copy link
Contributor Author

I'd like to make a POC probably in the upcoming weeks ( I'll make progress based on the other tasks), but we can make something like the ones in matrax here using jumanji register which is similar to what gymnasium do and cleaner than what first method do. But still, the first method quicker and doesn't need to store anything like a register.
Probably a POC using the Jumanji register to check the feasibility of this (second method) and ensure we don't have the same issues we had with the gym. What do you think?

@WiemKhlifi WiemKhlifi self-assigned this Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants