-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1365 from Dominik-Vogel/default_subscription
Add Subscribers from config
- Loading branch information
Showing
7 changed files
with
470 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Live Plotting\n", | ||
"(back to overview [offline](../Main.ipynb),[online](https://nbviewer.jupyter.org/github/QCoDeS/Qcodes/tree/master/docs/examples/Main.ipynb))\n", | ||
"\n", | ||
"\n", | ||
"[read on nbviewer](https://nbviewer.jupyter.org/github/QCoDeS/Qcodes/tree/master/docs/examples/plotting/live_plotting.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## TL;DR\n", | ||
"Enable live plotting by specifying 'subscripition.default_subscriber' in your qcodesrc.json." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Introduction\n", | ||
"Live plotting in qcodes can be achieved by sending the acquired data to other applications. For this an adapter for the specific application is necessary. These adapter register as subscribers to the qcodes dataset and expose a callback that gets called on regular intervals that can be specified.\n", | ||
"\n", | ||
"## Live plotting with plottr as an example\n", | ||
"An example of a live plotting application is for example [*plottr*](https://github.com/kouwenhovenlab/plottr). After installing *plottr* you can use it by simply setting `subscription.default_subscribers` to `[\"Plottr\"]` in your `qcodesrc.json` file or alternatively by updating your qcodes config for your current session:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import qcodes\n", | ||
"qcodes.config.subscription.default_subscribers = [\"Plottr\"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"With this simple chang you can run all your notebooks without any changes and live data will be streamed to plottr. For that lets consider the simple example adapted from the dataset docs:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib notebook\n", | ||
"import numpy as np\n", | ||
"from time import sleep\n", | ||
"from qcodes import find_or_create_instrument, initialise_database, new_experiment, Measurement\n", | ||
"from qcodes.tests.instrument_mocks import DummyInstrument" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"dac = find_or_create_instrument(DummyInstrument, 'dac', gates=['ch1'], recreate=True)\n", | ||
"dmm = find_or_create_instrument(DummyInstrument, 'dmm', gates=['v1'], recreate=True)\n", | ||
"\n", | ||
"def customgetter():\n", | ||
" return 5*np.exp(-0.2*dac.ch1()) + 0.02*5*np.random.randn()\n", | ||
" \n", | ||
"dmm.v1.get = customgetter" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"tutorial_exp#no sample#7@./exp_container_tutorial.db\n", | ||
"----------------------------------------------------" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"initialise_database()\n", | ||
"new_experiment(name='tutorial_exp', sample_name=\"no sample\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Running the next cell should render the data in the live plotting front end:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Starting experimental run with id: 17\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"meas = Measurement()\n", | ||
"meas.register_parameter(dac.ch1) # register the first independent parameter\n", | ||
"meas.register_parameter(dmm.v1, setpoints=(dac.ch1,)) # now register the dependent oone\n", | ||
"# make live plotting faster:\n", | ||
"meas.write_period = 0.1\n", | ||
"\n", | ||
"with meas.run() as datasaver: \n", | ||
" for set_v in np.linspace(0, 25, 100):\n", | ||
" dac.ch1.set(set_v)\n", | ||
" get_v = dmm.v1.get()\n", | ||
" datasaver.add_result((dac.ch1, set_v),\n", | ||
" (dmm.v1, get_v))\n", | ||
" # we added some extra sleep so that the live plotting can be observed\n", | ||
" sleep(0.1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.6" | ||
}, | ||
"nbsphinx": { | ||
"execute": "never" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": { | ||
"height": "1225px", | ||
"left": "1336px", | ||
"top": "111.133px", | ||
"width": "165px" | ||
}, | ||
"toc_section_display": true, | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.