Skip to content

Commit

Permalink
fix: Improve example notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
giulioungaretti committed Oct 23, 2016
1 parent 6f276d1 commit 3d4b850
Showing 1 changed file with 123 additions and 104 deletions.
227 changes: 123 additions & 104 deletions docs/examples/Configuring_QCoDeS.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand Down Expand Up @@ -369,7 +369,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"collapsed": false
},
Expand All @@ -382,7 +382,7 @@
" 'user': {}}"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -393,7 +393,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"collapsed": false
},
Expand All @@ -406,7 +406,7 @@
" 'user': {}}"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -424,7 +424,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"collapsed": false
},
Expand All @@ -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
},
Expand All @@ -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"
]
}
],
Expand All @@ -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
},
Expand All @@ -502,7 +517,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -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
},
Expand All @@ -556,7 +658,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {
"collapsed": false
},
Expand All @@ -574,7 +676,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {
"collapsed": false
},
Expand All @@ -592,7 +694,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {
"collapsed": false
},
Expand All @@ -604,7 +706,7 @@
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValidationError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-11-28539f77dfd3>\u001b[0m in \u001b[0;36m<module>\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<ipython-input-12-28539f77dfd3>\u001b[0m in \u001b[0;36m<module>\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",
Expand All @@ -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": {
Expand Down

0 comments on commit 3d4b850

Please sign in to comment.