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

Dont assume that unit attribute exists #770

Closed
wants to merge 2 commits into from

Conversation

jenshnielsen
Copy link
Collaborator

Fixes #769 .

@AdriaanRol
Copy link
Contributor

@jenshnielsen I tested your changes. They do not fix the problem.

Looking a bit more at the traceback I think it may have to do with having multiple subplots. I can see that the first plot get's created correctly (out of 2 I am trying to create) but the second one does not.

@jenshnielsen
Copy link
Collaborator Author

Do you get the same traceback? or a different one?

Can you inspect how the plot.traces dict looks normally there should be an element in the traces list for each subplot which in turn contains a config element which contains all the axis

@jenshnielsen
Copy link
Collaborator Author

I.e this is how it looks for me for a simple plot of a line graph and a 2d plot in

[{'config': {'figsize': (1200, 500), 'x': DataArray[6,6]: dac_ch2_set
   array([[ 0.,  1.,  2.,  3.,  4.,  5.],
          [ 0.,  1.,  2.,  3.,  4.,  5.],
          [ 0.,  1.,  2.,  3.,  4.,  5.],
          [ 0.,  1.,  2.,  3.,  4.,  5.],
          [ 0.,  1.,  2.,  3.,  4.,  5.],
          [ 0.,  1.,  2.,  3.,  4.,  5.]]), 'y': DataArray[6]: dac_ch1_set
   array([ 0.,  1.,  2.,  3.,  4.,  5.]), 'z': DataArray[6,6]: dmm_voltage
   array([[  25.,   52.,    2.,   17.,   73.,   68.],
          [  51.,   38.,   79.,   62.,   73.,  100.],
          [  60.,   72.,   20.,   37.,   56.,   51.],
          [   2.,   98.,   79.,   81.,   70.,   99.],
          [   4.,   71.,   10.,   39.,   11.,   30.],
          [  11.,    8.,   69.,   25.,   86.,   93.]])},
  'plot_object': {'cmap': 'hot',
   'hist': <ObjectProxy for process 24930, object 0x1db: <pyqtgraph.graphicsItems.HistogramLUTItem.HistogramLUTItem object at 0x117b7f948> >,
   'histlevels': (2.0, 100.0),
   'image': <ObjectProxy for process 24930, object 0x1d8: <pyqtgraph.graphicsItems.ImageItem.ImageItem object at 0x117b77a68> >,
   'scales': {'x': TransformState(translate=-0.5, scale=1.0, revisit=False),
    'y': TransformState(translate=-0.5, scale=1.0, revisit=False)}}},
 {'config': {'x': DataArray[6]: dac_ch1_set
   array([ 0.,  1.,  2.,  3.,  4.,  5.]), 'y': DataArray[6]: dac_ch1_set
   array([ 0.,  1.,  2.,  3.,  4.,  5.])},
  'plot_object': <ObjectProxy for process 24930, object 0x200: <pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x117b9c678> >}]

@AdriaanRol
Copy link
Contributor

@jenshnielsen Below the traces and the plot.traces.
The problem occurs when in the same loop the second trace get's added.

I have to focus on my experiment now but I think this info should be useful.

Traceback :

d:\githubrepos\pycqed_py3\pycqed\measurement\measurement_control.py in measure(self, *kw)
    171     def measure(self, *kw):
    172         if self.live_plot_enabled():
--> 173             self.initialize_plot_monitor()
    174 
    175         for sweep_function in self.sweep_functions:

d:\githubrepos\pycqed_py3\pycqed\measurement\measurement_control.py in initialize_plot_monitor(self)
    570                                      subplot=j+1,
    571                                      color=color_cycle[j % len(color_cycle)],
--> 572                                      symbol='o', symbolSize=5)
    573                 self.curves.append(self.main_QtPlot.traces[-1])
    574                 j += 1

d:\githubrepos\qcodes\qcodes\plots\base.py in add(self, updater, *args, **kwargs)
     89         # TODO(giulioungaretti): replace with an explicit version, see expand trace
     90         self.expand_trace(args, kwargs)
---> 91         self.add_to_plot(**kwargs)
     92         self.add_updater(updater, kwargs)
     93 

d:\githubrepos\qcodes\qcodes\plots\pyqtgraph.py in add_to_plot(self, subplot, **kwargs)
    147         if prev_default_title == self.win.windowTitle():
    148             self.win.setWindowTitle(self.get_default_title())
--> 149         self.fixUnitScaling()
    150 
    151     def _draw_plot(self, subplot_object, y, x=None, color=None, width=None,

d:\githubrepos\qcodes\qcodes\plots\pyqtgraph.py in fixUnitScaling(self, startranges)
    547 
    548                     # set limits either from dataset or
--> 549                     setarr = self.traces[i]['config'][axis].ndarray
    550                     arrmin = None
    551                     arrmax = None

AttributeError: 'list' object has no attribute 'ndarray'

Inspecting traces:

image

@AdriaanRol
Copy link
Contributor

More readable

[{'config': {'color': '#1f77b4',
   'symbol': 'o',
   'symbolSize': 5,
   'x': [0],
   'xlabel': 'Frequency',
   'xunit': 'Hz',
   'y': [0],
   'ylabel': 'Magn',
   'yunit': 'V'},
  'plot_object': <ObjectProxy for process 12880, object 0x1f: <pyqtgraph.graphicsItems.PlotDataItem.PlotDataItem object at 0x000000000564DE58> >}]

@jenshnielsen
Copy link
Collaborator Author

@AdriaanRol Thanks I will have a look

@jenshnielsen
Copy link
Collaborator Author

Your config object is quite different so the auto scaling will not work as is but I think this should be enough to keep the crash from happening

@jenshnielsen
Copy link
Collaborator Author

@AdriaanRol did you have a chance to test the latest version?

@AdriaanRol
Copy link
Contributor

@jenshnielsen I didn't see you made any further changes. I'll have to check that out. Won't be today though, we are kind of deadline pressed at the moment.

On a related note, I think it would be good to add some unittests to the plotting to prevent these kind of issues in the future. I'd say they should only test if the code runs as testing for visual correctness is notoriously hard. If you are interested, I have a travis build script (based on the QCoDeS one) that also includes proper installation of pyqtgraph.

@jenshnielsen
Copy link
Collaborator Author

@AdriaanRol thanks thats fine whenever you have time. Unittesting is great but given that you are using it with a config object that is completely foreign to qcodes I don't see how we could have tested this without better visibility to what you are doing

@AdriaanRol
Copy link
Contributor

@jenshnielsen . I'll try to create a unittest using only the default QCoDeS QtPlot API that reproduces the problem.

I think that should provide the visibility that you need and should prevent these kind of problems in the future.

@jenshnielsen
Copy link
Collaborator Author

Sounds good thanks

@AdriaanRol
Copy link
Contributor

@jenshnielsen I've made a new PR containing a self contained test using only the default QCoDeS API that also contains all the work from your branch. Looking forward to your input.

@jenshnielsen
Copy link
Collaborator Author

Super-seeded by #805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants