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

HiDPI / Retina screens cause redraw issues leading to a singular matrix error #286

Closed
nheeren opened this issue Sep 20, 2019 · 11 comments · Fixed by #363
Closed

HiDPI / Retina screens cause redraw issues leading to a singular matrix error #286

nheeren opened this issue Sep 20, 2019 · 11 comments · Fixed by #363
Labels
bug Issues/PRs related to bugs help needed Issues that we need help with
Milestone

Comments

@nheeren
Copy link

nheeren commented Sep 20, 2019

What I did:

  • Select process 'Activity market for aluminium, cast alloy (GLO)' from ecoinvent 3.5 cut-off for a LCA setup.
  • Press Calculate
  • Press Process Contribution
  • Unselect Plot Doesn't matter
  • Press right arrow
  • Repeat

I believe this has to do with the drawing in macOS / Qt. Yesterday it worked fine. I am not sure what changed, except that I had a larger screen plugged in.

Happening in development and stable version.

Optimal Contribution plot height: 4.55
Optimal Contribution plot height: 4.55
Optimal Contribution plot height: 4.55
Optimal Contribution plot height: 4.55
Optimal Contribution plot height: 4.55
/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/figure.py:2425: RuntimeWarning: divide by zero encountered in double_scalars
  w_pad = w_pad / width
Traceback (most recent call last):
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/activity_browser/app/ui/widgets/cutoff_menu.py", line 28, in <lambda>
    lambda: self.cutoff_slider_relative_check("sl"))
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/activity_browser/app/ui/widgets/cutoff_menu.py", line 126, in cutoff_slider_relative_check
    self.update_plot_table()
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/activity_browser/app/ui/widgets/cutoff_menu.py", line 42, in update_plot_table
    self.parent.update_plot()
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/activity_browser/app/ui/tabs/LCA_results_tabs.py", line 798, in update_plot
    self.plot.plot(self.df, unit=unit)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/activity_browser/app/ui/figures.py", line 201, in plot
    self.canvas.draw()
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/backends/backend_agg.py", line 388, in draw
    self.figure.draw(self.renderer)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/artist.py", line 38, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/figure.py", line 1698, in draw
    self.execute_constrained_layout(renderer)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/figure.py", line 2429, in execute_constrained_layout
    do_constrained_layout(fig, renderer, h_pad, w_pad, hspace, wspace)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/_constrained_layout.py", line 147, in do_constrained_layout
    invTransFig = fig.transFigure.inverted().transform_bbox
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/matplotlib/transforms.py", line 1809, in inverted
    self._inverted = Affine2D(inv(mtx), shorthand_name=shorthand_name)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 551, in inv
    ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
  File "/Users/n/code/_env/miniconda3/envs/ab/lib/python3.7/site-packages/numpy/linalg/linalg.py", line 97, in _raise_linalgerror_singular
    raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix
@nheeren nheeren changed the title Reducing the cut-off level in an LCA calculation leads to a singular matrix Reducing the cut-off level in an LCA calculation leads to a singular matrix error Sep 20, 2019
@nheeren
Copy link
Author

nheeren commented Sep 20, 2019

It is accompanied by some weird redrawing:

ezgif com-video-to-gif
The error is raised after pressing approx. 8 times and no more redrawing appears.

So I am pretty sure it has to do with the image.

More info:

  • Same when selecting EF contributions

@nheeren nheeren changed the title Reducing the cut-off level in an LCA calculation leads to a singular matrix error HiDPI / Retina screens cause redraw issues leading to a singular matrix error Sep 20, 2019
@nheeren
Copy link
Author

nheeren commented Sep 20, 2019

I found the problem. Upon a hunch I changed my MacBook's screen to its native resolution and the problem disappears. So it seems like HiDPI and / or Retina screens cause some issue with matplotlib. I guess googling into this direction might help you fixing this bug.

Somebody with a HiDPI screen (e.g. Surface Pro) should test this on Windows and Linux as well...

For the other poor souls on retina Macs: Use this App to switch to the highest / native resolution: http://displaymenu.milchimgemuesefach.de

@dgdekoning
Copy link
Contributor

Woah, thanks for digging into the problem and finding the issue!
That said, I honestly have no idea how to even start trying to build a fix for this, and would welcome help from anyone that knows how to solve or patch this issue.

Off the top of my head the only thing I can think of is to be heavy-handed and deleting the plot object when a redraw is requested.

@dgdekoning dgdekoning added bug Issues/PRs related to bugs help needed Issues that we need help with labels Sep 20, 2019
@nheeren
Copy link
Author

nheeren commented Sep 20, 2019

I guess we could try to isolate the issue within matplotlib and than bug their developers...

@nheeren
Copy link
Author

nheeren commented Sep 20, 2019

A temporary workaround would be to disable redraw when the 'Plot' checkbox is unchecked.

@dgdekoning
Copy link
Contributor

dgdekoning commented Sep 24, 2019

I guess we could try to isolate the issue within matplotlib and than bug their developers...

I am all for this, but don't really have the time to dive that deep into matplotlib.

A temporary workaround would be to disable redraw when the 'Plot' checkbox is unchecked.

I agree, and depending on the time required to draw the plot we might even 'just' delete the plot itself once the user clicks the checkbox. Will look into the temporary fixes in this direction.

@dgdekoning
Copy link
Contributor

Hey @nheeren, if you have the time could you see if this issue still occurs in the experimental PySide2 refactoring branch?

@cmutel
Copy link
Contributor

cmutel commented Jan 17, 2020

FWIW, the weird redrawing (seems to reduce by a factor of 2 each time, has to be related to scaling) happens with AB_dev 2020.01.10. I get it on my laptop without an external screen.
Screenshot 2020-01-17 at 11 21 34
Honestly, I think drawing a completely new plot canvas might prevent future errors as well. Worth considering, if it isn't too difficult.

@nheeren
Copy link
Author

nheeren commented Jan 17, 2020

@cmutel I assume you use some non-default resolution on your Mac? As a side note: Also others have this issue. When I have an external screen connected and open a new window in the Scholar One system on Firefox, it will also be scaled too small.

@dgdekoning dgdekoning added this to the Version 2.5.1 milestone Jan 17, 2020
@bsteubing
Copy link
Member

@nheeren and @cmutel: I just wanted to say thanks for reporting these bugs! In the mid-term we may want to get away from matplotlib plots altogether and move towards interactive plots... when I looked around last time, bokeh was an interesting option, but still had an issue with labels (bokeh/bokeh#8169). Other suggestions are welcome. And contributions of course also (thanks @e4BdSBmUzHowFico5Ktn for already looking into this a bit!).

@cmutel
Copy link
Contributor

cmutel commented Jan 19, 2020

@nheeren Nope, native (retina) resolution on 2016 MacBook Pro with no external screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues/PRs related to bugs help needed Issues that we need help with
Projects
None yet
4 participants