Combined Parameters¶
[1]:
import numpy as np
import qcodes as qc
from qcodes.parameters import ManualParameter, combine
from qcodes.validators import Numbers
from qcodes_loop.loops import Loop
Logging hadn't been started.
Activating auto-logging. Current session state plus future input saved.
Filename : C:\Users\a-halakh\.qcodes\logs\command_history.log
Mode : append
Output logging : True
Raw input log : False
Timestamping : True
State : active
Qcodes Logfile : C:\Users\a-halakh\.qcodes\logs\200324-28996-qcodes.log
False
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 = 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 2020-03-24 18:35:07
DataSet:
location = 'data/2020-03-24/#004_testsweep_18-35-07'
<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 2020-03-24 18:35:07
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 = 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 2020-03-24 18:35:07
DataSet:
location = 'data/2020-03-24/#005_testsweep_18-35-07'
<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 2020-03-24 18:35:07
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.instrument.parameter.CombinedParameter'),
('unit', 'a.u'),
('label', 'Sum'),
('full_name', 'combined'),
('aggregator', '<function linear at 0x0000024683100828>'),
('p1',
{'value': 2.0,
'raw_value': 2.0,
'ts': '2020-03-24 18:35:07',
'__class__': 'qcodes.instrument.parameter.ManualParameter',
'full_name': 'p1',
'post_delay': 0,
'label': 'p1',
'inter_delay': 0,
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p1'}),
('p2',
{'value': 2.0,
'raw_value': 2.0,
'ts': '2020-03-24 18:35:07',
'__class__': 'qcodes.instrument.parameter.ManualParameter',
'full_name': 'p2',
'post_delay': 0,
'label': 'p2',
'inter_delay': 0,
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p2'}),
('p3',
{'value': 2.0,
'raw_value': 2.0,
'ts': '2020-03-24 18:35:07',
'__class__': 'qcodes.instrument.parameter.ManualParameter',
'full_name': 'p3',
'post_delay': 0,
'label': 'p3',
'inter_delay': 0,
'vals': '<Numbers -10<=v<=10>',
'unit': '',
'name': 'p3'})])
[ ]: