Skip to content
This repository has been archived by the owner on May 21, 2022. It is now read-only.

Please add / document how to access observation and action spaces #41

Open
bionicles opened this issue May 29, 2020 · 4 comments
Open

Comments

@bionicles
Copy link

For architecture search across a variety of environments, it's crucial to access the parameters of the observation and action spaces.

How do you do that with this library?

@bionicles
Copy link
Author

bionicles commented May 29, 2020

function show_box_space(s)
    shape = s.shape
    dtype = pystr(s.dtype)
    target_type = occursin("int", dtype) ? Int : Float
    high = map(target_type, Array(s.high))
    low = map(target_type, Array(s.low))
    println("Box$shape")
    @show dtype
    @show high[1]
    @show low[1]
    return Dict("kind"=>"Box", "shape"=>shape, "dtype"=>dtype, "high"=>high, "low"=>low)
end

function show_discrete_space(s)
    n = s.n
    println("Discrete($n)")
    return Dict("kind"=>"Discrete", "n"=>n)
end

function show_space(s)
    space_repr = pystr(s)
    if occursin("Discrete", space_repr)
        return show_discrete_space(s)
    elseif occursin("Box", space_repr)
        return show_box_space(s)
    else
        print("WARNING: $space_repr unsupported!!!!1")
    end
end

function show_spaces(env_name)
    env = GymEnv(env_name)
    @show env_name
    println()
    println("Observation Space:")
    observation_space_dict = show_space(env.pyenv.observation_space)
    println()
    println("Action Space:")
    action_space_dict = show_space(env.pyenv.action_space)
    println()
    close(env)
    env_dict = Dict("name"=>env_name, "observation_space"=>observation_space_dict, "action_space"=>action_space_dict)
    return env_dict
end

env_names = ["procgen:procgen-$stub-v0" for stub in ["bigfish","bossfight","caveflyer","chaser","climber","coinrun","dodgeball","fruitbot",
    "heist","jumper","leaper","maze","miner","ninja","plunder","starpilot"]]
[show_spaces(env_name) for env_name in env_names]

^^^ I just wrote this. MIT License

@bionicles
Copy link
Author

Here is the result for all of the ProcGen envs:

Observation Space:
Box(64, 64, 3)
dtype = "uint8"
high[1] = 255
low[1] = 0

Action Space:
Discrete(15)

@iblislin
Copy link
Member

iblislin commented Jun 1, 2020

Hi @bionicles,
Thanks for your suggestions.
Could you open a PR and put this code into a examples dir in this repo?

@bionicles
Copy link
Author

sorry, i'm not working in julia right now, but you're welcome to reuse the code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants