|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Efficient generation of dynamic pulses - Hahn Echo\n", |
| 8 | + "This script implement a simulated Echo sequence, as described in the relative [blog post](https://blogs.zhinst.com/andrea/2021/09/08/efficient-generation-of-dynamic-pulses/)\n", |
| 9 | + "\n", |
| 10 | + "\n", |
| 11 | + "Copyright (C) 2021 Zurich Instruments\n", |
| 12 | + "\n", |
| 13 | + "This software may be modified and distributed under the terms of the MIT license. See the LICENSE file for details." |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": null, |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "#Define the parameters of the instrument\n", |
| 23 | + "dataserver_host = 'localhost' #Hostname or IP address of the dataserer\n", |
| 24 | + "dev_hd = 'devNNNN' #Device ID of the HDAWG\n", |
| 25 | + "awg_core = 0 #AWG Core (equal to output_channel//2)" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "code", |
| 30 | + "execution_count": null, |
| 31 | + "metadata": {}, |
| 32 | + "outputs": [], |
| 33 | + "source": [ |
| 34 | + "#Imports and initializations\n", |
| 35 | + "from zhinst.ziPython import ziDAQServer\n", |
| 36 | + "daq = ziDAQServer(dataserver_host, 8004, 6)\n", |
| 37 | + "\n", |
| 38 | + "from hdawg_utils import HDAWG_Core\n", |
| 39 | + "hdawg = HDAWG_Core(daq, dev_hd, awg_core)" |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + "cell_type": "code", |
| 44 | + "execution_count": null, |
| 45 | + "metadata": {}, |
| 46 | + "outputs": [], |
| 47 | + "source": [ |
| 48 | + "#Waveform paramaters\n", |
| 49 | + "hdawg.constants.PULSE_WIDTH = 10e-9 #ns\n", |
| 50 | + "hdawg.constants.SIGMAS_PULSE = 6\n", |
| 51 | + "\n", |
| 52 | + "#Sequence parameters\n", |
| 53 | + "hdawg.constants.T_START = 16\n", |
| 54 | + "hdawg.constants.T_END = 10240\n", |
| 55 | + "hdawg.constants.T_STEP = 27\n", |
| 56 | + "\n", |
| 57 | + "#Readout parameters\n", |
| 58 | + "hdawg.constants.TRIGGER_LEN = 32\n", |
| 59 | + "hdawg.constants.READOUT_LEN = 1024\n", |
| 60 | + "\n", |
| 61 | + "#Command Table paramaters\n", |
| 62 | + "hdawg.constants.OFFSET_PI = 16\n", |
| 63 | + "\n", |
| 64 | + "#amplitude paramaters\n", |
| 65 | + "AMPLITUDE_PI = 1.0\n", |
| 66 | + "AMPLITUDE_PI_2 = 0.5\n", |
| 67 | + "\n", |
| 68 | + "#Creation of the command table\n", |
| 69 | + "ct = []\n", |
| 70 | + "\n", |
| 71 | + "#pi/2 entries\n", |
| 72 | + "for i in range(16):\n", |
| 73 | + " entry = {\n", |
| 74 | + " \"index\": i,\n", |
| 75 | + " \"waveform\": {\n", |
| 76 | + " \"index\": i\n", |
| 77 | + " },\n", |
| 78 | + " \"amplitude0\": {\n", |
| 79 | + " \"value\": AMPLITUDE_PI_2,\n", |
| 80 | + " \"increment\": False\n", |
| 81 | + " }\n", |
| 82 | + " }\n", |
| 83 | + " ct.append(entry)\n", |
| 84 | + "\n", |
| 85 | + "#pi entries\n", |
| 86 | + "for i in range(16):\n", |
| 87 | + " entry = {\n", |
| 88 | + " \"index\": i+hdawg.constants.OFFSET_PI,\n", |
| 89 | + " \"waveform\": {\n", |
| 90 | + " \"index\": i\n", |
| 91 | + " },\n", |
| 92 | + " \"amplitude0\": {\n", |
| 93 | + " \"value\": AMPLITUDE_PI,\n", |
| 94 | + " \"increment\": False\n", |
| 95 | + " }\n", |
| 96 | + " }\n", |
| 97 | + " ct.append(entry)\n", |
| 98 | + "\n", |
| 99 | + "\n", |
| 100 | + "seq_definition = \"\"\"\n", |
| 101 | + "//Calculations\n", |
| 102 | + "const PULSE_WIDTH_SAMPLE = PULSE_WIDTH*DEVICE_SAMPLE_RATE;\n", |
| 103 | + "const PULSE_TOTAL_LEN = ceil(PULSE_WIDTH_SAMPLE*SIGMAS_PULSE*2/16)*16;\n", |
| 104 | + "\n", |
| 105 | + "//Waveform definition\n", |
| 106 | + "wave pulse = gauss(PULSE_TOTAL_LEN, PULSE_TOTAL_LEN/2, PULSE_WIDTH_SAMPLE);\n", |
| 107 | + "\n", |
| 108 | + "//Create shifted waveforms\n", |
| 109 | + "cvar j;\n", |
| 110 | + "for (j = 0; j < 16; j++) {\n", |
| 111 | + " wave w_shifted = join(zeros(j), pulse, zeros(16-j)); //Create the j-samples shifted waveform\n", |
| 112 | + " assignWaveIndex(1,w_shifted, j); //Assign index j to the waveform\n", |
| 113 | + "}\n", |
| 114 | + "\n", |
| 115 | + "\n", |
| 116 | + "//Execution, no averaging\n", |
| 117 | + "var t = T_START;\n", |
| 118 | + "var tp;\n", |
| 119 | + "var t_fine1, t_fine1_entry, coarse1;\n", |
| 120 | + "var t2, t_fine2, coarse2;\n", |
| 121 | + "do {\n", |
| 122 | + " //Calculate target tau (remove 16 for the right padding, common to all pulses)\n", |
| 123 | + " tp = t - 16;\n", |
| 124 | + " \n", |
| 125 | + " //The first delay doesn't need further adjustments, since the fine shift\n", |
| 126 | + " // of the first pulse is always zero, so we use t1 = tp\n", |
| 127 | + " t_fine1 = tp & 0xF; //Fine shift 1 (samples), four least significant bits\n", |
| 128 | + " t_fine1_entry = t_fine1 + OFFSET_PI; //Fine shift 1 (CT entry index, adjust for pi-pulse)\n", |
| 129 | + " coarse1 = tp & -0x10; //Check if coarse delay 1 is needed (boolean)\n", |
| 130 | + " \n", |
| 131 | + " //Calculate target tau for the second wait.\n", |
| 132 | + " //Adjust for fine delay 1 by adding it to tp, so equal to\n", |
| 133 | + " // t2 = t - (16 - t_fine1)\n", |
| 134 | + " t2 = tp + t_fine1;\n", |
| 135 | + " t_fine2 = t2 & 0xF; //Fine shift 2 (samples and CT entry, no offset for pi/2-pulse)\n", |
| 136 | + " coarse2 = t2 & -0x10; //Check if coarse delay 2 is needed (boolean)\n", |
| 137 | + " \n", |
| 138 | + " resetOscPhase(); //Reset the oscillator\n", |
| 139 | + " \n", |
| 140 | + " //First pi/2-pulse, no shift\n", |
| 141 | + " executeTableEntry(0); //Play first pulse, no fine shift\n", |
| 142 | + " \n", |
| 143 | + " //First tau wait time\n", |
| 144 | + " if(coarse1)\n", |
| 145 | + " playZero(tp); //Evolution time tau (coarse)\n", |
| 146 | + " \n", |
| 147 | + " //pi-pulse\n", |
| 148 | + " executeTableEntry(t_fine1_entry); //Play second pulse, fine shift\n", |
| 149 | + " \n", |
| 150 | + " //Second tau wait time\n", |
| 151 | + " if(coarse2)\n", |
| 152 | + " playZero(t2); //Evolution time tau (coarse)\n", |
| 153 | + " \n", |
| 154 | + " //Second pi/2-pulse\n", |
| 155 | + " executeTableEntry(t_fine2); //Play third pulse, fine shift\n", |
| 156 | + "\n", |
| 157 | + " \n", |
| 158 | + " playWave(marker(TRIGGER_LEN, 1)); //Readout trigger\n", |
| 159 | + " playZero(READOUT_LEN); //Readout time\n", |
| 160 | + "\n", |
| 161 | + " t += T_STEP; //Increase wait time\n", |
| 162 | + "} while (t < T_END); //Loop until the end\n", |
| 163 | + "\"\"\"\n", |
| 164 | + "\n", |
| 165 | + "hdawg.config(seq_definition, ct=ct)" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": null, |
| 171 | + "metadata": {}, |
| 172 | + "outputs": [], |
| 173 | + "source": [ |
| 174 | + "hdawg.run()" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "code", |
| 179 | + "execution_count": null, |
| 180 | + "metadata": {}, |
| 181 | + "outputs": [], |
| 182 | + "source": [] |
| 183 | + } |
| 184 | + ], |
| 185 | + "metadata": { |
| 186 | + "kernelspec": { |
| 187 | + "display_name": "Python 3", |
| 188 | + "language": "python", |
| 189 | + "name": "python3" |
| 190 | + }, |
| 191 | + "language_info": { |
| 192 | + "codemirror_mode": { |
| 193 | + "name": "ipython", |
| 194 | + "version": 3 |
| 195 | + }, |
| 196 | + "file_extension": ".py", |
| 197 | + "mimetype": "text/x-python", |
| 198 | + "name": "python", |
| 199 | + "nbconvert_exporter": "python", |
| 200 | + "pygments_lexer": "ipython3", |
| 201 | + "version": "3.7.6" |
| 202 | + } |
| 203 | + }, |
| 204 | + "nbformat": 4, |
| 205 | + "nbformat_minor": 4 |
| 206 | +} |
0 commit comments