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

simple_example.py is unstable #465

Closed
OrionZou opened this issue Jan 22, 2021 · 8 comments
Closed

simple_example.py is unstable #465

OrionZou opened this issue Jan 22, 2021 · 8 comments

Comments

@OrionZou
Copy link

OrionZou commented Jan 22, 2021

I run smarts.env:hiway-v0. it will stop unexpectedly.

my error (I clone SMARTS in Nov. 25 ,2020)
image

mycode:

import os

os.environ['SUMO_HOME'] = "/home/user/repos/sumo"

import gym
from smarts.core.agent_interface import AgentInterface, AgentType
from smarts.core.agent import AgentSpec, Agent
from elegantRL.env_util.continuous_space import agent_interface, observation_adapter, reward_adapter, action_adapter, \
    info_adapter, ACTION_SPACE
import numpy as np


class SimpleAgent(Agent):
    def __init__(self):
        self.action_space = gym.spaces.Box(
            low=np.array([0, 0, -1.0]), high=np.array([1.0, 1.0, 1.0]), dtype=np.float32
        )

    def act(self, obs):
        # return "keep_lane"
        return self.action_space.sample()


agent_spec = AgentSpec(
    interface=AgentInterface.from_type(AgentType.Full, max_episode_steps=None),
    agent_builder=SimpleAgent,
)

agent_specs = {
    "Agent-001": agent_spec,
    # "Agent-008": agent_spec,
}

env = gym.make(
    "smarts.env:hiway-v0",
    scenarios=["scenarios/loop"],
    agent_specs=agent_specs,
)

agents = {
    agent_id: agent_spec.build_agent()
    for agent_id, agent_spec in agent_specs.items()
}
observations = env.reset()

for i in range(100000000):
    print(i)
    agent_actions = {
        agent_id: agents[agent_id].act(agent_obs)
        for agent_id, agent_obs in observations.items()
    }
    for agent_id, agent_obs in observations.items():
        a = agents[agent_id].act(agent_obs)
    observations, r, d, i = env.step(agent_actions)
    if d:
        observations = env.reset()
@Gamenot
Copy link
Collaborator

Gamenot commented Jan 25, 2021

@GyChou Hello, sorry for the late reply. We are currently dealing with a non-trivial edge case issue regarding SUMO.

#472

What this means in this case is that you will be unable to make use of bubbles for now. Since "scenarios/loop" contains a bubble it has the possibility to crash.

It will mean removing the bubble in scenarios/loop/scenario.py and then using scl scenario build scenarios/loop --clean to rebuild the scenario.

There is the potential that this is from a different source so I am going to run your example overnight to see if I can catch it.

@Gamenot
Copy link
Collaborator

Gamenot commented Jan 25, 2021

Could you also update your post with your SUMO version and version of SMARTS?

You can get the sumo version with sumo --version (or /home/user/repos/sumo/bin/sumo in your case) and smarts version from your virtual environment with pip freeze | grep smarts if you used a package or by checking the version in setup.py if you are using the repository.

Thanks~

@Gamenot
Copy link
Collaborator

Gamenot commented Jan 25, 2021

This crash is interesting, I have not seen it before. It appears like it could be from the number of times resetting SUMO.

@liamchzh has the behaviour with resetting SUMO changed? I seem to remember terminating and restarting SUMO before.

@liamchzh
Copy link
Contributor

Yes, if we are reusing the same map when resetting, then reload SUMO instead of restart

# restart sumo process only when map file changes
if self._scenario and self._scenario.net_file_hash == scenario.net_file_hash:
restart_sumo = False
else:
restart_sumo = True

@Gamenot
Copy link
Collaborator

Gamenot commented Jan 26, 2021

I have confirmed, SUMO can freeze when reloading too many times.

pybullet build time: Dec 23 2020 01:47:29
32427
pybullet build time: Dec 23 2020 01:47:29
32428
pybullet build time: Dec 23 2020 01:47:29
32429
Traceback (most recent call last):
  File "examples/simple_example_test.py", line 55, in <module>
    observations = env.reset()
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/env/hiway_env.py", line 188, in reset
    env_observations = self._smarts.reset(scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 314, in reset
    self.setup(scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 361, in setup
    provider_state = self._setup_providers(self._scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 656, in _setup_providers
    provider_state.merge(provider.setup(scenario))
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/sumo_traffic_simulation.py", line 247, in setup
    self._traci_conn.simulation.subscribe(
  File "/usr/share/sumo/tools/traci/_simulation.py", line 468, in subscribe
    Domain.subscribe(self, "", varIDs, begin, end)
  File "/usr/share/sumo/tools/traci/domain.py", line 209, in subscribe
    self._connection._subscribe(self._subscribeID, begin, end, objectID, varIDs, parameters)
  File "/usr/share/sumo/tools/traci/connection.py", line 242, in _subscribe
    result = self._sendCmd(cmdID, (begin, end), objID, format, *args)
  File "/usr/share/sumo/tools/traci/connection.py", line 180, in _sendCmd
    return self._sendExact()
  File "/usr/share/sumo/tools/traci/connection.py", line 90, in _sendExact
    raise FatalTraCIError("connection closed by SUMO")
traci.exceptions.FatalTraCIError: connection closed by SUMO

My device also ended with a surprising error:

image

@Gamenot
Copy link
Collaborator

Gamenot commented Jan 26, 2021

    if d:
        observations = env.reset()

One thing to note here is that this snippet should be:

    if d["__all__"]:
        observations = env.reset()

Or the example will end early.

@liamchzh
Copy link
Contributor

liamchzh commented Jan 26, 2021

I have confirmed, SUMO can freeze when reloading too many times.

pybullet build time: Dec 23 2020 01:47:29
32427
pybullet build time: Dec 23 2020 01:47:29
32428
pybullet build time: Dec 23 2020 01:47:29
32429
Traceback (most recent call last):
  File "examples/simple_example_test.py", line 55, in <module>
    observations = env.reset()
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/env/hiway_env.py", line 188, in reset
    env_observations = self._smarts.reset(scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 314, in reset
    self.setup(scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 361, in setup
    provider_state = self._setup_providers(self._scenario)
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/smarts.py", line 656, in _setup_providers
    provider_state.merge(provider.setup(scenario))
  File "/home/dev/Desktop/repos/NewSMARTS/SMARTS/smarts/core/sumo_traffic_simulation.py", line 247, in setup
    self._traci_conn.simulation.subscribe(
  File "/usr/share/sumo/tools/traci/_simulation.py", line 468, in subscribe
    Domain.subscribe(self, "", varIDs, begin, end)
  File "/usr/share/sumo/tools/traci/domain.py", line 209, in subscribe
    self._connection._subscribe(self._subscribeID, begin, end, objectID, varIDs, parameters)
  File "/usr/share/sumo/tools/traci/connection.py", line 242, in _subscribe
    result = self._sendCmd(cmdID, (begin, end), objID, format, *args)
  File "/usr/share/sumo/tools/traci/connection.py", line 180, in _sendCmd
    return self._sendExact()
  File "/usr/share/sumo/tools/traci/connection.py", line 90, in _sendExact
    raise FatalTraCIError("connection closed by SUMO")
traci.exceptions.FatalTraCIError: connection closed by SUMO

Are you able to reproduce this if we force SUMO to restart everytime?

@Gamenot Gamenot added this to the Backlog milestone Jan 27, 2021
@Gamenot
Copy link
Collaborator

Gamenot commented Feb 3, 2021

Closed since we found the cause in #480.

@Gamenot Gamenot closed this as completed Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants