# Combined Parameters

[1]:

import qcodes as qc
import numpy as np

from qcodes.instrument.parameter import ManualParameter
from qcodes.utils.validators import Numbers
from qcodes.loops import Loop


If you want to sweep multiple parameters at once qcodes offers the combine function. You can combine any number of any kind paramter. We’ll use a ManualParameter for this example.

[2]:

p1 = ManualParameter('p1', vals=Numbers(-10, 10))
p2 = ManualParameter('p2', vals=Numbers(-10, 10))
p3 = ManualParameter('p3', vals=Numbers(-10, 10))
p4 = ManualParameter('p4', vals=Numbers(-10, 10))
# set to -1 so we get some data out
p4.set(-1)


## Simple combined parameters

[3]:

combined = qc.combine(p1, p2, p3, name='combined')

sweep_vals = np.array([[1, 1,1], [1, 1,1]])

[4]:

# 2d loop with a inner loop over a combined parameter
loop = Loop(p1.sweep(0,10,1)).loop(combined.sweep(sweep_vals), delay=0.001).each(p4)

[5]:

data = loop.get_data_set(name='testsweep')

[6]:

data = loop.run()

Started at 2022-07-01 15:00:55
DataSet:
location = 'data/2022-07-01/#001_testsweep_15-00-55'
<Type>   | <array_id>   | <array.name> | <array.shape>
Setpoint | p1_set       | p1           | (11,)
Setpoint | combined_set | combined     | (11, 2)
Measured | p4           | p4           | (11, 2)
Measured | p1           | p1           | (11, 2)
Measured | p2           | p2           | (11, 2)
Measured | p3           | p3           | (11, 2)
Finished at 2022-07-01 15:00:55


The combined_set just stores the indices

[7]:

print(data.combined_set)

DataArray[11,2]: combined_set
array([[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.]])


But the acutal set values are saved, but labeled as “measured”

[8]:

data.p3

[8]:

DataArray[11,2]: p3
array([[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.]])


## Combine and aggregate parameters

If an aggregator function is given, the aggregated values are saved instead of the indices.

[9]:

# define an aggregator function that takes as arguments the parameters you whish to aggegate
def linear(x,y,z):
return x+y+z

[10]:

combined = qc.combine(p1, p2, p3, name='combined', label="Sum", unit="a.u", aggregator=linear)

x_vals = np.linspace(1, 2, 2)
y_vals = np.linspace(1, 2, 2)
z_vals = np.linspace(1, 2, 2)

[11]:

# 2d loop with a inner loop over a combined parameter
loop = Loop(p1.sweep(0,10,1)).loop(combined.sweep(x_vals, y_vals, z_vals), delay=0.001).each(p4)

[12]:

data = loop.get_data_set(name='testsweep')

[13]:

data = loop.run()

Started at 2022-07-01 15:00:55
DataSet:
location = 'data/2022-07-01/#002_testsweep_15-00-55'
<Type>   | <array_id>   | <array.name> | <array.shape>
Setpoint | p1_set       | p1           | (11,)
Setpoint | combined_set | combined     | (11, 2)
Measured | p4           | p4           | (11, 2)
Measured | p1           | p1           | (11, 2)
Measured | p2           | p2           | (11, 2)
Measured | p3           | p3           | (11, 2)
Finished at 2022-07-01 15:00:55


the combined_set now stores the aggregated values

[14]:

print(data.combined_set)

DataArray[11,2]: combined_set
array([[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.],
[3., 6.]])

[15]:

# snapshot of the combined parameter
combined.snapshot()

[15]:

OrderedDict([('__class__',
'qcodes.parameters.combined_parameter.CombinedParameter'),
('unit', 'a.u'),
('label', 'Sum'),
('full_name', 'combined'),
('aggregator', '<function linear at 0x7fec1143c9d0>'),
('p1',
{'__class__': 'qcodes.parameters.parameter.ManualParameter',
'full_name': 'p1',
'value': 2.0,
'raw_value': 2.0,
'ts': '2022-07-01 15:00:55',
'post_delay': 0,
'label': 'p1',
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p1',
'inter_delay': 0}),
('p2',
{'__class__': 'qcodes.parameters.parameter.ManualParameter',
'full_name': 'p2',
'value': 2.0,
'raw_value': 2.0,
'ts': '2022-07-01 15:00:55',
'post_delay': 0,
'label': 'p2',
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p2',
'inter_delay': 0}),
('p3',
{'__class__': 'qcodes.parameters.parameter.ManualParameter',
'full_name': 'p3',
'value': 2.0,
'raw_value': 2.0,
'ts': '2022-07-01 15:00:55',
'post_delay': 0,
'label': 'p3',
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p3',
'inter_delay': 0})])

[ ]: