Skip to content

Commit

Permalink
Merge pull request #131 from DiCarloLab-Delft/plotting_enhancements
Browse files Browse the repository at this point in the history
Been using this for a while, merging as it works fine.
  • Loading branch information
AdriaanRol authored Mar 20, 2017
2 parents 80034a2 + 51946e2 commit 8f629af
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 56 deletions.
104 changes: 71 additions & 33 deletions examples/Setting up a basic measurement using the MC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"Starting measurement: dummy_hard\n",
"Sweep function: None_Sweep\n",
"Detector function: Dummy_Detector\n",
" 100% completed \telapsed time: 1.3s \ttime left: 0.0s\n"
" 100% completed \telapsed time: 1.2s \ttime left: 0.0s\n"
]
}
],
Expand Down Expand Up @@ -147,11 +147,15 @@
"Starting measurement: dummy_hard persistent\n",
"Sweep function: None_Sweep\n",
"Detector function: Dummy_Detector\n",
" 100% completed \telapsed time: 1.7s \ttime left: 0.0s\n"
" 100% completed \telapsed time: 1.8s \ttime left: 0.0s\n"
]
}
],
"source": [
"\n",
"MC.set_sweep_function(None_Sweep(sweep_control='hard'))\n",
"MC.set_sweep_points(np.linspace(0, 10, 30))\n",
"MC.set_detector_function(det.Dummy_Detector_Hard(noise=0.5, delay=.02))\n",
"dat2 = MC.run('dummy_hard persistent')"
]
},
Expand All @@ -177,11 +181,11 @@
"Starting measurement: 1D test\n",
"Sweep function: x\n",
"Detector function: parabola\n",
" 100% completed \telapsed time: 6.9s \ttime left: 0.0s\n",
" 100% completed \telapsed time: 6.5s \ttime left: 0.0s\n",
"Starting measurement: 1D test-persist\n",
"Sweep function: x\n",
"Detector function: parabola\n",
" 100% completed \telapsed time: 8.2s \ttime left: 0.0s\n"
" 100% completed \telapsed time: 7.2s \ttime left: 0.0s\n"
]
}
],
Expand All @@ -196,6 +200,9 @@
"dat = MC.run('1D test')\n",
"\n",
"# the second plot will also show the first line\n",
"MC.set_sweep_function(dummy_instrument.x)\n",
"MC.set_sweep_points(np.linspace(-1,1,30))\n",
"\n",
"dat2= MC.run('1D test-persist')"
]
},
Expand All @@ -208,7 +215,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"collapsed": true
},
Expand All @@ -229,7 +236,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"collapsed": false
},
Expand All @@ -241,7 +248,8 @@
"Starting measurement: test\n",
"Sweep function 0: x\n",
"Sweep function 1: Sweep_function\n",
"Detector function: parabola\n"
"Detector function: parabola\n",
" 100% completed \telapsed time: 5.0s \ttime left: 0.0ss\n"
]
}
],
Expand Down Expand Up @@ -270,11 +278,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting measurement: 2D_hard\n",
"Sweep function 0: None_Sweep\n",
"Sweep function 1: None_Sweep\n",
"Detector function: Dummy_Detector\n",
" 100% completed \telapsed time: 14.0s \ttime left: 0.0s\n"
]
}
],
"source": [
"MC.soft_avg(1)\n",
"sweep_pts = np.linspace(0, 10, 30)\n",
Expand Down Expand Up @@ -307,11 +327,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting measurement: dummy_hard\n",
"Sweep function: None_Sweep\n",
"Detector function: Dummy_Detector\n",
" 100% completed \telapsed time: 1.1s \ttime left: 0.0s\n"
]
}
],
"source": [
"MC.soft_avg(4)\n",
"MC.set_sweep_function(None_Sweep(sweep_control='hard'))\n",
Expand All @@ -330,11 +361,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting measurement: dummy_hard_2D\n",
"Sweep function 0: None_Sweep\n",
"Sweep function 1: None_Sweep\n",
"Detector function: Dummy_Detector\n",
" 100% completed \telapsed time: 16.7s \ttime left: 0.0s\n"
]
}
],
"source": [
"MC.soft_avg(10)\n",
"sweep_pts = np.linspace(0, 10, 30)\n",
Expand All @@ -359,11 +402,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Starting measurement: 1D test\n",
"Sweep function 0: module\n",
"Sweep function 1: module\n",
"Detector function: parabola\n",
"Optimization completed in 1.564s\n"
]
}
],
"source": [
"from pycqed.measurement.optimization import nelder_mead\n",
"MC.soft_avg(1)\n",
Expand Down Expand Up @@ -402,24 +457,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
},
"widgets": {
"state": {
"44b04146583d411ebdb370fc77dee9bd": {
"views": []
},
"58176991bf4e4018988ec82641bf54ed": {
"views": []
},
"a7d1ae0e766940e38dc294b39e0d9736": {
"views": []
},
"bebdcf0477504d95ae28f5c134512877": {
"views": []
}
},
"version": "1.1.1"
"version": "3.6.0"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def __init__(self, name, **kw):

# Instrument parameters
for parname in ['x', 'y', 'z']:
self.add_parameter(parname, unit='a.u.',
self.add_parameter(parname, unit='m',
parameter_class=ManualParameter,
vals=vals.Numbers(), initial_value=0)

self.add_parameter('noise', unit='a.u.',
self.add_parameter('noise', unit='V',
label='white noise amplitude',
parameter_class=ManualParameter,
vals=vals.Numbers(), initial_value=0)
Expand All @@ -34,11 +34,13 @@ def __init__(self, name, **kw):
parameter_class=ManualParameter,
vals=vals.Numbers(), initial_value=0)

self.add_parameter('parabola', unit='a.u.',
self.add_parameter('parabola', unit='V',
get_cmd=self._measure_parabola)
self.add_parameter('skewed_parabola', unit='a.u.',
self.add_parameter('skewed_parabola', unit='V',
get_cmd=self._measure_skewwed_parabola)

def get_idn(self):
return 'dummy'
def _measure_parabola(self):
time.sleep(self.delay())
return (self.x()**2 + self.y()**2 + self.z()**2 +
Expand Down
2 changes: 1 addition & 1 deletion pycqed/measurement/detector_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(self, delay=0, noise=0, **kw):
self.detector_control = 'hard'
self.name = 'Dummy_Detector'
self.value_names = ['distance', 'Power']
self.value_units = ['m', 'nW']
self.value_units = ['m', 'W']
self.delay = delay
self.noise = noise
self.times_called = 0
Expand Down
10 changes: 5 additions & 5 deletions pycqed/measurement/mc_parameter_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def wrap_par_to_swf(parameter):
sweep_function.sweep_control = 'soft'
sweep_function.name = parameter.name
sweep_function.parameter_name = parameter.label
sweep_function.unit = parameter.units
sweep_function.unit = parameter.unit

sweep_function.prepare = pass_function
sweep_function.finish = pass_function
Expand All @@ -30,7 +30,7 @@ def wrap_pars_to_swf(parameters):
sweep_function.sweep_control = 'soft'
sweep_function.name = parameters[0].name
sweep_function.parameter_name = parameters[0].label
sweep_function.unit = parameters[0].units
sweep_function.unit = parameters[0].unit

sweep_function.prepare = pass_function
sweep_function.finish = pass_function
Expand All @@ -56,7 +56,7 @@ def wrap_par_to_det(parameter, control='soft'):
detector_function.detector_control = control
detector_function.name = parameter.name
detector_function.value_names = [parameter.label]
detector_function.value_units = [parameter.units]
detector_function.value_units = [parameter.unit]

detector_function.prepare = pass_function
detector_function.finish = pass_function
Expand Down Expand Up @@ -85,7 +85,7 @@ def wrapped_func():
return detector_function

def wrap_par_remainder(par, remainder=1):
new_par = qc.Parameter(name=par.name, label=par.label, unit=par.units)
new_par = qc.Parameter(name=par.name, label=par.label, unit=par.unit)
def wrap_set(val):
val = val % remainder
par.set(val)
Expand All @@ -94,7 +94,7 @@ def wrap_set(val):
return new_par

def wrap_par_set_get(par):
new_par = qc.Parameter(name=par.name, label=par.label, unit=par.units)
new_par = qc.Parameter(name=par.name, label=par.label, unit=par.unit)
def wrap_set(val):
par.set(val)
par.get()
Expand Down
43 changes: 30 additions & 13 deletions pycqed/measurement/measurement_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def __init__(self, name,
# pyqtgraph plotting process is reused for different measurements.
if self.live_plot_enabled():
self.main_QtPlot = QtPlot(
windowTitle='Main plotmon of {}'.format(self.name),
window_title='Main plotmon of {}'.format(self.name),
figsize=(600, 400))
self.secondary_QtPlot = QtPlot(
windowTitle='Secondary plotmon of {}'.format(self.name),
window_title='Secondary plotmon of {}'.format(self.name),
figsize=(600, 400))

self.soft_iteration = 0 # used as a counter for soft_avg
Expand Down Expand Up @@ -390,10 +390,8 @@ def finish(self, result):
'''
# this data can be plotted by enabling persist_mode
self._persist_dat = result
self._persist_xlabs = self.column_names[
0:len(self.sweep_function_names)]
self._persist_ylabs = self.column_names[
len(self.sweep_function_names):]
self._persist_xlabs = self.sweep_par_names
self._persist_ylabs = self.detector_function.value_names

for attr in ['TwoD_array',
'dset',
Expand Down Expand Up @@ -476,8 +474,11 @@ def initialize_plot_monitor(self):
if self.main_QtPlot.traces != []:
self.main_QtPlot.clear()
self.curves = []
xlabels = self.column_names[0:len(self.sweep_function_names)]
ylabels = self.column_names[len(self.sweep_function_names):]
xlabels= self.sweep_par_names
xunits = self.sweep_par_units
ylabels = self.detector_function.value_names
yunits = self.detector_function.value_units

j = 0
if (self._persist_ylabs == ylabels and
self._persist_xlabs == xlabels) and self.persist_mode():
Expand All @@ -496,7 +497,10 @@ def initialize_plot_monitor(self):
color=0.75, # a grayscale value
symbol='o', symbolSize=5)
self.main_QtPlot.add(x=[0], y=[0],
xlabel=xlab, ylabel=ylab,
xlabel=xlab,
xunit=xunits[xi],
ylabel=ylab,
yunit=yunits[yi],
subplot=j+1,
color=color_cycle[j%len(color_cycle)],
symbol='o', symbolSize=5)
Expand Down Expand Up @@ -545,13 +549,18 @@ def initialize_plot_monitor_2D(self):
[n, m, len(self.detector_function.value_names)])
self.TwoD_array[:] = np.NAN
self.secondary_QtPlot.clear()
slabels= self.sweep_par_names
sunits = self.sweep_par_units
zlabels = self.detector_function.value_names
zunits = self.detector_function.value_units

for j in range(len(self.detector_function.value_names)):
self.secondary_QtPlot.add(x=self.sweep_pts_x,
y=self.sweep_pts_y,
z=self.TwoD_array[:, :, j],
xlabel=self.column_names[0],
ylabel=self.column_names[1],
zlabel=self.column_names[2+j],
xlabel=slabels[0], xunit=sunits[0],
ylabel=sunits[1], yunit=sunits[1],
zlabel=zlabels[j], zunit=zunits[j],
subplot=j+1,
cmap='viridis')

Expand Down Expand Up @@ -580,11 +589,18 @@ def initialize_plot_monitor_adaptive(self):
'''
self.time_last_ad_plot_update = time.time()
self.secondary_QtPlot.clear()

slabels= self.sweep_par_names
sunits = self.sweep_par_units
zlabels = self.detector_function.value_names
zunits = self.detector_function.value_units

for j in range(len(self.detector_function.value_names)):
self.secondary_QtPlot.add(x=[0],
y=[0],
xlabel='iteration',
ylabel=self.detector_function.value_names[j],
ylabel=zlabels[j],
yunit=zunits[j],
subplot=j+1,
symbol='o', symbolSize=5)

Expand Down Expand Up @@ -655,6 +671,7 @@ def get_column_names(self):
for sweep_function in self.sweep_functions:
self.column_names.append(sweep_function.parameter_name+' (' +
sweep_function.unit+')')

self.sweep_par_names.append(sweep_function.parameter_name)
self.sweep_par_units.append(sweep_function.unit)

Expand Down

0 comments on commit 8f629af

Please sign in to comment.