{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Dynamic Nuclear Polarisation/Changing repetition count during runtime\n", "\n", "This example demonstrates how to change the repetition count of pulses during runtime. One possible application of changing parameters during runtime is dynamic nuclear polarisation. We will call parameters which are able to change after program creation volatile. Since this example is meant to illustrate how the concept of changing the values of volatile parameter works, we will use simple example pulses.\n", "\n", "First we have to connect to the AWG (If you want to run this cell, set `awg_name` and possibly `awg_address` according to the AWG you are using). " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from qupulse.hardware.setup import HardwareSetup\n", "from doc.source.examples.hardware.zhinst import add_to_hardware_setup\n", "from doc.source.examples.hardware.tabor import add_tabor_to_hardware_setup\n", "\n", "awg_name = 'TABOR'\n", "awg_address = None\n", "hardware_setup = HardwareSetup()\n", "\n", "if awg_name == 'ZI':\n", " hdawg, channel_pairs = add_to_hardware_setup(hardware_setup, awg_address, name=awg_name)\n", " used_awg = hdawg.channel_pair_AB\n", "elif awg_name == 'TABOR':\n", " teawg, channel_pairs = add_tabor_to_hardware_setup(hardware_setup, tabor_address=awg_address, name=awg_name)\n", " used_awg = channel_pairs[0]\n", "else:\n", " ValueError('Unknown AWG')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a next step we create our dnp pulse template, with three different pumping schemes: 'minus', 'zero' and 'plus'. In reality these could for example be t-, s- and cs-pumping pulses." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from qupulse.pulses import PointPT, RepetitionPT\n", "\n", "zero = PointPT([(0, 0), ('t_quant', 0)], ('X', 'Y'))\n", "minus = PointPT([(0, '-x'), ('t_quant', '-x')], ('X', 'Y'))\n", "plus = PointPT([(0, 'x'), ('t_quant', 'x')], ('X', 'Y'))\n", "\n", "dnp = RepetitionPT(minus, 'n_minus') @ RepetitionPT(zero, 'n_zero') @ RepetitionPT(plus, 'n_plus')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "On program creation, we set the parameters and channel mappings of the program as usual. However we want to be able to change how often we repeat each of the pulses dynamically. For that we have to say on program creating which of the parameters are supposed to change during runtime, using the keyword `volatile`." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "sample_rate = used_awg.sample_rate / 10**9\n", "n_quant = 192\n", "t_quant = n_quant / sample_rate\n", "\n", "dnp_prog = dnp.create_program(parameters=dict(t_quant=float(t_quant), n_minus=3, n_zero=3, n_plus=3, x=0.25),\n", " channel_mapping={'X': '{}_A'.format(awg_name), 'Y': '{}_B'.format(awg_name)},\n", " volatile={'n_minus', 'n_zero', 'n_plus'})\n", "dnp_prog.cleanup()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we can upload our program to the AWG and use it as usual." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LOOP 1 times:\n", " ->EXEC 3 times\n", " ->EXEC 3 times\n", " ->EXEC 3 times\n" ] } ], "source": [ "hardware_setup.register_program('dnp', dnp_prog)\n", "hardware_setup.arm_program('dnp')\n", "\n", "used_awg.run_current_program()\n", "\n", "print(used_awg._known_programs['dnp'].program.program)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected our pumping pulses are executed 3 times each.\n", "\n", "We can now adjust the repetitions of the pulses by simply using the function `update_parameters`. We need to give `update_parameters` the name of the program we want to change and the values to which we want to set certain parameters. Say, next time we run the program we only want to do one zero pulse but 5 plus pulses instead of 3. Then we can simply do:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "hardware_setup.update_parameters('dnp', dict(n_zero=1, n_plus=5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This changes the program in the AWG and the program memory accordingly such that next time we run the program the AWG will output 3 minus, 1 zero and 5 plus pulses." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "LOOP 1 times:\n", " ->EXEC 3 times\n", " ->EXEC 1 times\n", " ->EXEC 5 times\n" ] } ], "source": [ "used_awg.run_current_program()\n", "\n", "print(used_awg._known_programs['dnp'].program.program)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we can see the AWG now outputs 3 minus pulses, 1 zero pulse and 5 plus pulses as desired." ] } ], "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.4" } }, "nbformat": 4, "nbformat_minor": 1 }