From 3d4b8501914897b5b186b24f26af761282dd93d1 Mon Sep 17 00:00:00 2001 From: Giulio Ungaretti Date: Fri, 21 Oct 2016 17:54:07 +0200 Subject: [PATCH] fix: Improve example notebook --- docs/examples/Configuring_QCoDeS.ipynb | 227 ++++++++++++++----------- 1 file changed, 123 insertions(+), 104 deletions(-) diff --git a/docs/examples/Configuring_QCoDeS.ipynb b/docs/examples/Configuring_QCoDeS.ipynb index 23a31d45534..b5f3b0ec017 100644 --- a/docs/examples/Configuring_QCoDeS.ipynb +++ b/docs/examples/Configuring_QCoDeS.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": { "collapsed": false }, @@ -369,7 +369,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "collapsed": false }, @@ -382,7 +382,7 @@ " 'user': {}}" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -393,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -406,7 +406,7 @@ " 'user': {}}" ] }, - "execution_count": 3, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -424,7 +424,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -446,16 +446,31 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Defaults are the settings that are shipped with the package, which you can overwrite programmatically.\n", + "## configuring qcodes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Defaults are the settings that are shipped with the package, which you can overwrite programmatically." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A way to customize qcodes is to write your own json files, they are expected to be in the directories printed below.\n", + "One will be empty because one needs to define first the environment variable in the OS.\n", "\n", - "The simplest way is to write your onw json files, they are expected to be in the following directories one will be empty because one needs to define first the eniroment varialbe in ones OS.\n", + "They are ordered by \"weight\", meaning that the last file always wins if it's overwriting any preconfigured defaults or values in the other files.\n", "\n", - "They are ordered by \"weight\", meaning that the last file always wins if it's overwriting any preconfigured defaults or values in the other files." + "Simply copy the file to the directories and you are good to go." ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -464,9 +479,9 @@ "name": "stdout", "output_type": "stream", "text": [ - "/home/unga/config.json\n", + "/home/unga/qcodesrc.json\n", "\n", - "/home/unga/Hack/qdev/docs/examples/config.json\n" + "/home/unga/Hack/qdev/docs/examples/qcodesrc.json\n" ] } ], @@ -478,12 +493,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The easiest way to add something to the config is to use the provided helper:" + "But the easiest way to add something to the config is to use the provided helper:" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -502,7 +517,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": { "collapsed": false }, @@ -524,12 +539,99 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### To use this in your experiment:" + "## saving changes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "All the changes made to the defaults are stored, and one can then decide to save them to the expected place." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method save_to_cwd in module qcodes.config.config:\n", + "\n", + "save_to_cwd() method of qcodes.config.config.Config instance\n", + " Save files to current working dir\n", + "\n" + ] + } + ], + "source": [ + "help(qc.config.save_to_cwd)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method save_to_env in module qcodes.config.config:\n", + "\n", + "save_to_env() method of qcodes.config.config.Config instance\n", + " Save files to env path\n", + "\n" + ] + } + ], + "source": [ + "help(qc.config.save_to_env)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false, + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on method save_to_home in module qcodes.config.config:\n", + "\n", + "save_to_home() method of qcodes.config.config.Config instance\n", + " Save files to home dir\n", + "\n" + ] + } + ], + "source": [ + "help(qc.config.save_to_home)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Using a custom configured variable in your experiment:\n", + "\n", + "Simply get the value you have set before with dot notation.\n", + "For example:" + ] + }, + { + "cell_type": "code", + "execution_count": 9, "metadata": { "collapsed": false }, @@ -556,7 +658,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": { "collapsed": false }, @@ -574,7 +676,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -592,7 +694,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": { "collapsed": false }, @@ -604,7 +706,7 @@ "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mValidationError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mqc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcurrent_config\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloglevel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'YOLO'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mqc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;31m# NOTE that you how have a broken config!\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mqc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcurrent_config\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcore\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloglevel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'YOLO'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mqc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconfig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[1;31m# NOTE that you how have a broken config!\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home/unga/Hack/qdev/qcodes/config/config.py\u001b[0m in \u001b[0;36mvalidate\u001b[1;34m(self, json_config, schema, extra_schema_path)\u001b[0m\n\u001b[0;32m 168\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 169\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mjson_config\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mschema\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 170\u001b[1;33m \u001b[0mjsonschema\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcurrent_config\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcurrent_schema\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 171\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 172\u001b[0m \u001b[0mjsonschema\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mjson_config\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mschema\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;32m/home/unga/.pyenv/versions/3.4.5/envs/qcodes/lib/python3.4/site-packages/jsonschema/validators.py\u001b[0m in \u001b[0;36mvalidate\u001b[1;34m(instance, schema, cls, *args, **kwargs)\u001b[0m\n\u001b[0;32m 476\u001b[0m \u001b[0mcls\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalidator_for\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mschema\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 477\u001b[0m \u001b[0mcls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_schema\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mschema\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 478\u001b[1;33m \u001b[0mcls\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mschema\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minstance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;32m/home/unga/.pyenv/versions/3.4.5/envs/qcodes/lib/python3.4/site-packages/jsonschema/validators.py\u001b[0m in \u001b[0;36mvalidate\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 121\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mvalidate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 122\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0merror\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miter_errors\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 123\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0merror\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 124\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 125\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mis_type\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minstance\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", @@ -617,89 +719,6 @@ "qc.config.validate() \n", "# NOTE that you how have a broken config! " ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## saving changes" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "All the changes made to the defaults are stored, and one can then decide to save them to the expected place." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on method save_to_cwd in module qcodes.config.config:\n", - "\n", - "save_to_cwd() method of qcodes.config.config.Config instance\n", - " Save files to current working dir\n", - "\n" - ] - } - ], - "source": [ - "help(qc.config.save_to_cwd)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on method save_to_env in module qcodes.config.config:\n", - "\n", - "save_to_env() method of qcodes.config.config.Config instance\n", - " Save files to env path\n", - "\n" - ] - } - ], - "source": [ - "help(qc.config.save_to_env)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on method save_to_home in module qcodes.config.config:\n", - "\n", - "save_to_home() method of qcodes.config.config.Config instance\n", - " Save files to home dir\n", - "\n" - ] - } - ], - "source": [ - "help(qc.config.save_to_home)" - ] } ], "metadata": {