This page was generated from
docs/examples/Parameters/MultiParameter.ipynb.
Interactive online version:
.
MultiParameterΒΆ
Return multiple items at once, where each item can be a single value or an array.
Note: Most of the kwarg names here are the plural of those used in
ParameterandArrayParameter. In particular,MultiParameteris the ONLY one that usesunits, all the others useunit.
MultiParameter is, for now, only gettable.
[1]:
import numpy as np
from qcodes.parameters import ManualParameter, MultiParameter
[2]:
class SingleIQPair(MultiParameter):
def __init__(self, scale_param):
# only name, names, and shapes are required
# this version returns two scalars (shape = `()`)
super().__init__(
"single_iq",
names=("I", "Q"),
shapes=((), ()),
labels=("In phase amplitude", "Quadrature amplitude"),
units=("V", "V"),
# including these setpoints is unnecessary here, but
# if you have a parameter that returns a scalar alongside
# an array you can represent the scalar as an empty sequence.
setpoints=((), ()),
docstring="param that returns two single values, I and Q",
)
self._scale_param = scale_param
def get_raw(self):
scale_val = self._scale_param()
return (scale_val, scale_val / 2)
scale = ManualParameter("scale", initial_value=2)
iq = SingleIQPair(scale_param=scale)
# simple get
print("simple get:", iq())
simple get: (2, 1.0)
[3]:
class IQArray(MultiParameter):
def __init__(self, scale_param):
# names, labels, and units are the same
super().__init__(
"iq_array",
names=("I", "Q"),
shapes=((5,), (5,)),
labels=("In phase amplitude", "Quadrature amplitude"),
units=("V", "V"),
# note that EACH item needs a sequence of setpoint arrays
# so a 1D item has its setpoints wrapped in a length-1 tuple
setpoints=(((0, 1, 2, 3, 4),), ((0, 1, 2, 3, 4),)),
docstring="param that returns two single values, I and Q",
)
self._scale_param = scale_param
self._indices = np.array([0, 1, 2, 3, 4])
def get_raw(self):
scale_val = self._scale_param()
return (self._indices * scale_val, self._indices * scale_val / 2)
iq_array = IQArray(scale_param=scale)
# simple get
print("simple get", iq_array())
simple get (array([0, 2, 4, 6, 8]), array([0., 1., 2., 3., 4.]))