Skip to content

Commit

Permalink
working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Aypac committed Apr 14, 2018
1 parent 36c92db commit d01e6d3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pycqed/analysis/measurement_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8974,7 +8974,8 @@ def DAC_scan_analysis_and_plot(scan_start, scan_stop, dac, feed, dac_prefix='',p
# Qis[i] = a.fit_results.params['Qi']
# except:
# pass
peaks_x, peaks_z,smoothed_z=a_tools.peak_finder_v3(frequency_values[i], amplitude_values[i], smoothing=smoothing, perc=perc, window_len=smooth_window_len,factor=factor)
peaks_x, peaks_z,smoothed_z=a_tools.peak_finder_v3(frequency_values[i], amplitude_values[i], smoothing=smoothing,
perc=perc, window_len=smooth_window_len,factor=factor)
#save peaks and smoothed data
smoothed_amplitude_values[i,:] = smoothed_z
peak_frequencies[i] = peaks_x
Expand Down
71 changes: 51 additions & 20 deletions pycqed/analysis_v2/dac_scan_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
from pycqed.analysis_v2.base_analysis import plot_scatter_errorbar_fit, plot_scatter_errorbar


class BasicDACvsFrequency(ba.BaseDataAnalysis):
class FluxFrequency(ba.BaseDataAnalysis):

def __init__(self, t_start: str = None, t_stop: str = None,
label: str = '',
auto: bool = True,
data_file_path: str = None,
close_figs: bool = True,
options_dict: dict = None, extract_only: bool = False,
do_fitting: bool = False):
do_fitting: bool = False,
is_spectroscopy: bool = True,
extract_fitparams: bool = True):
super().__init__(t_start=t_start, t_stop=t_stop,
label=label,
data_file_path=data_file_path,
Expand All @@ -34,10 +36,16 @@ def __init__(self, t_start: str = None, t_stop: str = None,
}
self.numeric_params = ['freq', 'amp', 'phase', 'dac']

self.extract_fitparams = self.options_dict.get('fitparams', True)
if self.extract_fitparams:
p = self.options_dict.get('fitparams_key', 'Fitted Params distance.f0.value')
self.params_dict.update({'fitparams': p})
self.is_spectroscopy = is_spectroscopy
self.extract_fitparams = extract_fitparams
if extract_fitparams:
if is_spectroscopy:
default_key = 'Fitted Params distance.f0.value'
else:
default_key = 'Fitted Params HM.f0.value'

p = self.options_dict.get('fitparams_key', default_key)
self.params_dict['fitparams'] = p
self.numeric_params.append('fitparams')

temp_keys = self.options_dict.get('temp_keys', {})
Expand Down Expand Up @@ -67,8 +75,9 @@ def process_data(self):
data_real=compl.real, data_imag=compl.imag, percentile=70, normalize=True)

if self.extract_fitparams:
self.proc_data_dict['fit_frequencies'] = np.array(self.raw_data_dict['fitparams'][sorted_indices],
dtype=float)
self.proc_data_dict['fit_frequencies'] = self.raw_data_dict['fitparams'][
sorted_indices] * self.options_dict.get('fitparams_corr_fact',
1)

if self.temperature_plots:
self.proc_data_dict['T_mc'] = np.array(self.raw_data_dict['T_mc'][sorted_indices], dtype=float)
Expand Down Expand Up @@ -100,8 +109,14 @@ def process_data(self):

def run_fitting(self):
self.fit_dicts = {}
fit_result = fit_qubit_dac_arch(freq=self.proc_data_dict['fit_frequencies'],
dac=self.proc_data_dict['dac_values'])
if self.is_spectroscopy:
default_fitfunc = fit_qubit_dac_arch
else:
default_fitfunc = fit_resonator_dac_arch

fitfunc = self.options_dict.get('fitfunc', default_fitfunc)
fit_result = fitfunc(freq=self.proc_data_dict['fit_frequencies'], dac=self.proc_data_dict['dac_values'])

self.fit_dicts['fit_result'] = fit_result
# self.fit_dicts['E_c'] = fit_result.params['E_c']
# self.fit_dicts['f_max'] = fit_result.params['f_max']
Expand All @@ -110,7 +125,6 @@ def run_fitting(self):
# self.fit_dicts['asymmetry'] = fit_result.params['asymmetry']

def prepare_plots(self):
fit_result = self.fit_dicts['fit_result']
if self.options_dict.get('plot_vs_flux', False):
factor = fit_result.params['V_per_phi0']
else:
Expand All @@ -135,7 +149,16 @@ def prepare_plots(self):
'plot_transpose': self.options_dict.get('plot_transpose', False),
}

scatter = {
'plotfn': self.plot_line,
'xvals': self.proc_data_dict['dac_values'],
'yvals': self.proc_data_dict['fit_frequencies'],
'marker': 'x',
'linestyle': 'None',
}

if self.do_fitting:
fit_result = self.fit_dicts['fit_result']
fit = {
'plotfn': self.plot_fit,
'fit_res': fit_result,
Expand All @@ -145,20 +168,13 @@ def prepare_plots(self):
'linestyle': '-',
}

scatter = {
'plotfn': self.plot_line,
'xvals': self.proc_data_dict['dac_values'],
'yvals': self.proc_data_dict['fit_frequencies'],
'marker': 'x',
'linestyle': 'None',
}

for ax in ['amplitude', 'phase', 'distance']:
z = self.proc_data_dict['%s_values' % ax]
td = deepcopy(twoDPlot)
td['zvals'] = z
td['zlabel'] = ax
self.plot_dicts[ax] = td
td['ax_id'] = ax
self.plot_dicts[ax + '_z'] = td

sc = deepcopy(scatter)
sc['ax_id'] = ax
Expand All @@ -182,3 +198,18 @@ def fit_qubit_dac_arch(freq, dac):

fit_result = arch_model.fit(freq, dac_voltage=dac)
return fit_result


def fit_resonator_dac_arch(freq, dac):
# fixme!!!!
arch_model = lmfit.Model(Qubit_dac_to_freq)
arch_model.set_param_hint('E_c', value=260e6, min=100e6, max=350e6)
arch_model.set_param_hint('f_max', value=5e9, min=0.1e9, max=10e9)
arch_model.set_param_hint('dac_sweet_spot', value=0, min=-0.5, max=0.5)
arch_model.set_param_hint('V_per_phi0', value=0.1, min=0)
arch_model.set_param_hint('asymmetry', value=0)

arch_model.make_params()

fit_result = arch_model.fit(freq, dac_voltage=dac)
return fit_result
2 changes: 1 addition & 1 deletion pycqed/analysis_v2/measurement_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@

from pycqed.analysis_v2.coherence_analysis import CoherenceTimesAnalysis, CoherenceTimesAnalysisSingle
from pycqed.analysis_v2.spectroscopy_analysis import Spectroscopy, ResonatorSpectroscopy, VNA_analysis, complex_spectroscopy
from pycqed.analysis_v2.dac_scan_analysis import BasicDACvsFrequency
from pycqed.analysis_v2.dac_scan_analysis import FluxFrequency
16 changes: 8 additions & 8 deletions pycqed/analysis_v2/spectroscopy_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def prepare_plots(self):
'plotsize': plotsize
}
else:
self.plot_dicts['amp'] = {'plotfn': self.plot_colorx ,
self.plot_dicts['amp'] = {'plotfn': self.plot_colorx,
'xvals': proc_data_dict['plot_xvals'],
'xwidth': proc_data_dict['plot_xwidth'],
'yvals': proc_data_dict['plot_frequency'],
Expand All @@ -155,7 +155,7 @@ def prepare_plots(self):
'plotcbar': self.options_dict.get('colorbar', False),
}

self.plot_dicts['amp'] = {'plotfn': self.plot_colorx ,
self.plot_dicts['amp'] = {'plotfn': self.plot_colorx,
'xvals': proc_data_dict['plot_xvals'],
'yvals': proc_data_dict['plot_frequency'],
'zvals': proc_data_dict['plot_amp'],
Expand Down Expand Up @@ -526,12 +526,12 @@ def plot_fitting(self):
ax.plot(list(fit_dict['fit_xvals'].values())[
0], fit_results.best_fit, 'r-', linewidth=1.5)
textstr = 'f0 = %.5f $\pm$ %.1g GHz' % (
fit_results.params['f0'].value, fit_results.params['f0'].stderr) + '\n' \
'Q = %.4g $\pm$ %.0g' % (
fit_results.params['Q'].value, fit_results.params['Q'].stderr) + '\n' \
'Qc = %.4g $\pm$ %.0g' % (
fit_results.params['Qc'].value, fit_results.params['Qc'].stderr) + '\n' \
'Qi = %.4g $\pm$ %.0g' % (
fit_results.params['f0'].value, fit_results.params['f0'].stderr) + '\n' \
'Q = %.4g $\pm$ %.0g' % (
fit_results.params['Q'].value, fit_results.params['Q'].stderr) + '\n' \
'Qc = %.4g $\pm$ %.0g' % (
fit_results.params['Qc'].value, fit_results.params['Qc'].stderr) + '\n' \
'Qi = %.4g $\pm$ %.0g' % (
fit_results.params['Qi'].value, fit_results.params['Qi'].stderr)
box_props = dict(boxstyle='Square',
facecolor='white', alpha=0.8)
Expand Down

0 comments on commit d01e6d3

Please sign in to comment.