fossasia/visdom

Invalid reshaping of Y for lineplots sharing the same X-axis

Open

#688 opened on Nov 13, 2019

View on GitHub
 (7 comments) (3 reactions) (0 assignees)Python (9,831 stars) (1,152 forks)batch import
Fix Proposedbughelp wanted

Description

Bug Description When plotting a line (via visdom.line) I get an error of incompatible shapes for X and Y when using inputs Y of size Nx1 and X of size N. Specifically, I localized the problem to line 1688 of __init__.py where Y is reshaped to size 1xN if only one line is used (i.e. Y originally has shape Nx1). This activates the if condition on line 1691 which makes X tiled to shape NxN. This causes a problem on line 1694 since X and Y now don't have the same shape. This is where the exception occurs and crashes my program!

I can 'fix' the error by changing line 1688 to: Y = Y.reshape(Y.shape[0]). Of course, I am not sure whether this is actually necessary or whether my usage of Visdom.line is the problem. I have observed the same code to be working a few months ago (August) without any changes.

A final note. The first time I use the plot function where Y has size 1x1 it does work correctly. I suspect this is due to line 1692 where X is tiled if X and Y have different ndims.

Reproduction Steps Enter steps to reproduce the behavior:

  1. Create vector X of size N with simple increasing values, e.g. by range(N).
  2. Create vector Y of size Nx1 with random values, e.g. by numpy.random.uniform(size=(N, 1))
  3. Plot line in visdom using the Visdom.line method. The update parameter is set to 'replace'.

Example code:

data = np.vstack([m[self.metric] for m in self.loggers]).T
if self.x_metric == 'auto':
    x = np.linspace(1, data.shape[0], data.shape[0])
else:
    x = np.vstack([m[self.x_metric] for m in self.loggers]).T

self.win = self.vis.line(
    Y=data,
    X=x,
    win=self.win,
    update='replace' if self.win else None,
    opts=dict(
        legend=self.legend,
        markers=True,
        xlabel=self.units,
        ylabel=self.metric,
        title=self.metric,
    )
)

Expected behavior To get a single line as output without errors.

Client logs: For issues that make it to the point of reaching the frontend in a browser, please include the javascript logs from that browser. In Chrome, javascript logs can be found via View -> Developer -> JavaScript Console.

Server logs: Checking for scripts. It's Alive! INFO:root:Application Started You can navigate to http://localhost:8095 INFO:tornado.access:304 GET / (::1) 1237.00ms INFO:tornado.access:101 GET /socket (::1) 1.00ms INFO:root:Opened new socket from ip: ::1 INFO:tornado.access:304 GET /static/fonts/glyphicons-halflings-regular.woff2 (::1) 475.50ms INFO:tornado.access:304 GET /extensions/MathMenu.js?V=2.7.1 (::1) 16.00ms INFO:tornado.access:200 POST /env/main (::1) 1.00ms INFO:tornado.access:200 POST /env/main (::1) 3.00ms INFO:tornado.access:304 GET /favicon.png (::1) 15.00ms INFO:tornado.access:304 GET /extensions/MathZoom.js?V=2.7.1 (::1) 15.00ms INFO:tornado.access:304 GET / (::1) 14.00ms INFO:tornado.access:101 GET /socket (::1) 1.00ms INFO:root:Opened new socket from ip: ::1 INFO:tornado.access:200 POST /env/main (::1) 0.00ms INFO:tornado.access:200 POST /env/main (::1) 1.00ms INFO:tornado.access:200 GET /favicon.png (::1) 14.00ms INFO:tornado.access:304 GET /extensions/MathMenu.js?V=2.7.1 (::1) 13.00ms INFO:tornado.access:304 GET /extensions/MathZoom.js?V=2.7.1 (::1) 11.02ms INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 0.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 1.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 1.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 0.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 0.99ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 1.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 1.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 1.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 0.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 0.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 1.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 0.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/viz13-11-08h56 (127.0.0.1) 0.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 2.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:tornado.access:200 POST /env/plots13-11-08h56 (127.0.0.1) 1.00ms INFO:tornado.access:101 GET /vis_socket (127.0.0.1) 0.00ms INFO:root:Opened visdom socket from ip: 127.0.0.1 INFO:root:comparing envs INFO:tornado.access:200 POST /compare/main+plots13-11-08h56 (::1) 1.00ms INFO:tornado.access:200 POST /env/plots13-11-08h56 (::1) 0.00ms INFO:tornado.access:200 POST /env/plots13-11-08h56 (::1) 1.00ms INFO:tornado.access:200 POST /env/plots13-11-08h56 (::1) 1.00ms INFO:tornado.access:200 POST /events (127.0.0.1) 2.00ms INFO:tornado.access:200 POST /env/plots13-11-08h56 (::1) 1.00ms

Additional context My visdom server is running locally.

Contributor guide