Pi-Star-Lab / RESCO

Reinforcement Learning Benchmarks for Traffic Signal Control (RESCO)
120 stars 37 forks source link

KeyError FMA2C 'top_mgr' #17

Closed Zackly23 closed 10 months ago

Zackly23 commented 1 year ago

Hi, Thanks for the code you shared

I try to run FMA2C agent with the available environment and its gives me an error about the 'top_mgr' like below

Traceback (most recent call last):
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 112, in <module>
    main()
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 36, in main
    run_trial(args, args.tr)
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 99, in run_trial
    agent = alg(agt_config, obs_act, args.map, trial)
  File "C:\Users\hp\Downloads\RESCO-V1\RESCO-main\resco_benchmark\agents\fma2c.py", line 45, in __init__
    self.managers[manager] = MA2CAgent(config, obs_act[manager][0], mgr_act_size, mgr_fingerprint_size, 0,
KeyError: 'top_mgr'

I am trying to fix it by changing obs_act in fma2c line 48 by

self.managers[manager] = MA2CAgent(config, obs_act[worker_ids[0]][0], mgr_act_size, mgr_fingerprint_size, 0,
                                                   manager + str(thread_number), self.sess)

but, its gives me another error like this

Traceback (most recent call last):
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 112, in <module>
    main()
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 36, in main
    run_trial(args, args.tr)
  File "C:/Users/hp/Downloads/RESCO-V1/RESCO-main/resco_benchmark/main.py", line 105, in run_trial
    act = agent.act(obs)
  File "C:\Users\hp\Downloads\RESCO-V1\RESCO-main\resco_benchmark\agents\fma2c.py", line 115, in act
    acts[agent_id] = self.managers[agent_id].act(combine)
  File "C:\Users\hp\Downloads\RESCO-V1\RESCO-main\resco_benchmark\agents\ma2c.py", line 127, in act
{'coef': 0.4, 'coop_gamma': 0.9, 'clip_wave': 4.0, 'clip_wait': 4.0, 'norm_wave': 5.0, 'norm_wait': 100.0, 'alpha': 0.75, 'management': {'top_mgr': ['360082', '360086'], 'bot_mgr': ['GS_cluster_2415878664_254486231_359566_359576']}, 'management_neighbors': {'top_mgr': ['bot_mgr'], 'bot_mgr': ['top_mgr']}, 'supervisors': {'360082': 'top_mgr', '360086': 'top_mgr', 'GS_cluster_2415878664_254486231_359566_359576': 'bot_mgr'}, 'cologne3': {...}}
    policy, self.value = self.model.forward(observation, False)
  File "C:\Users\hp\Downloads\RESCO-V1\RESCO-main\resco_benchmark\agents\ma2c.py", line 215, in forward
    return self.policy.forward(self.sess, obs, done, out_type)
  File "C:\Users\hp\Downloads\RESCO-V1\RESCO-main\resco_benchmark\agents\ma2c.py", line 377, in forward
    self.states: self.states_fw})
  File "C:\Users\hp\Downloads\RESCO-main\RESCO-main\venv\lib\site-packages\tensorflow_core\python\client\session.py", line 956, in run
    run_metadata_ptr)
  File "C:\Users\hp\Downloads\RESCO-main\RESCO-main\venv\lib\site-packages\tensorflow_core\python\client\session.py", line 1156, in _run
    (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1, 19) for Tensor 'Placeholder:0', which has shape '(1, 20)'
Error: tcpip::Socket::recvAndCheck @ recv: peer shutdown
Quitting (on error).

Thank You

jault commented 1 year ago

Hi, please try commenting out this line: https://github.com/Pi-Star-Lab/RESCO/blob/main/resco_benchmark/multi_signal.py#L75 It was added for compatibility with another library. I'll see about a proper fix if commenting it out works here for you. Please let me know!

Zackly23 commented 1 year ago

Hi jault, thanks for the response I am following your instruction by commenting out line 75 of multi_signal and trying to rerun the agent, but it gives me an error like this

Traceback (most recent call last):
  File "C:/Users/hp/Downloads/RESCO-V2/RESCO-main/resco_benchmark/main.py", line 109, in <module>
    main()
  File "C:/Users/hp/Downloads/RESCO-V2/RESCO-main/resco_benchmark/main.py", line 36, in main
    run_trial(args, args.tr)
  File "C:/Users/hp/Downloads/RESCO-V2/RESCO-main/resco_benchmark/main.py", line 85, in run_trial
    log_dir=args.log_dir, libsumo=args.libsumo, warmup=map_config['warmup'])
  File "C:\Users\hp\Downloads\RESCO-V2\RESCO-main\resco_benchmark\multi_signal.py", line 83, in __init__
    self.action_space.append(gym.spaces.Discrete(len(self.phases[ts])))
KeyError: 'top_mgr'

it seems like self.phases does not have a key attribute of top_mgr.

Thank you

demetere commented 1 year ago

Hello @Zackly23, try this, it may work:

for ts in observations:
            o_shape = observations[ts].shape
            self.obs_shape[ts] = o_shape
            o_shape = gym.spaces.Box(low=-np.inf, high=np.inf, shape=o_shape)
            self.ts_order.append(ts)
            self.observation_space.append(o_shape)
            if ts == 'top_mgr' or ts == 'bot_mgr': continue     # Not a traffic signal
            self.action_space.append(gym.spaces.Discrete(len(self.phases[ts])))

meaning move https://github.com/Pi-Star-Lab/RESCO/blob/main/resco_benchmark/multi_signal.py#L75 before this acttion self.action_space.append(gym.spaces.Discrete(len(self.phases[ts]))) that is https://github.com/Pi-Star-Lab/RESCO/blob/main/resco_benchmark/multi_signal.py#L81 ,

I dont know how correct is this fix, I am running some experiments too and it is running after this change. Hope it will help you too. I will make pull request later with all changes and little bugs I found

jault commented 10 months ago

https://github.com/Pi-Star-Lab/RESCO/commit/567cece6d0694c1c16b2687df445e02860fb0e9e