LucasAlegre / sumo-rl

Reinforcement Learning environments for Traffic Signal Control with SUMO. Compatible with Gymnasium, PettingZoo, and popular RL libraries.
https://lucasalegre.github.io/sumo-rl
MIT License
720 stars 196 forks source link

Bad result when running experiments/ppo_4x4grid.py #147

Open sitexa opened 1 year ago

sitexa commented 1 year ago

I got bad result when runningpython experiments/ppo_4x4grid.py, outputs/4x4grid/ppo_conn0_ep2.cvs: So, when run python outputs/plot.py -f -f outputs/4x4grid/ppo_conn0_ep2.cvs, exceptions were raised out.

My environment is as following:

sumo: 1.18.0
sumo-rl: 1.4.3
gymnasium: 0.26.3
stable-baselines3: 2.0.0a13 
ray: 2.5.0
python: 3.10.11

Can anyone get rid of this error? Thanks.

LucasAlegre commented 1 year ago

Which exceptions were raised?

sitexa commented 1 year ago

The errors were as following:

python outputs/plot.py -f tests/ppo_conn0_ep2.csv
  Traceback (most recent call last):
    File "/Users/xnpeng/sumoptis/sumo-rl/outputs/plot.py", line 90, in <module>
      plot_df(main_df, xaxis=args.xaxis, yaxis=args.yaxis, label=next(labels), color=next(colors), ma=args.ma)
    File "/Users/xnpeng/sumoptis/sumo-rl/outputs/plot.py", line 43, in plot_df
      df[yaxis] = pd.to_numeric(df[yaxis], errors="coerce")  # convert NaN string to NaN value
    File "/Users/xnpeng/miniforge3/envs/sumoai/lib/python3.10/site-packages/pandas/core/frame.py", line 3761, in __getitem__
      indexer = self.columns.get_loc(key)
    File "/Users/xnpeng/miniforge3/envs/sumoai/lib/python3.10/site-packages/pandas/core/indexes/range.py", line 349, in get_loc
      raise KeyError(key)
  KeyError: 'system_total_waiting_time'

I found it was the data error , no comma char between 2 lines, maybe produced when saving result to csv file :


        def save_csv(self, out_csv_name, episode):
        """Save metrics of the simulation to a .csv file.

        Args:
            out_csv_name (str): Path to the output .csv file. E.g.: "results/my_results
            episode (int): Episode number to be appended to the output file name.
        """
        if out_csv_name is not None:
            df = pd.DataFrame(self.metrics)
            Path(Path(out_csv_name).parent).mkdir(parents=True, exist_ok=True)
            df.to_csv(out_csv_name + f"_conn{self.label}_ep{episode}" + ".csv", index=False)

LucasAlegre commented 1 year ago

Are you using Windows, @sitexa ? This error does not occur for me

sitexa commented 1 year ago

Are you using Windows, @sitexa ? This error does not occur for me

Sometime happen sometime not, depends on the data, maybe empty or null fields. MacOS.

sitexa commented 1 year ago

Are you using Windows, @sitexa ? This error does not occur for me

Sometime happen sometime not, depends on the data, maybe empty or null fields. MacOS.

Also on Ubuntu, there were data format error, every run.

Please take a look at the csv file: ppo_conn0_ep2.csv

@LucasAlegre

LucasAlegre commented 1 year ago

Was this already fixed in the last commit? @sitexa

sitexa commented 1 year ago

Was this already fixed in the last commit? @sitexa

Not yet. It's the same error, data error in ppo_conn0_ep2.csv, when run plot.py.

TypeError: Could not convert 0.81648920.0 to numeric
image
sitexa commented 1 year ago

I solved the problem temporary by changing the plot.py code:

df = pd.read_csv(f, sep=args.sep, on_bad_lines="skip", usecols=[args.xaxis, args.yaxis], converters={args.xaxis: convert_to_float, args.yaxis: convert_to_float})

where convert_to_float is as bellow:

def convert_to_float(x) -> float:
    try:
        return float(x)
    except:
        return float(0)