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

Bad result when running experiments/ppo_4x4grid.py #147

Open
sitexa opened this issue Jul 19, 2023 · 8 comments
Open

Bad result when running experiments/ppo_4x4grid.py #147

sitexa opened this issue Jul 19, 2023 · 8 comments

Comments

@sitexa
Copy link

sitexa commented Jul 19, 2023

I got bad result when running python 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
Copy link
Owner

Which exceptions were raised?

@sitexa
Copy link
Author

sitexa commented Jul 21, 2023

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
Copy link
Owner

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

@sitexa
Copy link
Author

sitexa commented Jul 24, 2023

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
Copy link
Author

sitexa commented Jul 24, 2023

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
Copy link
Owner

Was this already fixed in the last commit? @sitexa

@sitexa
Copy link
Author

sitexa commented Jul 30, 2023

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
Copy link
Author

sitexa commented Jul 30, 2023

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)

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

2 participants