plottr
plottr copied to clipboard
Qcodes Autoplot crash with categorical data
Using a dataset created with the following code:
import numpy as np
import qcodes as qc
qc.config.core.db_location = "./test.db"
qc.initialise_database()
exp = qc.load_or_create_experiment("categorical_data", sample_name="no sample")
m = qc.Measurement(exp=exp)
m.register_custom_parameter('x')
m.register_custom_parameter('label', paramtype='text')
m.register_custom_parameter('y', setpoints=('x', 'label'))
def f(x, label):
if label == 'trig':
return np.sin(x * 2 * np.pi)
elif label == 'gauss':
return np.exp(-x**2)
with m.run() as datasaver:
for x in np.linspace(-1, 1, 10):
for label in ['trig', 'gauss']:
datasaver.add_result(('x', x),
('label', label),
('y', f(x, label)))
When opening the dataset with Autoplot, it crashes with the following stack trace:
Traceback (most recent call last):
File "plottr/plottr/apps/inspectr.py", line 425, in plotRun
fc, win = autoplotQcodesDataset(pathAndId=(self.filepath, runId))
File "plottr/plottr/apps/autoplot.py", line 237, in autoplotQcodesDataset
win = QCAutoPlotMainWindow(fc, pathAndId=pathAndId)
File "plottr/plottr/apps/autoplot.py", line 213, in __init__
self.setDefaults()
File "plottr/plottr/apps/autoplot.py", line 182, in setDefaults
self.fc.nodes()['Dimension assignment'].dimensionRoles = drs
File "plottr/plottr/node/node.py", line 40, in wrap
self.ui.optSetters[optName](val)
File "plottr/plottr/node/dim_reducer.py", line 627, in setRoles
self.widget.setRole(dimName, role)
File "plottr/plottr/node/dim_reducer.py", line 336, in setRole
super().setRole(dim, role, **kw)
File "plottr/plottr/node/dim_reducer.py", line 276, in setRole
super().setRole(dim, role)
File "plottr/plottr/node/dim_reducer.py", line 202, in setRole
self.choices[dim]['roleSelectionWidget'].setCurrentText(role)
KeyError: 'label'
The (or at least one) correct behavior would be to add the categorical dimension as a slider, which works if the data has at least one 'numerical' dimension (if not, then I'm not sure what should happen).