{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Abstract Pulse Template\n", "This pulse template can be used as a place holder for a pulse template with a defined interface. Pulse template properties like `defined_channels` can be passed on initialization to declare those properties who make up the interface. Omitted properties raise an `NotSpecifiedError` exception if accessed. Properties which have been accessed are marked as \"frozen\".\n", "The abstract pulse template can be linked to another pulse template by calling the `link_to` member. The target has to have the same properties for all properties marked as \"frozen\". This ensures a property always returns the same value." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "scrolled": true }, "outputs": [], "source": [ "from qupulse.pulses import AbstractPT, FunctionPT, AtomicMultiChannelPT, PointPT\n", "\n", "init = PointPT([(0, (1, 0)), ('t_init', (0, 1), 'linear')], ['X', 'Y'])\n", "abstract_readout = AbstractPT('readout', defined_channels={'X', 'Y'}, integral={'X': 1, 'Y': 'a*b'})\n", "manip = AtomicMultiChannelPT(FunctionPT('sin(t)', 't_manip', channel='X'),\n", " FunctionPT('cos(t)', 't_manip', channel='Y'))\n", "\n", "experiment = init @ manip @ abstract_readout" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can access declared properties like integral. If we try to get a non-declared property an exception is raised." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The integral has been declared so we can get it\n", "{'Y': Expression('a*b + sin(t_manip)'), 'X': Expression('t_init - cos(t_manip) + 2')}\n", "\n", "We get an error that for the pulse \"readout\" the property \"duration\" was not specified:\n", "NotSpecifiedError('readout', 'duration')\n" ] } ], "source": [ "print('The integral has been declared so we can get it')\n", "print(experiment.integral)\n", "print()\n", "\n", "import traceback\n", "try:\n", " experiment.duration\n", "except Exception as err:\n", " print('We get an error that for the pulse \"readout\" the property \"duration\" was not specified:')\n", " print(repr(err))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can link the abstract pulse template to an actual pulse template. By accessing the integral property above we froze it. Linking a pulse with a different property will result in an error." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "With wrong integral value:\n", "RuntimeError('Cannot link to target. Wrong value of property \"integral\"')\n", "the linking worked. The new experiment has now a defined duration of Expression('t_init + t_manip + t_read') .\n" ] } ], "source": [ "my_readout_wrong_integral = AtomicMultiChannelPT(FunctionPT('1', 't_read', channel='X'),\n", " FunctionPT('a*b', 't_read', channel='Y'))\n", "\n", "my_readout = AtomicMultiChannelPT(FunctionPT('1 / t_read', 't_read', channel='X'),\n", " FunctionPT('a*b / t_read', 't_read', channel='Y'))\n", "\n", "try:\n", " print('With wrong integral value:')\n", " abstract_readout.link_to(my_readout_wrong_integral)\n", "except Exception as err:\n", " print(repr(err))\n", "\n", "abstract_readout.link_to(my_readout)\n", "print('the linking worked. The new experiment has now a defined duration of', repr(experiment.duration), '.')" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 1 }