From 9647808dbe9520d80127dcc62d76c94e33ee03d1 Mon Sep 17 00:00:00 2001 From: Alan Geller Date: Thu, 25 Aug 2016 16:48:30 -0700 Subject: [PATCH 01/11] Snapshot local commit --- docs/examples/Tutorial.ipynb | 1565 +++++++++++++++++++++++++--------- qcodes/loops.py | 102 ++- qcodes/plots/base.py | 14 + 3 files changed, 1260 insertions(+), 421 deletions(-) diff --git a/docs/examples/Tutorial.ipynb b/docs/examples/Tutorial.ipynb index 56407f4f4b50..46d9d0ee0c83 100644 --- a/docs/examples/Tutorial.ipynb +++ b/docs/examples/Tutorial.ipynb @@ -40,249 +40,250 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "collapsed": false + "collapsed": false, + "scrolled": false }, "outputs": [ { "data": { "application/javascript": [ - "/*\n", - " * Qcodes Jupyter/IPython widgets\n", - " */\n", - "require([\n", - " 'nbextensions/widgets/widgets/js/widget',\n", - " 'nbextensions/widgets/widgets/js/manager'\n", - "], function (widget, manager) {\n", - "\n", - " var UpdateView = widget.DOMWidgetView.extend({\n", - " render: function() {\n", - " window.MYWIDGET = this;\n", - " this._interval = 0;\n", - " this.update();\n", - " },\n", - " update: function() {\n", - " this.display(this.model.get('_message'));\n", - " this.setInterval();\n", - " },\n", - " display: function(message) {\n", - " /*\n", - " * display method: override this for custom display logic\n", - " */\n", - " this.el.innerHTML = message;\n", - " },\n", - " remove: function() {\n", - " clearInterval(this._updater);\n", - " },\n", - " setInterval: function(newInterval) {\n", - " var me = this;\n", - " if(newInterval===undefined) newInterval = me.model.get('interval');\n", - " if(newInterval===me._interval) return;\n", - "\n", - " me._interval = newInterval;\n", - "\n", - " if(me._updater) clearInterval(me._updater);\n", - "\n", - " if(me._interval) {\n", - " me._updater = setInterval(function() {\n", - " me.send({myupdate: true});\n", - " if(!me.model.comm_live) {\n", - " console.log('missing comm, canceling widget updates', me);\n", - " clearInterval(me._updater);\n", - " }\n", - " }, me._interval * 1000);\n", - " }\n", - " }\n", - " });\n", - " manager.WidgetManager.register_widget_view('UpdateView', UpdateView);\n", - "\n", - " var HiddenUpdateView = UpdateView.extend({\n", - " display: function(message) {\n", - " this.$el.hide();\n", - " }\n", - " });\n", - " manager.WidgetManager.register_widget_view('HiddenUpdateView', HiddenUpdateView);\n", - "\n", - " var SubprocessView = UpdateView.extend({\n", - " render: function() {\n", - " var me = this;\n", - " me._interval = 0;\n", - " me._minimize = '';\n", - " me._restore = '';\n", - "\n", - " // max lines of output to show\n", - " me.maxOutputLength = 500;\n", - "\n", - " // in case there is already an outputView present,\n", - " // like from before restarting the kernel\n", - " $('.qcodes-output-view').not(me.$el).remove();\n", - "\n", - " me.$el\n", - " .addClass('qcodes-output-view')\n", - " .attr('qcodes-state', 'docked')\n", - " .html(\n", - " '
' +\n", - " '
' +\n", - " '' +\n", - " '' +\n", - " '' +\n", - " '' +\n", - " '' +\n", - " '' +\n", - " '
' +\n", - " '
'\n",
-       "                );\n",
-       "\n",
-       "            me.clearButton = me.$el.find('.qcodes-clear-output');\n",
-       "            me.minButton = me.$el.find('.qcodes-minimize');\n",
-       "            me.outputArea = me.$el.find('pre');\n",
-       "            me.subprocessList = me.$el.find('.qcodes-process-list');\n",
-       "            me.abortButton = me.$el.find('.qcodes-abort-loop');\n",
-       "            me.processLinesButton = me.$el.find('.qcodes-processlines')\n",
-       "\n",
-       "            me.outputLines = [];\n",
-       "\n",
-       "            me.clearButton.click(function() {\n",
-       "                me.outputArea.html('');\n",
-       "                me.clearButton.addClass('disabled');\n",
-       "            });\n",
-       "\n",
-       "            me.abortButton.click(function() {\n",
-       "                me.send({abort: true});\n",
-       "            });\n",
-       "\n",
-       "            me.processLinesButton.click(function() {\n",
-       "                // toggle multiline process list display\n",
-       "                me.subprocessesMultiline = !me.subprocessesMultiline;\n",
-       "                me.showSubprocesses();\n",
-       "            });\n",
-       "\n",
-       "            me.$el.find('.js-state').click(function() {\n",
-       "                var state = this.className.substr(this.className.indexOf('qcodes'))\n",
-       "                        .split('-')[1].split(' ')[0];\n",
-       "                me.model.set('_state', state);\n",
-       "            });\n",
-       "\n",
-       "            $(window)\n",
-       "                .off('resize.qcodes')\n",
-       "                .on('resize.qcodes', function() {me.clipBounds();});\n",
-       "\n",
-       "            me.update();\n",
-       "        },\n",
-       "\n",
-       "        updateState: function() {\n",
-       "            var me = this,\n",
-       "                oldState = me.$el.attr('qcodes-state'),\n",
-       "                state = me.model.get('_state');\n",
-       "\n",
-       "            if(state === oldState) return;\n",
-       "\n",
-       "            setTimeout(function() {\n",
-       "                // not sure why I can't pop it out of the widgetarea in render, but it seems that\n",
-       "                // some other bit of code resets the parent after render if I do it there.\n",
-       "                // To be safe, just do it on every state click.\n",
-       "                me.$el.appendTo('body');\n",
-       "\n",
-       "                if(oldState === 'floated') {\n",
-       "                    console.log('here');\n",
-       "                    me.$el.draggable('destroy').css({left:'', top: ''});\n",
-       "                }\n",
-       "\n",
-       "                me.$el.attr('qcodes-state', state);\n",
-       "\n",
-       "                if(state === 'floated') {\n",
-       "                    me.$el\n",
-       "                        .draggable({stop: function() { me.clipBounds(); }})\n",
-       "                        .css({\n",
-       "                            left: window.innerWidth - me.$el.width() - 15,\n",
-       "                            top: window.innerHeight - me.$el.height() - 10\n",
-       "                        });\n",
-       "                }\n",
-       "\n",
-       "                // any previous highlighting is now moot\n",
-       "                me.$el.removeClass('qcodes-highlight');\n",
-       "            }, 0);\n",
-       "\n",
-       "        },\n",
-       "\n",
-       "        clipBounds: function() {\n",
-       "            var me = this;\n",
-       "            if(me.$el.attr('qcodes-state') === 'floated') {\n",
-       "                var bounds = me.$el[0].getBoundingClientRect(),\n",
-       "                    minVis = 40,\n",
-       "                    maxLeft = window.innerWidth - minVis,\n",
-       "                    minLeft = minVis - bounds.width,\n",
-       "                    maxTop = window.innerHeight - minVis;\n",
-       "\n",
-       "                if(bounds.left > maxLeft) me.$el.css('left', maxLeft);\n",
-       "                else if(bounds.left < minLeft) me.$el.css('left', minLeft);\n",
-       "\n",
-       "                if(bounds.top > maxTop) me.$el.css('top', maxTop);\n",
-       "                else if(bounds.top < 0) me.$el.css('top', 0);\n",
-       "            }\n",
-       "        },\n",
-       "\n",
-       "        display: function(message) {\n",
-       "            var me = this;\n",
-       "            if(message) {\n",
-       "                var initialScroll = me.outputArea.scrollTop();\n",
-       "                me.outputArea.scrollTop(me.outputArea.prop('scrollHeight'));\n",
-       "                var scrollBottom = me.outputArea.scrollTop();\n",
-       "\n",
-       "                if(me.$el.attr('qcodes-state') === 'minimized') {\n",
-       "                    // if we add text and the box is minimized, highlight the\n",
-       "                    // title bar to alert the user that there are new messages.\n",
-       "                    // remove then add the class, so we get the animation again\n",
-       "                    // if it's already highlighted\n",
-       "                    me.$el.removeClass('qcodes-highlight');\n",
-       "                    setTimeout(function(){\n",
-       "                        me.$el.addClass('qcodes-highlight');\n",
-       "                    }, 0);\n",
-       "                }\n",
-       "\n",
-       "                var newLines = message.split('\\n'),\n",
-       "                    out = me.outputLines,\n",
-       "                    outLen = out.length;\n",
-       "                if(outLen) out[outLen - 1] += newLines[0];\n",
-       "                else out.push(newLines[0]);\n",
-       "\n",
-       "                for(var i = 1; i < newLines.length; i++) {\n",
-       "                    out.push(newLines[i]);\n",
-       "                }\n",
-       "\n",
-       "                if(out.length > me.maxOutputLength) {\n",
-       "                    out.splice(0, out.length - me.maxOutputLength + 1,\n",
-       "                        '<<< Output clipped >>>');\n",
-       "                }\n",
-       "\n",
-       "                me.outputArea.text(out.join('\\n'));\n",
-       "                me.clearButton.removeClass('disabled');\n",
-       "\n",
-       "                // if we were scrolled to the bottom initially, make sure\n",
-       "                // we stay that way.\n",
-       "                me.outputArea.scrollTop(initialScroll === scrollBottom ?\n",
-       "                    me.outputArea.prop('scrollHeight') : initialScroll);\n",
-       "            }\n",
-       "\n",
-       "            me.showSubprocesses();\n",
-       "            me.updateState();\n",
-       "        },\n",
-       "\n",
-       "        showSubprocesses: function() {\n",
-       "            var me = this,\n",
-       "                replacer = me.subprocessesMultiline ? '
' : ', ',\n", - " processes = (me.model.get('_processes') || '')\n", - " .replace(/\\n/g, '>' + replacer + '<');\n", - "\n", - " if(processes) processes = '<' + processes + '>';\n", - " else processes = 'No subprocesses';\n", - "\n", - " me.abortButton.toggleClass('disabled', processes.indexOf('Measurement')===-1);\n", - "\n", - " me.subprocessList.html(processes);\n", - " }\n", - " });\n", - " manager.WidgetManager.register_widget_view('SubprocessView', SubprocessView);\n", - "});\n" + "/*\r\n", + " * Qcodes Jupyter/IPython widgets\r\n", + " */\r\n", + "require([\r\n", + " 'nbextensions/widgets/widgets/js/widget',\r\n", + " 'nbextensions/widgets/widgets/js/manager'\r\n", + "], function (widget, manager) {\r\n", + "\r\n", + " var UpdateView = widget.DOMWidgetView.extend({\r\n", + " render: function() {\r\n", + " window.MYWIDGET = this;\r\n", + " this._interval = 0;\r\n", + " this.update();\r\n", + " },\r\n", + " update: function() {\r\n", + " this.display(this.model.get('_message'));\r\n", + " this.setInterval();\r\n", + " },\r\n", + " display: function(message) {\r\n", + " /*\r\n", + " * display method: override this for custom display logic\r\n", + " */\r\n", + " this.el.innerHTML = message;\r\n", + " },\r\n", + " remove: function() {\r\n", + " clearInterval(this._updater);\r\n", + " },\r\n", + " setInterval: function(newInterval) {\r\n", + " var me = this;\r\n", + " if(newInterval===undefined) newInterval = me.model.get('interval');\r\n", + " if(newInterval===me._interval) return;\r\n", + "\r\n", + " me._interval = newInterval;\r\n", + "\r\n", + " if(me._updater) clearInterval(me._updater);\r\n", + "\r\n", + " if(me._interval) {\r\n", + " me._updater = setInterval(function() {\r\n", + " me.send({myupdate: true});\r\n", + " if(!me.model.comm_live) {\r\n", + " console.log('missing comm, canceling widget updates', me);\r\n", + " clearInterval(me._updater);\r\n", + " }\r\n", + " }, me._interval * 1000);\r\n", + " }\r\n", + " }\r\n", + " });\r\n", + " manager.WidgetManager.register_widget_view('UpdateView', UpdateView);\r\n", + "\r\n", + " var HiddenUpdateView = UpdateView.extend({\r\n", + " display: function(message) {\r\n", + " this.$el.hide();\r\n", + " }\r\n", + " });\r\n", + " manager.WidgetManager.register_widget_view('HiddenUpdateView', HiddenUpdateView);\r\n", + "\r\n", + " var SubprocessView = UpdateView.extend({\r\n", + " render: function() {\r\n", + " var me = this;\r\n", + " me._interval = 0;\r\n", + " me._minimize = '';\r\n", + " me._restore = '';\r\n", + "\r\n", + " // max lines of output to show\r\n", + " me.maxOutputLength = 500;\r\n", + "\r\n", + " // in case there is already an outputView present,\r\n", + " // like from before restarting the kernel\r\n", + " $('.qcodes-output-view').not(me.$el).remove();\r\n", + "\r\n", + " me.$el\r\n", + " .addClass('qcodes-output-view')\r\n", + " .attr('qcodes-state', 'docked')\r\n", + " .html(\r\n", + " '
' +\r\n", + " '
' +\r\n", + " '' +\r\n", + " '' +\r\n", + " '' +\r\n", + " '' +\r\n", + " '' +\r\n", + " '' +\r\n", + " '
' +\r\n", + " '
'\r\n",
+       "                );\r\n",
+       "\r\n",
+       "            me.clearButton = me.$el.find('.qcodes-clear-output');\r\n",
+       "            me.minButton = me.$el.find('.qcodes-minimize');\r\n",
+       "            me.outputArea = me.$el.find('pre');\r\n",
+       "            me.subprocessList = me.$el.find('.qcodes-process-list');\r\n",
+       "            me.abortButton = me.$el.find('.qcodes-abort-loop');\r\n",
+       "            me.processLinesButton = me.$el.find('.qcodes-processlines')\r\n",
+       "\r\n",
+       "            me.outputLines = [];\r\n",
+       "\r\n",
+       "            me.clearButton.click(function() {\r\n",
+       "                me.outputArea.html('');\r\n",
+       "                me.clearButton.addClass('disabled');\r\n",
+       "            });\r\n",
+       "\r\n",
+       "            me.abortButton.click(function() {\r\n",
+       "                me.send({abort: true});\r\n",
+       "            });\r\n",
+       "\r\n",
+       "            me.processLinesButton.click(function() {\r\n",
+       "                // toggle multiline process list display\r\n",
+       "                me.subprocessesMultiline = !me.subprocessesMultiline;\r\n",
+       "                me.showSubprocesses();\r\n",
+       "            });\r\n",
+       "\r\n",
+       "            me.$el.find('.js-state').click(function() {\r\n",
+       "                var state = this.className.substr(this.className.indexOf('qcodes'))\r\n",
+       "                        .split('-')[1].split(' ')[0];\r\n",
+       "                me.model.set('_state', state);\r\n",
+       "            });\r\n",
+       "\r\n",
+       "            $(window)\r\n",
+       "                .off('resize.qcodes')\r\n",
+       "                .on('resize.qcodes', function() {me.clipBounds();});\r\n",
+       "\r\n",
+       "            me.update();\r\n",
+       "        },\r\n",
+       "\r\n",
+       "        updateState: function() {\r\n",
+       "            var me = this,\r\n",
+       "                oldState = me.$el.attr('qcodes-state'),\r\n",
+       "                state = me.model.get('_state');\r\n",
+       "\r\n",
+       "            if(state === oldState) return;\r\n",
+       "\r\n",
+       "            setTimeout(function() {\r\n",
+       "                // not sure why I can't pop it out of the widgetarea in render, but it seems that\r\n",
+       "                // some other bit of code resets the parent after render if I do it there.\r\n",
+       "                // To be safe, just do it on every state click.\r\n",
+       "                me.$el.appendTo('body');\r\n",
+       "\r\n",
+       "                if(oldState === 'floated') {\r\n",
+       "                    console.log('here');\r\n",
+       "                    me.$el.draggable('destroy').css({left:'', top: ''});\r\n",
+       "                }\r\n",
+       "\r\n",
+       "                me.$el.attr('qcodes-state', state);\r\n",
+       "\r\n",
+       "                if(state === 'floated') {\r\n",
+       "                    me.$el\r\n",
+       "                        .draggable({stop: function() { me.clipBounds(); }})\r\n",
+       "                        .css({\r\n",
+       "                            left: window.innerWidth - me.$el.width() - 15,\r\n",
+       "                            top: window.innerHeight - me.$el.height() - 10\r\n",
+       "                        });\r\n",
+       "                }\r\n",
+       "\r\n",
+       "                // any previous highlighting is now moot\r\n",
+       "                me.$el.removeClass('qcodes-highlight');\r\n",
+       "            }, 0);\r\n",
+       "\r\n",
+       "        },\r\n",
+       "\r\n",
+       "        clipBounds: function() {\r\n",
+       "            var me = this;\r\n",
+       "            if(me.$el.attr('qcodes-state') === 'floated') {\r\n",
+       "                var bounds = me.$el[0].getBoundingClientRect(),\r\n",
+       "                    minVis = 40,\r\n",
+       "                    maxLeft = window.innerWidth - minVis,\r\n",
+       "                    minLeft = minVis - bounds.width,\r\n",
+       "                    maxTop = window.innerHeight - minVis;\r\n",
+       "\r\n",
+       "                if(bounds.left > maxLeft) me.$el.css('left', maxLeft);\r\n",
+       "                else if(bounds.left < minLeft) me.$el.css('left', minLeft);\r\n",
+       "\r\n",
+       "                if(bounds.top > maxTop) me.$el.css('top', maxTop);\r\n",
+       "                else if(bounds.top < 0) me.$el.css('top', 0);\r\n",
+       "            }\r\n",
+       "        },\r\n",
+       "\r\n",
+       "        display: function(message) {\r\n",
+       "            var me = this;\r\n",
+       "            if(message) {\r\n",
+       "                var initialScroll = me.outputArea.scrollTop();\r\n",
+       "                me.outputArea.scrollTop(me.outputArea.prop('scrollHeight'));\r\n",
+       "                var scrollBottom = me.outputArea.scrollTop();\r\n",
+       "\r\n",
+       "                if(me.$el.attr('qcodes-state') === 'minimized') {\r\n",
+       "                    // if we add text and the box is minimized, highlight the\r\n",
+       "                    // title bar to alert the user that there are new messages.\r\n",
+       "                    // remove then add the class, so we get the animation again\r\n",
+       "                    // if it's already highlighted\r\n",
+       "                    me.$el.removeClass('qcodes-highlight');\r\n",
+       "                    setTimeout(function(){\r\n",
+       "                        me.$el.addClass('qcodes-highlight');\r\n",
+       "                    }, 0);\r\n",
+       "                }\r\n",
+       "\r\n",
+       "                var newLines = message.split('\\n'),\r\n",
+       "                    out = me.outputLines,\r\n",
+       "                    outLen = out.length;\r\n",
+       "                if(outLen) out[outLen - 1] += newLines[0];\r\n",
+       "                else out.push(newLines[0]);\r\n",
+       "\r\n",
+       "                for(var i = 1; i < newLines.length; i++) {\r\n",
+       "                    out.push(newLines[i]);\r\n",
+       "                }\r\n",
+       "\r\n",
+       "                if(out.length > me.maxOutputLength) {\r\n",
+       "                    out.splice(0, out.length - me.maxOutputLength + 1,\r\n",
+       "                        '<<< Output clipped >>>');\r\n",
+       "                }\r\n",
+       "\r\n",
+       "                me.outputArea.text(out.join('\\n'));\r\n",
+       "                me.clearButton.removeClass('disabled');\r\n",
+       "\r\n",
+       "                // if we were scrolled to the bottom initially, make sure\r\n",
+       "                // we stay that way.\r\n",
+       "                me.outputArea.scrollTop(initialScroll === scrollBottom ?\r\n",
+       "                    me.outputArea.prop('scrollHeight') : initialScroll);\r\n",
+       "            }\r\n",
+       "\r\n",
+       "            me.showSubprocesses();\r\n",
+       "            me.updateState();\r\n",
+       "        },\r\n",
+       "\r\n",
+       "        showSubprocesses: function() {\r\n",
+       "            var me = this,\r\n",
+       "                replacer = me.subprocessesMultiline ? '
' : ', ',\r\n", + " processes = (me.model.get('_processes') || '')\r\n", + " .replace(/\\n/g, '>' + replacer + '<');\r\n", + "\r\n", + " if(processes) processes = '<' + processes + '>';\r\n", + " else processes = 'No subprocesses';\r\n", + "\r\n", + " me.abortButton.toggleClass('disabled', processes.indexOf('Measurement')===-1);\r\n", + "\r\n", + " me.subprocessList.html(processes);\r\n", + " }\r\n", + " });\r\n", + " manager.WidgetManager.register_widget_view('SubprocessView', SubprocessView);\r\n", + "});\r\n" ], "text/plain": [ "" @@ -294,82 +295,82 @@ { "data": { "text/html": [ - "" ], "text/plain": [ @@ -394,7 +395,8 @@ "\n", "# this makes a widget in the corner of the window to show and control\n", "# subprocesses and any output they would print to the terminal\n", - "qc.show_subprocess_widget()" + "qc.show_subprocess_widget()\n", + "\n" ] }, { @@ -478,23 +480,826 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Data is DataSet:\n", + " mode = DataMode.LOCAL\n", + " location = 'data/2016-08-25/#031_{name}_16-41-22'\n", + " | | | \n", + " Setpoint | gates_chan0_set | chan0 | (401,)\n", + " Measured | meter_amplitude | amplitude | (401,)\n" + ] + }, + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " this.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width);\n", + " canvas.attr('height', height);\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DataSet:\n", + " mode = DataMode.LOCAL\n", + " location = 'data/2016-09-29/#029_{name}_15-13-41'\n", + " | | | \n", + " Setpoint | gates_chan1_set | chan1 | (30,)\n", + " Setpoint | gates_chan0_set | chan0 | (30, 54)\n", + " Measured | meter_amplitude_0 | amplitude | (30, 54)\n", + " Measured | meter_amplitude_3 | amplitude | (30, 54)\n", + "started at 2016-09-29 15:13:57\n" + ] + } + ], "source": [ - "# It may be that live plotting is not working on your system (see #259)\n", - "# Below is a snippet that serves as a workaround, this will be removed upon closing #259\n", - "\n", - "# while data.sync():\n", - "# plotQ.update()\n", - "# plotQ.update()" + "plot = qc.MatPlot(data.meter_amplitude_0, cmap=plt.cm.hot, figsize=(12, 4.5), subplots=(1, 2))\n", + "plot.add(data.meter_amplitude_3, cmap=plt.cm.hot, subplot=2)\n", + "data2 = loop.with_bg_task(plot.update, 0.0005).run(name='2D_test',background=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Example: multiple 2D measurements with live plotting" + "### The equivalent in QtPlot" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": { - "collapsed": false, - "scrolled": false + "collapsed": false }, "outputs": [ { @@ -1439,178 +2222,161 @@ "text": [ "DataSet:\n", " mode = DataMode.LOCAL\n", - " location = 'data/2016-09-27/#001_{name}_15-07-17'\n", + " location = 'data/2016-09-29/#030_{name}_15-13-57'\n", " | | | \n", " Setpoint | gates_chan1_set | chan1 | (30,)\n", " Setpoint | gates_chan0_set | chan0 | (30, 54)\n", " Measured | meter_amplitude_0 | amplitude | (30, 54)\n", " Measured | meter_amplitude_3 | amplitude | (30, 54)\n", - "started at 2016-09-27 15:07:33\n" + "started at 2016-09-29 15:14:23\n" ] } ], "source": [ - "loop2 = qc.Loop(c1[-15:15:1], 0.01).loop(c0[-15:12:.5], 0.001).each(\n", + "loop = qc.Loop(c1[-15:15:1], 0.01).loop(c0[-15:12:.5], 0.001).each(\n", " meter.amplitude, # first measurement, at c2=0 -> amplitude_0 bcs it's action 0\n", " qc.Task(c2.set, 1), # action 1 -> c2.set(1)\n", " qc.Wait(0.001),\n", " meter.amplitude, # second measurement, at c2=1 -> amplitude_4 bcs it's action 4\n", " qc.Task(c2.set, 0)\n", " )\n", - "data2 = loop2.get_data_set(data_manager=False)\n", - "\n", - "# use the subplot and add features of qc.MatPlot\n", - "# plot2 = qc.MatPlot(data2.meter_amplitude_0, cmap=plt.cm.hot, figsize=(12, 4.5), subplots=(1, 2))\n", - "# plot2.add(data2.meter_amplitude_3, cmap=plt.cm.hot, subplot=2)\n", + "data = loop.get_data_set(data_manager=False)\n", "\n", - "# the equivalent in QtPlot\n", - "# by clearing the old window it can be reused\n", "plotQ = qc.QtPlot()\n", - "plotQ.add(data2.meter_amplitude_0, figsize=(1200, 500))\n", - "plotQ.add(data2.meter_amplitude_3, subplot=2)\n", - "\n", - "data2 = loop2.with_bg_task(plotQ.update, 0.0005).run(name='2D_test',background=False)\n" + "plotQ.add(data.meter_amplitude_0, figsize=(1200, 500))\n", + "plotQ.add(data.meter_amplitude_3, subplot=2)\n", + "data2 = loop.with_bg_task(plotQ.update, 0.0005).run(name='2D_test',background=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Example same outer loop, different inner loop " + "### Example same outer loop, different inner loop " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [], "source": [ - "data3 = qc.Loop(c1[-15:15:1], 0.1).each(\n", + "loop3 = qc.Loop(c1[-15:15:1], 0.1).each(\n", " qc.Task(c0.set, -10),\n", " qc.Task(c2.set, 0),\n", " # a 1D measurement\n", " meter.amplitude,\n", - " # a 2D sweep, .each is actually unnecessary bcs this is the default measurement\n", + " # a 2D sweep, .each is actually unnecessary because this is the default measurement\n", " qc.Loop(c0[-15:15:1], 0.001).each(meter.amplitude),\n", " qc.Task(c0.set, -10),\n", " # a 2D sweep with the same outer but different inner loop\n", " qc.Loop(c2[-10:10:0.2], 0.001).each(meter.amplitude),\n", " AverageGetter(meter.amplitude, c2[-10:10:0.2], 0.001)\n", - ").run(name='TwoD_different_inner_test')\n", - "\n", - "# several plots updating simultaneously\n", - "# plot3 = qc.MatPlot(data3.meter_amplitude_3_0, cmap=plt.cm.hot)\n", - "# plot3b = qc.MatPlot(data3.meter_amplitude_5_0, cmap=plt.cm.hot, figsize=(12, 4.5), subplots=(1,2))\n", - "# plot3b.add(data3.meter_avg_amplitude, subplot=2)\n", - "plotQ.clear()\n", - "plotQ.add(data3.meter_amplitude_3_0)\n", - "plotQ.add(data3.meter_amplitude_5_0, cmap='viridis', subplot=2)\n", - "plotQ.add(data3.meter_avg_amplitude, subplot=3)" + ")\n", + "data = loop3.get_data_set(data_manager=False) \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Example 2D scan and average" + "### several plots updating simultaneously (Currently broken on matplotlib)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { - "collapsed": false, - "scrolled": false + "collapsed": false }, - "outputs": [], - "source": [ - "# An example of a parameter that returns several values of different dimension\n", - "# This produces the last two arrays from data3, but only takes the data once.\n", - "data4 = qc.Loop(c1[-15:15:1], 0.01).each(\n", - " AverageAndRaw(meter.amplitude, c2[-10:10:0.2], 0.001)\n", - ").run(name='TwoD_average_test')\n", - "\n", - "# plot4 = qc.MatPlot(data4.meter_amplitude, cmap=plt.cm.hot, subplots=(1,2), figsize=(12, 4.5))\n", - "# plot4.add(data4.meter_avg_amplitude, subplot=2)\n", - "\n", - "plotQ.clear()\n", - "plotQ.add(data4.meter_amplitude, figsize=(1200, 500), cmap='viridis')\n", - "plotQ.add(data4.meter_avg_amplitude, subplot=2)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/unga/Hack/qdev/qcodes/plots/pyqtgraph.py:292: UserWarning: nonuniform nested setpoint array passed to pyqtgraph. ignoring, using default scaling.\n", + " 'nonuniform nested setpoint array passed to '\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DataSet:\n", + " mode = DataMode.LOCAL\n", + " location = 'data/2016-09-29/#031_{name}_15-14-23'\n", + " | | | \n", + " Setpoint | gates_chan1_set | chan1 | (30,)\n", + " Measured | meter_amplitude_2 | amplitude | (30,)\n", + " Setpoint | gates_chan0_set | chan0 | (30, 30)\n", + " Measured | meter_amplitude_3_0 | amplitude | (30, 30)\n", + " Setpoint | gates_chan2_set | chan2 | (30, 100)\n", + " Measured | meter_amplitude_5_0 | amplitude | (30, 100)\n", + " Measured | meter_avg_amplitude | avg_amplitude | (30,)\n", + "started at 2016-09-29 15:15:07\n" + ] + } + ], "source": [ - "# Data analysis, loading old data " + "plotQ = qc.QtPlot()\n", + "plotQ.add(data.meter_amplitude_3_0)\n", + "plotQ.add(data.meter_amplitude_5_0, cmap='viridis', subplot=2)\n", + "plotQ.add(data.meter_avg_amplitude, subplot=3)\n", + "data = loop3.with_bg_task(plotQ.update, 0.0005).run(name='TwoD_different_inner_test', background=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "`DataSet` objects are not intended to be instantiated directly, but\n", - "rather through the helper functions:\n", - "- `load_data` for existing data sets, including the data currently\n", - " being acquired.\n", - "- `new_data` to make an empty data set to be populated with new\n", - " measurements or simulation data. `new_data` is called internally by\n", - " `Loop.run()` so is also generally not needed directly.\n", + "### Example 2D scan and average\n", "\n", - "If you omit `location`, or if `location` matches the data set currently\n", - "being acquired, `load_data` and subsequent calls to `data_set.sync()`\n", - "will pull from the `DataServer` (`DataMode.PULL_FROM_SERVER`).\n", - "Otherwise `load_data` and `data_set.sync()` will read from disk\n", - "(`DataMode.LOCAL`).\n", - "\n", - "Note that a `DataServer` is, at least for now, local to one parent\n", - "process / notebook, so if you open a separate notebook for analysis, even\n", - "your live data will be pulled from disk." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Use the location of a file created earlier this session\n", - "location = data3.location \n", - "print(location)\n", - "data = qc.load_data(location=location)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "data" + " An example of a parameter that returns several values of different dimension\n", + " This produces the last two arrays from data3, but only takes the data once." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { - "collapsed": false + "collapsed": false, + "scrolled": false }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "DataSet:\n", + " mode = DataMode.LOCAL\n", + " location = 'data/2016-09-29/#032_{name}_15-15-07'\n", + " | | | \n", + " Setpoint | gates_chan1_set | chan1 | (30,)\n", + " Measured | chan2 | chan2 | (30, 100)\n", + " Measured | meter_amplitude | amplitude | (30, 100)\n", + " Measured | meter_avg_amplitude | avg_amplitude | (30,)\n", + "started at 2016-09-29 15:15:28\n" + ] + } + ], "source": [ - "plotQ.clear()\n", - "plotQ.add(data.meter_avg_amplitude)" + "loop4 = qc.Loop(c1[-15:15:1], 0.01).each(\n", + " AverageAndRaw(meter.amplitude, c2[-10:10:0.2], 0.001)\n", + ")\n", + "data4 = loop4.get_data_set(data_manager=False)\n", + "plotQ = qc.QtPlot()\n", + "plotQ.add(data4.meter_amplitude, figsize=(1200, 500), cmap='viridis')\n", + "plotQ.add(data4.meter_avg_amplitude, subplot=2)\n", + "data4 = loop4.with_bg_task(plotQ.update, 0.005).run(name='TwoD_average_test', background=False)" ] } ], "metadata": { + "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python [default]", "language": "python", "name": "python3" }, From d9a02ad8ef50fda3c829ee78dfc203951e337845 Mon Sep 17 00:00:00 2001 From: Giulio Ungaretti Date: Thu, 29 Sep 2016 15:56:59 +0200 Subject: [PATCH 11/11] fix: Strip white spaces --- qcodes/loops.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qcodes/loops.py b/qcodes/loops.py index 9b3f7d710267..e4b89c3bf799 100644 --- a/qcodes/loops.py +++ b/qcodes/loops.py @@ -890,7 +890,7 @@ def _run_loop(self, first_delay=0, action_indices=(), # after the first setpoint, delay reverts to the loop delay delay = self.delay - # now check for a background task and execute it if it's + # now check for a background task and execute it if it's # been long enough since the last time # don't let exceptions in the background task interrupt # the loop @@ -913,7 +913,7 @@ def _run_loop(self, first_delay=0, action_indices=(), tprint('loop %s DONE: %d/%d (%.1f [s])' % ( self.sweep_values.name, i + 1, imax, time.time() - t0), dt=-1, tag='outerloop') - + # run the background task one last time to catch the last setpoint(s) if self.bg_task is not None: self.bg_task()