Skip to content

Commit

Permalink
Merge 78f3550 into cb02add
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Ristè committed Sep 24, 2019
2 parents cb02add + 78f3550 commit 453dc43
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 2,160 deletions.
1 change: 0 additions & 1 deletion QGL/PulseSequencePlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def extract_waveforms(fileNames, nameDecorator='', time=False):

translator = resolve_translator(fileName, translators)
wfs = translator.read_sequence_file(fileName)
print(f"Sampling rate from extract_waveforms {translator.SAMPLING_RATE}")
sample_time = 1.0/translator.SAMPLING_RATE if time else 1
for (k, seqs) in sorted(wfs.items()):
if all_zero_seqs(seqs):
Expand Down
70 changes: 70 additions & 0 deletions doc/Generate channel library.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Channel library\n",
"\n",
"This code to generate a sample channel library and stores it in the database `example.sqlite`. This channel library is used in the examples in this directory. See Auspex [example notebooks](https://github.com/BBN-Q/Auspex/tree/develop/doc/examples) for documentation. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from QGL import *\n",
"\n",
"cl = ChannelLibrary(db_resource_name=\"./example.sqlite\")\n",
"q1 = cl.new_qubit(\"q1\")\n",
"q2 = cl.new_qubit(\"q2\")\n",
"CNOT12 = cl.new_edge(q1, q2)\n",
"aps2_1 = cl.new_APS2(\"BBNAPS1\", address=\"192.168.5.101\") \n",
"aps2_2 = cl.new_APS2(\"BBNAPS2\", address=\"192.168.5.102\")\n",
"aps2_3 = cl.new_APS2(\"BBNAPS3\", address=\"192.168.5.103\") \n",
"aps2_4 = cl.new_APS2(\"BBNAPS4\", address=\"192.168.5.104\")\n",
"dig_1 = cl.new_X6(\"X6_1\", address=0)\n",
"h1 = cl.new_source(\"Holz1\", \"HolzworthHS9000\", \"HS9004A-009-1\", power=-30)\n",
"h2 = cl.new_source(\"Holz2\", \"HolzworthHS9000\", \"HS9004A-009-2\", power=-30) \n",
"cl.set_control(q1, aps2_1, generator=h1)\n",
"cl.set_measure(q1, aps2_2, dig_1.ch(1), generator=h2)\n",
"cl.set_control(q2, aps2_3, generator=h1)\n",
"cl.set_measure(q2, aps2_4, dig_1.ch(2), generator=h2)\n",
"cl.set_master(aps2_1, aps2_1.ch(\"m2\"))\n",
"cl.set_control(CNOT12, aps2_1, generator=h1)\n",
"cl[\"q1\"].measure_chan.frequency = 0e6\n",
"cl.commit()"
]
},
{
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
152 changes: 128 additions & 24 deletions doc/QGL-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"metadata": {},
"source": [
"# Setup\n",
"Load the necessary modules from QGL. This will also import ``numpy`` into the namespace as ``np``."
"\n",
"Load the necessary modules from QGL. This will also import ``numpy`` into the namespace as ``np``. \n",
"\n",
"The AWGDir environment variable is used to indicate where QGL will store it's output sequence files. First we load the QGL module. It defaults to a temporary directory as provided by Python's tempfile module.\n"
]
},
{
Expand All @@ -17,31 +20,43 @@
"from QGL import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we instantiate the channel library. By default bbndb will use an sqlite database at the location specified by the BBN_DB environment variabe, but we override this behavior below in order to use a temporary in memory database for testing purposes.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"output_notebook()"
"cl = ChannelLibrary(db_resource_name=\":memory:\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The channel library has a number of convenience functions defined to create instruments and qubits, as well as functions to define the relationships between them. Let us create a qubit first:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"# create a channel library object, which loads qubit configurations from file.\n",
"# By default, we look for the BBN_MEAS_FILE environment variable for the location of the\n",
"# YAML configuration. Calling ChannelLibrary with no arguments will load the file from\n",
"# that location.\n",
"#cl = ChannelLibrary()\n",
"\n",
"# Altneratively you can specify the desired configuration file location.\n",
"cl = ChannelLibrary(library_file=\"./config/measure.yml\")"
"q1 = cl.new_qubit(\"q1\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In order to compile the QGL program into pulse sequences, we need to define a minimal hardware configuration. Basically, we need to specify AWG resources for output pulse compilation and digitizer resources for signal measurement. "
]
},
{
Expand All @@ -50,47 +65,136 @@
"metadata": {},
"outputs": [],
"source": [
"# create a Qubit object (holds onto pulse parameters like shape, duration, channel, etc)\n",
"q1 = QubitFactory('q1')"
"# Most calls required label and address. Let's define \n",
"# an AWG for control pulse generation \n",
"aps2_1 = cl.new_APS2(\"BBNAPS1\", address=\"192.168.5.101\") \n",
"# an AWG for measurement pulse generation\n",
"aps2_2 = cl.new_APS2(\"BBNAPS2\", address=\"192.168.5.102\")\n",
"# and digitizer for measurement collection\n",
"dig_1 = cl.new_X6(\"X6_1\", address=0)\n",
"\n",
"# Qubit q1 is controlled by AWG aps2_1, and uses microwave source h1\n",
"cl.set_control(q1, aps2_1)\n",
"# Qubit q1 is measured by AWG aps2_2 and digitizer dig_1, and uses microwave source h2\n",
"cl.set_measure(q1, aps2_2, dig_1.ch(1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic sequence construction"
"# Basic sequence construction and plotting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can construct sequences by creating lists of `Pulse` objects. These can be constructed by calling various primitives defined for qubits. For example, 90 and 180 degree rotations about X and Y:"
"You can construct simple gate sequences by creating `Lists` of `Pulse` objects. These can be constructed by calling various primitives defined for qubits, for example, 90 and 180 degree rotations about X and Y:"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"seq = [X90(q1),Y90(q1),X(q1),Id(q1),Y(q1)]"
"seq1 = [[X(q1), Y(q1)]]\n",
"seq2 = [[X90(q1),Y90(q1),X(q1),Id(q1),Y(q1)]]\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display these in the \"logical\" space with the `show` command. Since our `Qubit` object is a quadrature channel, you see two colors corresponding to I and Q control."
"This sequence of pulses can be plotted for visual review. First, you must compile the QGL into pulses based on the hardware defined above. Since our `Qubit` object is a quadrature channel, you see two colors corresponding to the I and Q control signals."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Compiled 1 sequences.\n"
]
}
],
"source": [
"show(seq)"
"mf = compile_to_hardware(seq1, 'Test1')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1cbc56fea1b8497b9d03453ec8266d8d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(IntSlider(value=1, description='Segment', max=1, min=1), Figure(animation_duration=50, axes=[Ax…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plot_pulse_files(mf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, let's visualize the second sequence. "
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Compiled 1 sequences.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bd9aaa48fbec45dabd46bf8320cf8ad1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(IntSlider(value=1, description='Segment', max=1, min=1), Figure(animation_duration=50, axes=[Ax…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mf = compile_to_hardware(seq2, 'Test2')\n",
"plot_pulse_files(mf)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Constructing more sophisticated sequences (stopped here)"
]
},
{
Expand Down Expand Up @@ -401,7 +505,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 453dc43

Please sign in to comment.