CIRADA-Tools/RM-Tools

QUfitting requests X display

zhangxiang-planet opened this issue · 4 comments

I got this error when running qufit within slurm jobs:

qt.qpa.screen: QXcbConnection: Could not connect to display pearcey-login:48.0
Could not connect to any X display.

The options I used were qufit -i -m $model $file

I've been able to reproduce this error. Even if showPlots is not asked for, Matplotlib seems to trigger x11 to open. This causes a crash for jobs running without x11 forwarding.

I found a fix for my local repo, by adding these lines to do_QUfit_1D_mnest.py

import matplotlib as mpl
mpl.use('Agg')

Hi Xiang, Alec:

Sorry for the delay in responding to your issues; I've been on leave the past 2 weeks and am just now catching up.

I think I understand the problem, but I'm not sure how to fix it properly. The mpl.use('Agg') trick makes sense, but I don't want to put that in for everyone because not everyone will want to use that backend (it disables interactive plotting, and can't produce vector graphic outputs). Micromanaging the mpl backends isn't supposed to be necessary; it should take care of that automatically.

This seems to be more of a Slurm problem than a matplotlib problem: Slurm doesn't seem properly set the environment to tell matplotlib that there's no interactive display. According to the matplotlib documentation, you can set an environment variable (MPLBACKEND=Agg; https://matplotlib.org/stable/tutorials/introductory/usage.html#backends) in your Slurm script, and it will function equivalently to the .use() command, without permanently modifying the QUfitting script.

Cheers,
Cameron

Thanks, Cameron. MPLBACKEND=Agg sounds like a great idea!