<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Tutorial 1. The Measurement Control
This tutorial covers basic usage of PycQED focusing on running basic experiments using MeasurementControl. 
The MeasurementControl is the main Instrument in charge of running any experiment. It takes care of saving the data in a standardized format as well as live plotting of the data during the experiment. 
PycQED makes a distinction between soft(ware) controlled measurements and hard(ware) controlled measurements. 
In a soft measurement MeasurementControl is in charge of the measurement loop and consecutively sets and gets datapoints. A soft measurement can be 1D, 2D or higher dimensional and also supports adaptive measurements in which the datapoints are determined during the measurement loop. 
In a hard measurement the hardware (such as an AWG or a central controller) is in charge of the measurement loop. In this case, the datapoints to be acquired are determined before the experiment starts and are precompiled into the hardware which is then armed and starts acquisition. In a hard measurement MeasurementControl does not take care of the measurement loop but still takes care of the data storage and live plotting of the experiment. 
import required modules
Step1:  Creating an instance of MeasurementControl
Measurements are controlled through the MeasurementControl usually instantiated as MC
Step2:  The InstrumentMonitor can be used to see the parameters of any instrument connected to the station and updates during the loop initiated by MeasurementControl.
Step3:  Create instruments used in the experiment
Let's start by creating a dummy instrument called MockParabola.
Step4:  A 1D hard measurement
A hard measurement is a measurement where the data acquisition loop happens in the hardware.
Step5:  By setting persist_mode = True we can see a copy of the last measurements
Step6:  A simple 1D soft measurement
A soft measurement is a a measurement where the data acquisition loop occurs in the software
Step7:  You can play around a bit with the options in the MC
Step8:  A simple 2D measurement
Step9:  2D combinatioin of a hard inner and soft outer loop
The hard inner loop returns 30 values
Step10:  A Hard measurement that uses soft averaging
The number of soft_averages determines how many times the experiment will be performed. 
Only the averaged data is plotted and saved. 
The number of soft-averages can be set as a parameter of the Measurement Control. 
Will first implement it for 1D hard sweeps (easier) and then follow for combinations of hard and soft sweeps.
Step11:  2D soft averaging
Step12:  Starting an adaptive measurement
This example does a 2D optimization over the mock parabola
<ASSISTANT_TASK:>
Python Code:
import pycqed as pq
import numpy as np
from pycqed.measurement import measurement_control
from pycqed.measurement.sweep_functions import None_Sweep
import pycqed.measurement.detector_functions as det
from qcodes import station
station = station.Station()
Explanation: Tutorial 1. The Measurement Control
This tutorial covers basic usage of PycQED focusing on running basic experiments using MeasurementControl. 
The MeasurementControl is the main Instrument in charge of running any experiment. It takes care of saving the data in a standardized format as well as live plotting of the data during the experiment. 
PycQED makes a distinction between soft(ware) controlled measurements and hard(ware) controlled measurements. 
In a soft measurement MeasurementControl is in charge of the measurement loop and consecutively sets and gets datapoints. A soft measurement can be 1D, 2D or higher dimensional and also supports adaptive measurements in which the datapoints are determined during the measurement loop. 
In a hard measurement the hardware (such as an AWG or a central controller) is in charge of the measurement loop. In this case, the datapoints to be acquired are determined before the experiment starts and are precompiled into the hardware which is then armed and starts acquisition. In a hard measurement MeasurementControl does not take care of the measurement loop but still takes care of the data storage and live plotting of the experiment. 
import required modules
End of explanation
MC = measurement_control.MeasurementControl('MC',live_plot_enabled=True, verbose=True)
MC.station = station
station.add_component(MC)
Explanation: Creating an instance of MeasurementControl
Measurements are controlled through the MeasurementControl usually instantiated as MC
End of explanation
from pycqed.instrument_drivers.virtual_instruments import instrument_monitor as im 
IM = im.InstrumentMonitor('IM', station)
station.add_component(IM)
# Link the instrument monitor to the MC so that it gets updated in the loop
MC.instrument_monitor('IM')
IM.update()
IM.update_interval(.1)
IM.update()
Explanation: The InstrumentMonitor can be used to see the parameters of any instrument connected to the station and updates during the loop initiated by MeasurementControl.
End of explanation
from pycqed.instrument_drivers.physical_instruments.dummy_instruments import DummyParHolder
dummy_instrument = DummyParHolder('dummy_instrument')
station.add_component(dummy_instrument)
Explanation: Create instruments used in the experiment
Let's start by creating a dummy instrument called MockParabola.
End of explanation
MC.soft_avg(15)
MC.persist_mode(True)
MC.set_sweep_function(None_Sweep(sweep_control='hard'))
MC.set_sweep_points(np.linspace(0, 10, 30))
MC.set_detector_function(det.Dummy_Detector_Hard(noise=0.5, delay=.02))
dat = MC.run('dummy_hard')
data_set = dat['dset']
Explanation: A 1D hard measurement
A hard measurement is a measurement where the data acquisition loop happens in the hardware.
End of explanation
MC.set_sweep_function(None_Sweep(sweep_control='hard'))
MC.set_sweep_points(np.linspace(0, 10, 30))
MC.set_detector_function(det.Dummy_Detector_Hard(noise=0.5, delay=.02))
dat2 = MC.run('dummy_hard persistent')
data_set2 = dat2['dset']
Explanation: By setting persist_mode = True we can see a copy of the last measurements
End of explanation
dummy_instrument.x(145/134545)
IM.update()
dummy_instrument.delay(.01)
MC.soft_avg(15)
MC.set_sweep_function(dummy_instrument.x)
MC.set_sweep_points(np.linspace(-1,1,30))
dummy_instrument.noise(1)
MC.set_detector_function(dummy_instrument.parabola)
dat = MC.run('1D test')
data_set = dat['dset']
# the second plot will also show the first line
MC.set_sweep_function(dummy_instrument.x)
MC.set_sweep_points(np.linspace(-1,1,30))
dat2= MC.run('1D test-persist')
data_set2 = dat2['dset']
dummy_instrument.delay(.01)
MC.soft_avg(15)
MC.set_sweep_function(dummy_instrument.x)
MC.set_sweep_points(np.linspace(-1,1,30))
MC.set_detector_function(det.Dummy_Detector_Soft())
dat = MC.run('1D test')
data_set = dat['dset']
Explanation: A simple 1D soft measurement
A soft measurement is a a measurement where the data acquisition loop occurs in the software
End of explanation
MC.persist_mode(True) # Turns on and off persistent plotting
MC.verbose(True)
MC.plotting_interval(.2)
MC.live_plot_enabled(True)
Explanation: You can play around a bit with the options in the MC:
End of explanation
dummy_instrument.delay(.0001)
MC.soft_avg(4)
sweep_pts = np.linspace(-2, 2, 30)
sweep_pts_2D = np.linspace(-2, 2, 5)
MC.set_sweep_function(dummy_instrument.x)
MC.set_sweep_function_2D(dummy_instrument.y)
MC.set_sweep_points(sweep_pts)
MC.set_sweep_points_2D(sweep_pts_2D)
MC.set_detector_function(dummy_instrument.parabola)
dat=MC.run('test', mode='2D')
data_set = dat['dset']
Explanation: A simple 2D measurement
End of explanation
MC.soft_avg(1)
sweep_pts = np.linspace(0, 10, 30)
sweep_pts_2D = np.linspace(0, 10, 30)
MC.set_sweep_function(None_Sweep(sweep_control='hard'))
MC.set_sweep_function_2D(None_Sweep(sweep_control='soft'))
MC.set_sweep_points(sweep_pts)
MC.set_sweep_points_2D(sweep_pts_2D)
MC.set_detector_function(det.Dummy_Detector_Hard(delay=.05, noise=.1))
dat = MC.run('2D_hard', mode='2D')
data_set = dat['dset']
Explanation: 2D combinatioin of a hard inner and soft outer loop
The hard inner loop returns 30 values
End of explanation
MC.soft_avg(4)
MC.set_sweep_function(None_Sweep(sweep_control='hard'))
MC.set_sweep_points(np.linspace(0, 10, 30))
MC.set_detector_function(det.Dummy_Detector_Hard(noise=1.5, delay=.02))
dat = MC.run('dummy_hard')
data_set = dat['dset']
Explanation: A Hard measurement that uses soft averaging
The number of soft_averages determines how many times the experiment will be performed. 
Only the averaged data is plotted and saved. 
The number of soft-averages can be set as a parameter of the Measurement Control. 
Will first implement it for 1D hard sweeps (easier) and then follow for combinations of hard and soft sweeps.
End of explanation
MC.soft_avg(10)
sweep_pts = np.linspace(0, 10, 30)
sweep_pts_2D = np.linspace(0, 10, 5)
MC.set_sweep_function(None_Sweep(sweep_control='hard'))
MC.set_sweep_function_2D(None_Sweep(sweep_control='soft'))
MC.set_sweep_points(sweep_pts)
MC.set_sweep_points_2D(sweep_pts_2D)
MC.set_detector_function(det.Dummy_Detector_Hard(noise=1.5, delay=.001))
dat = MC.run('dummy_hard_2D', mode='2D')
data_set = dat['dset']
Explanation: 2D soft averaging
End of explanation
dummy_instrument.delay(.05)
dummy_instrument.noise(2)
from pycqed.measurement.optimization import nelder_mead
MC.soft_avg(1)
dummy_instrument
MC.set_sweep_functions([dummy_instrument.x, dummy_instrument.y])
MC.set_adaptive_function_parameters({'adaptive_function':nelder_mead, 
                                    'x0':[-5,-5], 'initial_step': [2.5, 2.5]})
dummy_instrument.noise(2)
MC.set_detector_function(dummy_instrument.parabola)
dat = MC.run('1D test', mode='adaptive')
data_set = dat['dset']
Explanation: Starting an adaptive measurement
This example does a 2D optimization over the mock parabola
End of explanation
<END_TASK>