Skip to content

Commit

Permalink
Revert "Merge branch 'develop_awgv1_devices' of https://github.com/Di…
Browse files Browse the repository at this point in the history
…CarloLab-Delft/PycQED_py3 into develop_awgv1_devices"

This reverts commit 066b3c3, reversing
changes made to 31ee0be.
  • Loading branch information
Yves Salathe committed Aug 21, 2018
1 parent 066b3c3 commit ffe4d87
Show file tree
Hide file tree
Showing 84 changed files with 513 additions and 951 deletions.
312 changes: 261 additions & 51 deletions examples/Setting up a basic measurement using the MC.ipynb

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions pycqed/analysis/analysis_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,19 +1950,22 @@ def plot_errorbars(x, y, ax=None, linewidth=2 ,markersize=2, marker='none'):


def calculate_transmon_transitions(EC, EJ, asym=0, reduced_flux=0,
no_transitions=2, dim=None, ng=0):
no_transitions=2, dim=None):
'''
Calculates transmon energy levels from the full transmon qubit Hamiltonian.
'''
if dim is None:
dim = no_transitions*20

EJphi = EJ*np.sqrt(asym**2 + (1-asym**2)*np.cos(np.pi*reduced_flux)**2)
Ham = 4*EC*np.diag(np.arange(-dim-ng, dim-ng+1)**2) - EJphi/2 * \

Ham = 4*EC*np.diag(np.arange(-dim, dim+1)**2) - EJphi/2 * \
(np.eye(2*dim+1, k=+1) + np.eye(2*dim+1, k=-1))
HamEigs = np.linalg.eigvalsh(Ham)
HamEigs.sort()

transitions = HamEigs[1:]-HamEigs[:-1]

return transitions[:no_transitions]


Expand Down
2 changes: 1 addition & 1 deletion pycqed/analysis/decoupling/decoupling_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def extract_data(self):

# extracts the data
for i, q_label in enumerate(self.qubit_scan_labels):
opt_dict = {'scan_label': '_spectroscopy_'+q_label,
opt_dict = {'scan_label': '__qubit_'+q_label,
'exact_label_match':True}

self.spec_scans[i] = RA.quick_analysis(t_start=self.scan_start,
Expand Down
170 changes: 32 additions & 138 deletions pycqed/analysis/fitting_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from scipy.special import erfc
import lmfit
import logging
from pycqed.analysis import analysis_toolbox as a_tools
from pycqed.analysis.tools import data_manipulation as dm_tools


#################################
Expand Down Expand Up @@ -312,10 +310,33 @@ def HangerFuncAmplitude(f, f0, Q, Qe, A, theta):
return abs(A * (1. - Q / Qe * np.exp(1.j * theta) / (1. + 2.j * Q * (f / 1.e9 - f0) / f0)))


def HangerFuncComplex(f, pars):
'''
This is the complex function for a hanger which DOES NOT
take into account a possible slope
Input:
f = frequency
pars = parameters dictionary
f0, Q, Qe, A, theta, phi_v, phi_0
def hanger_func_complex_SI(f, f0, Q, Qe,
A, theta, phi_v, phi_0,
slope =1):
Author: Stefano Poletto
'''
f0 = pars['f0']
Q = pars['Q']
Qe = pars['Qe']
A = pars['A']
theta = pars['theta']
phi_v = pars['phi_v']
phi_0 = pars['phi_0']

S21 = A * (1 - Q / Qe * np.exp(1j * theta) / (1 + 2.j * Q * (f / 1.e9 - f0) / f0)) * \
np.exp(1j * (phi_v * f + phi_0))

return S21

def hanger_func_complex_SI(f: float, f0: float, Ql: float, Qe: float,
A: float, theta: float, phi_v: float, phi_0: float,
alpha:float =1):
'''
This is the complex function for a hanger (lamda/4 resonator).
See equation 3.1 of the Asaad master thesis.
Expand All @@ -328,42 +349,22 @@ def hanger_func_complex_SI(f, f0, Q, Qe,
f : frequency
f0 : resonance frequency
A : background transmission amplitude
Q : loaded quality factor
Ql : loaded quality factor
Qe : extrinsic quality factor
theta: phase of Qe (in rad)
phi_v: phase to account for propagation delay to sample
phi_0: phase to account for propagation delay from sample
slope: slope of signal around the resonance
The complex hanger function that has a list of parameters as input
is now called hanger_func_complex_SI_pars
alpha: slope of signal around the resonance
'''
slope_corr = (1+slope*(f-f0)/f0)
slope_corr = (1+alpha*(f-f0)/f0)
propagation_delay_corr = np.exp(1j * (phi_v * f + phi_0))
hanger_contribution = (1 - Q / Qe * np.exp(1j * theta)/
(1 + 2.j * Q * (f - f0) / f0))
hanger_contribution = (1 - Ql / Qe * np.exp(1j * theta)/
(1 + 2.j * Ql * (f - f0) / f0))
S21 = A * slope_corr * hanger_contribution * propagation_delay_corr

return S21

def hanger_func_complex_SI_pars(f,pars):
'''
This function is used in the minimization fitting which requires parameters.
It calls the function hanger_func_complex_SI, see there for details.
'''

f0 = pars['f0']
Ql = pars['Ql']
Qe = pars['Qe']
A = pars['A']
theta = pars['theta']
phi_v = pars['phi_v']
phi_0 = pars['phi_0']
alpha = pars['alpha']
return hanger_func_complex_SI(f, f0, Ql, Qe,
A, theta, phi_v, phi_0, alpha)



def PolyBgHangerFuncAmplitude(f, f0, Q, Qe, A, theta, poly_coeffs):
Expand All @@ -374,7 +375,6 @@ def PolyBgHangerFuncAmplitude(f, f0, Q, Qe, A, theta, poly_coeffs):
HangerFuncAmplitude(f, f0, Q, Qe, A, theta))



def SlopedHangerFuncAmplitude(f, f0, Q, Qe, A, theta, slope):
# This is the function for a hanger (lambda/4 resonator) which takes into
# account a possible slope df
Expand Down Expand Up @@ -594,112 +594,6 @@ def exp_dec_guess(model, data, t):
return params



def SlopedHangerFuncAmplitudeGuess(data, f, fit_window=None):
xvals = f
peaks = a_tools.peak_finder(xvals, data)
# Search for peak
if peaks['dip'] is not None: # look for dips first
f0 = peaks['dip']
amplitude_factor = -1.
elif peaks['peak'] is not None: # then look for peaks
f0 = peaks['peak']
amplitude_factor = 1.
else: # Otherwise take center of range
f0 = np.median(xvals)
amplitude_factor = -1.

min_index = np.argmin(data)
max_index = np.argmax(data)
min_frequency = xvals[min_index]
max_frequency = xvals[max_index]

amplitude_guess = max(dm_tools.reject_outliers(data))

# Creating parameters and estimations
S21min = (min(dm_tools.reject_outliers(data)) /
max(dm_tools.reject_outliers(data)))

Q = f0 / abs(min_frequency - max_frequency)

Qe = abs(Q / abs(1 - S21min))
guess_dict = {'f0': {'value': f0*1e-9,
'min': min(xvals)*1e-9,
'max': max(xvals)*1e-9},
'A': {'value': amplitude_guess},
'Q': {'value': Q,
'min': 1,
'max': 50e6},
'Qe': {'value': Qe,
'min': 1,
'max': 50e6},
'Qi': {'expr': 'abs(1./(1./Q-1./Qe*cos(theta)))',
'vary': False},
'Qc': {'expr': 'Qe/cos(theta)',
'vary': False},
'theta': {'value': 0,
'min': -np.pi/2,
'max': np.pi/2},
'slope': {'value':0,
'vary':True}}
return guess_dict



def hanger_func_complex_SI_Guess(data, f, fit_window=None):
## This is complete garbage, just to get some return value
xvals = f
abs_data = np.abs(data)
peaks = a_tools.peak_finder(xvals, abs_data)
# Search for peak
if peaks['dip'] is not None: # look for dips first
f0 = peaks['dip']
amplitude_factor = -1.
elif peaks['peak'] is not None: # then look for peaks
f0 = peaks['peak']
amplitude_factor = 1.
else: # Otherwise take center of range
f0 = np.median(xvals)
amplitude_factor = -1.

min_index = np.argmin(abs_data)
max_index = np.argmax(abs_data)
min_frequency = xvals[min_index]
max_frequency = xvals[max_index]

amplitude_guess = max(dm_tools.reject_outliers(abs_data))

# Creating parameters and estimations
S21min = (min(dm_tools.reject_outliers(abs_data)) /
max(dm_tools.reject_outliers(abs_data)))

Q = f0 / abs(min_frequency - max_frequency)

Qe = abs(Q / abs(1 - S21min))
guess_dict = {'f0': {'value': f0*1e-9,
'min': min(xvals)*1e-9,
'max': max(xvals)*1e-9},
'A': {'value': amplitude_guess},
'Qe': {'value': Qe,
'min': 1,
'max': 50e6},
'Ql': {'value': Q,
'min': 1,
'max': 50e6},
'theta': {'value': 0,
'min': -np.pi/2,
'max': np.pi/2},
'alpha': {'value':0,
'vary':True},
'phi_0': {'value':0,
'vary':True},
'phi_v': {'value':0,
'vary':True}}

return guess_dict



def group_consecutives(vals, step=1):
"""Return list of consecutive lists of numbers from vals (number list)."""
run = []
Expand Down Expand Up @@ -1119,7 +1013,7 @@ def sum_int(x,y):
HangerAmplitudeModel = lmfit.Model(HangerFuncAmplitude)
SlopedHangerAmplitudeModel = lmfit.Model(SlopedHangerFuncAmplitude)
PolyBgHangerAmplitudeModel = lmfit.Model(PolyBgHangerFuncAmplitude)
HangerComplexModel = lmfit.Model(hanger_func_complex_SI)
HangerComplexModel = lmfit.Model(HangerFuncComplex)
SlopedHangerComplexModel = lmfit.Model(SlopedHangerFuncComplex)
QubitFreqDacModel = lmfit.Model(QubitFreqDac)
QubitFreqFluxModel = lmfit.Model(QubitFreqFlux)
Expand Down
4 changes: 2 additions & 2 deletions pycqed/analysis/measurement_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3668,7 +3668,7 @@ def plot_2D_histograms(self, shots_I_0, shots_Q_0, shots_I_1, shots_Q_1,

axarray[0].set_title('2D histogram, pi pulse')
im1 = axarray[0].imshow(np.transpose(H1), interpolation='nearest',
origin='low', aspect='auto',
origin='low',
extent=[xedges1[0], xedges1[-1],
yedges1[0], yedges1[-1]], cmap=cmap)

Expand All @@ -3684,7 +3684,7 @@ def plot_2D_histograms(self, shots_I_0, shots_Q_0, shots_I_1, shots_Q_1,
# plotting 2D histograms of mmts with no pulse
axarray[1].set_title('2D histogram, no pi pulse')
im0 = axarray[1].imshow(np.transpose(H0), interpolation='nearest',
origin='low', aspect='auto',
origin='low',
extent=[xedges0[0], xedges0[-1], yedges0[0],
yedges0[-1]], cmap=cmap)

Expand Down
51 changes: 22 additions & 29 deletions pycqed/analysis/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import matplotlib.colors as col
import hsluv


def set_xlabel(axis, label, unit=None, **kw):
"""
Takes in an axis object and add a unit aware label to it.
Expand Down Expand Up @@ -62,13 +61,12 @@ def set_ylabel(axis, label, unit=None, **kw):
return axis


SI_PREFIXES = dict(zip(range(-24, 25, 3), 'yzafpnμm kMGTPEZY'))
SI_PREFIXES[0] = ""

# N.B. not all of these are SI units, however, all of these support SI prefixes
SI_UNITS = 'm,s,g,W,J,V,A,F,T,Hz,Ohm,S,N,C,px,b,B,K,Bar,Vpeak,Vpp,Vp,Vrms'.split(
',')
SI_PREFIXES_2 = dict(zip(range(-24, 25, 3), 'yzafpnμm kMGTPEZY'))
# SI_PREFIXES_2[0] = ""
#SI_PREFIXES = 'yzafpnμm kMGTPEZY'

SI_UNITS = 'm,s,g,W,J,V,A,F,T,Hz,Ohm,S,N,C,px,b,B,K,Bar,Vpeak,Vpp,Vp,Vrms'.split(',')

def SI_prefix_and_scale_factor(val, unit=None):
"""
Expand All @@ -86,12 +84,7 @@ def SI_prefix_and_scale_factor(val, unit=None):
try:
with np.errstate(all="ignore"):
prefix_power = np.log10(abs(val))//3 * 3
prefix = SI_PREFIXES[prefix_power]
# Greek symbols not supported in tex
if plt.rcParams['text.usetex'] and prefix == 'μ':
prefix = r'$\mu$'

return 10 ** -prefix_power, prefix + unit
return 10 ** -prefix_power, SI_PREFIXES_2[prefix_power] + unit
except (KeyError, TypeError):
pass

Expand Down Expand Up @@ -283,6 +276,7 @@ def flex_colormesh_plot_vs_xy(xvals, yvals, zvals, ax=None,
xvals = np.array(xvals)
yvals = np.array(yvals)


# First, we need to sort the data as otherwise we get odd plotting
# artefacts. An example is e.g., plotting a fourier transform
sorted_x_arguments = xvals.argsort()
Expand Down Expand Up @@ -352,6 +346,7 @@ def autolabel_barplot(ax, rects, rotation=90):
ha='center', va='bottom', rotation=rotation)



def set_axeslabel_color(ax, color):
'''
Ad hoc function to set the labels, ticks, ticklabels and title to a color.
Expand All @@ -366,7 +361,8 @@ def set_axeslabel_color(ax, color):
plt.setp(ax.title, color=color)


# generate custom colormaps

##### generate custom colormaps
def make_segmented_cmap():
white = '#ffffff'
black = '#000000'
Expand All @@ -376,24 +372,21 @@ def make_segmented_cmap():
'anglemap', [black, red, white, blue, black], N=256, gamma=1)
return anglemap

def make_anglemap( N = 256, use_hpl = True ):
h = np.ones(N) # hue
h[:N//2] = 11.6 # red
h[N//2:] = 258.6 # blue
s = 100 # saturation
l = np.linspace(0, 100, N//2) # luminosity
l = np.hstack( (l,l[::-1] ) )

def make_anglemap(N=256, use_hpl=True):
h = np.ones(N) # hue
h[:N//2] = 11.6 # red
h[N//2:] = 258.6 # blue
s = 100 # saturation
l = np.linspace(0, 100, N//2) # luminosity
l = np.hstack((l, l[::-1]))

colorlist = np.zeros((N, 3))
colorlist = np.zeros((N,3))
for ii in range(N):
if use_hpl:
colorlist[ii, :] = hsluv.hpluv_to_rgb((h[ii], s, l[ii]))
colorlist[ii,:] = hsluv.hpluv_to_rgb( (h[ii], s, l[ii]) )
else:
colorlist[ii, :] = hsluv.hsluv_to_rgb((h[ii], s, l[ii]))
colorlist[colorlist > 1] = 1 # correct numeric errors
colorlist[ii,:] = hsluv.hsluv_to_rgb( (h[ii], s, l[ii]) )
colorlist[colorlist > 1] = 1 # correct numeric errors
colorlist[colorlist < 0] = 0
return col.ListedColormap(colorlist)


hsluv_anglemap = make_anglemap(use_hpl=False)
return col.ListedColormap( colorlist )
hsluv_anglemap = make_anglemap( use_hpl = False )
Loading

0 comments on commit ffe4d87

Please sign in to comment.