{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## MultiParameter\n", "Return multiple items at once, where each item can be a single value or an array. \n", "\n", "> Note: Most of the kwarg names here are the plural of those used in `Parameter` and `ArrayParameter`. In particular, `MultiParameter` is the ONLY one that uses `units`, all the others use `unit`.\n", "\n", "`MultiParameter` is, for now, only gettable." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from qcodes.parameters import ManualParameter, MultiParameter" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "simple get: (2, 1.0)\n" ] } ], "source": [ "class SingleIQPair(MultiParameter):\n", " def __init__(self, scale_param):\n", " # only name, names, and shapes are required\n", " # this version returns two scalars (shape = `()`)\n", " super().__init__('single_iq', names=('I', 'Q'), shapes=((), ()),\n", " labels=('In phase amplitude', 'Quadrature amplitude'),\n", " units=('V', 'V'),\n", " # including these setpoints is unnecessary here, but\n", " # if you have a parameter that returns a scalar alongside\n", " # an array you can represent the scalar as an empty sequence.\n", " setpoints=((), ()),\n", " docstring='param that returns two single values, I and Q')\n", " self._scale_param = scale_param\n", "\n", " def get_raw(self):\n", " scale_val = self._scale_param()\n", " return (scale_val, scale_val / 2)\n", "\n", "\n", "scale = ManualParameter('scale', initial_value=2)\n", "iq = SingleIQPair(scale_param=scale)\n", "\n", "# simple get\n", "print('simple get:', iq())" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "simple get (array([0, 2, 4, 6, 8]), array([0., 1., 2., 3., 4.]))\n" ] } ], "source": [ "class IQArray(MultiParameter):\n", " def __init__(self, scale_param):\n", " # names, labels, and units are the same\n", " super().__init__('iq_array', names=('I', 'Q'), shapes=((5,), (5,)),\n", " labels=('In phase amplitude', 'Quadrature amplitude'),\n", " units=('V', 'V'),\n", " # note that EACH item needs a sequence of setpoint arrays\n", " # so a 1D item has its setpoints wrapped in a length-1 tuple\n", " setpoints=(((0, 1, 2, 3, 4),), ((0, 1, 2, 3, 4),)),\n", " docstring='param that returns two single values, I and Q')\n", " self._scale_param = scale_param\n", " self._indices = np.array([0, 1, 2, 3, 4])\n", "\n", " def get_raw(self):\n", " scale_val = self._scale_param()\n", " return (self._indices * scale_val, self._indices * scale_val / 2)\n", "\n", "\n", "iq_array = IQArray(scale_param=scale)\n", "\n", "# simple get\n", "print('simple get', iq_array())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.0" } }, "nbformat": 4, "nbformat_minor": 4 }