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

[Bug] Render not always working for gym engine #251

Open
jelledouwe opened this issue Mar 29, 2023 · 0 comments
Open

[Bug] Render not always working for gym engine #251

jelledouwe opened this issue Mar 29, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@jelledouwe
Copy link
Contributor

jelledouwe commented Mar 29, 2023

🐛 Bug

When using the gym engine, the human render screen does not always appear.

To Reproduce

Create object (for example pendulum-v1) with gym engine and single process backend.
Then call env.render("human") and train with sb3.

import eagerx
from eagerx_dcsc_setups.pendulum.objects import Pendulum
from eagerx_dcsc_setups.pendulum.envs import PendulumEnv
from eagerx.engines.openai_gym.engine import GymEngine
from eagerx.wrappers import Flatten
from eagerx.backends.single_process import SingleProcess

import stable_baselines3 as sb3
import gym.wrappers as w

if __name__ == "__main__":
    rate = 20

    # Create pendulum object
    pendulum = Pendulum.make(
        "pendulum",
        actuators=["u"],
        sensors=["x", "image"],
        states=["model_state", "max_speed", "length"],
        actuator_rate=rate,
        sensor_rate=rate,
    )

    # Create graph
    graph = eagerx.Graph.create()
    graph.add(pendulum)
    graph.connect(action="voltage", target=pendulum.actuators.u)
    graph.connect(source=pendulum.sensors.x, observation="angle_data")
    graph.render(source=pendulum.sensors.image, rate=rate)

    gym_engine = GymEngine.make(rate=rate, process=eagerx.ENVIRONMENT)

    backend = SingleProcess.make()

    # Create envs
    train_env = PendulumEnv(
        name="TrainEnv",
        rate=rate,
        graph=graph,
        engine=gym_engine,
        backend=backend,
    )
    train_env = w.rescale_action.RescaleAction(Flatten(train_env), min_action=-1.0, max_action=1.0)
    train_env.render("human")
    model = sb3.SAC("MlpPolicy", train_env, verbose=1, learning_rate=7e-4)
    model.learn(total_timesteps=5000)

Expected behavior

Render screen opening.
Note that a workaround is to do an extra reset before training.

@jelledouwe jelledouwe added the bug Something isn't working label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant