aims-umich / neorl

NeuroEvolution Optimization with Reinforcement Learning
MIT License
51 stars 18 forks source link

`import neorl.benchmark` breaks matplotlib display for linux #22

Closed deanrp2 closed 2 years ago

deanrp2 commented 2 years ago

The code snippet below does not produce a plot when using ssh on a linux computer:

import neorl.benchmarks
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 100)
y = x**2

plt.plot(x, y)
plt.show()

These two code snippets do produce the plot:

import neorl
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 100)
y = x**2

plt.plot(x, y)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 1, 100)
y = x**2

plt.plot(x, y)
plt.show()
import neorl.benchmarks
deanrp2 commented 2 years ago

The only thing I found on this is here: https://www.pyimagesearch.com/2015/08/24/resolved-matplotlib-figures-not-showing-up-or-displaying/

But the fix is pretty complicated. If possible, we should try to not make users need to do all this.

deanrp2 commented 2 years ago

I think I got it after our talk. It is on line 33 of neorl/benchmarks/kp.py and line 34 of neorl/benchmarks/tsp.py. It is changing some display settings. I would say throw those imports in the __init__.py file into the bench_2dplot function. Also, make sure that these are necessary, this seems like the sort of thing somebody may need if they have a weird setup that slipped through into the repo.

mradaideh commented 2 years ago

@deanrp2 Thank you for your comments and for catching this bug. As you have pointed out the two benchmarks TSP/KP have a silent plot suppression of matplotlib using the mode Agg, which is invoked when you run import neorl.benchmarks. These commands are removed in the next NEORL release.