In [1]:
!ipython locate profile
In [2]:
%install_ext https://raw.githubusercontent.com/rasbt/python_reference/master/ipython_magic/watermark.py
%load_ext watermark
In [3]:
import numpy as np
from numpy import linalg as LA
from numpy import array
from numpy import pi
import matplotlib.pyplot as plt
In [4]:
fig_width = 3.39
golden_mean = (np.sqrt(5)-1.0)/2.0 # Aesthetic ratio
fig_height = fig_width*golden_mean # height in inches
MAX_HEIGHT_INCHES = 8.0
if fig_height > MAX_HEIGHT_INCHES:
print("WARNING: fig_height too large:" + fig_height +
"so will reduce to" + MAX_HEIGHT_INCHES + "inches.")
fig_height = MAX_HEIGHT_INCHES
fig, ax = plt.subplots(figsize = (fig_width, fig_height), dpi=400, frameon=True)
small_tick_size = 8
small_label_size = 8
In [5]:
import matplotlib.pyplot as plt
import sys
import math
from scipy.optimize import curve_fit
import pickle
if "/home/dominique/Code/PG/Source" not in sys.path:
sys.path.append("/home/dominique/Code/PG/Source")
import phase_fluctuations as PF
from phase_fluctuations import TbModel, TbParams, SWaveModel, DWaveModel
from MCMC import MCMCDriver
import scipy.constants as cst
def K_to_meV(in_temp):
return cst.physical_constants["Boltzmann constant in eV/K"][0] * in_temp * 1000.0
def meV_to_K(in_temp):
return in_temp / 1000.0 / cst.physical_constants["Boltzmann constant in eV/K"][0]
def func(x, a, b, c):
return a * np.exp(-b * x) + c
def func_short(x, a, b):
return a * np.exp(-b * x)
def func_combined(x, a, b, d):
return a * np.exp(-b * x) / np.power(x, d)
def func_power(x, a, b):
return a * np.power(x, b)
def func_exponent(x, a, b):
#return a * np.power(x - 290.112982064, b)
return a * np.exp(-np.power(x - 290.112982064, b))
def func_full(x, a, b, c):
return a * np.exp(-np.abs(b) * x) / np.power(x, c)
In [6]:
%load_ext autoreload
%autoreload 2
In [7]:
%who
%matplotlib inline
In [8]:
%watermark -a "Dominique" -d -t -u -v -h -m -g
We pick the following parameters:
This means that we have the following physical properties
In [12]:
Tc_mf = meV_to_K(0.5*250)
print meV_to_K(pi/2.0)
print 1.0/0.89
print cst.physical_constants["Boltzmann constant"]
In [13]:
print '$T_c^{MF} = $', Tc_mf, "K"
T_KT = meV_to_K(0.1*250)
print r"$T_{KT} = $", T_KT, "K"
In [14]:
T_CST = 0.25
MY_PARAMS = {"width":10, "chem_potential": 0.0,
"hopping_constant": T_CST, "J_constant": 0.1 * T_CST / 0.89,
"delta": 1.0 * T_CST,
"use_assaad": False, "broadening_delta": 0.01 * T_CST}
MY_MODEL = TbModel(MY_PARAMS)
In [15]:
TB_PARAMS = {"width":14, "use_assaad": True}
MY_MODEL.set_params(TB_PARAMS)
print MY_MODEL
In [13]:
all_test_vectors = []
nb_samples = MY_MODEL.lattice.width
for elem in np.arange(nb_samples):
print "handling", elem
k_in = elem * 1.0 * np.pi * np.array([1.0, 1.0]) / nb_samples
test2_vector = MY_MODEL.get_vector_spectral_function_point(k_in,
MY_MODEL.lattice.omega_mesh)
all_test_vectors.append(test2_vector)
In [23]:
def get_spectral_function(x):
import numpy as np
import os
print "process", os.getpid(), "handling", x
nb_samples = MY_MODEL.lattice.width
k_in = x * np.pi * np.array([1.0, 1.0]) / nb_samples
return MY_MODEL.get_vector_spectral_function_point(k_in, MY_MODEL.lattice.omega_mesh)
In [ ]:
import multiprocessing
nb_samples = MY_MODEL.lattice.width
multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=3)
all_test_vectors = pool.map(get_spectral_function, np.arange(nb_samples))
In [19]:
array_coords = []
z_values = []
for elem in np.arange(nb_samples):
k_in = elem * np.pi * np.array([1.0, 0.0]) / nb_samples
to_add = [[k_in[0], energy/T_CST] for energy in MY_MODEL.lattice.omega_mesh]
array_coords.extend(to_add)
z_values.extend(all_test_vectors[elem])# / np.amax(all_test_vectors[elem]))
array_coords = np.array(array_coords)
z_values = np.array(z_values)
In [20]:
from scipy.interpolate import griddata
visu_factor = 3
fig, ax = plt.subplots(figsize = (fig_width*visu_factor, fig_height*visu_factor), dpi=400, frameon=False)
xmin = 0.0
xmax = np.pi
ymin = -5.0
ymax = 5.0
#grid_x = np.linspace(xmin, xmax, num = 200)
#grid_y = np.linspace(ymin, ymax, num = 2000)
grid_x, grid_y = np.mgrid[xmin:xmax:100j, ymin:ymax:200j]
grid_z1 = griddata(array_coords, z_values, (grid_x, grid_y), method='nearest', fill_value=0.0)
p = ax.pcolormesh(grid_x, grid_y, grid_z1, cmap=plt.get_cmap('Greys'),rasterized=True)
#for index, theta in np.ndenumerate(thetas):
# ax.plot(theta, resonance_omega_values[index], marker='o', color='k')
cb = fig.colorbar(p, ax=ax)
ax.plot(grid_x, -2.0 * 2.0 * T_CST * np.cos(grid_x) / T_CST)
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
plt.savefig("spectral_function.pdf")
In [39]:
import contextlib
@contextlib.contextmanager
def printoptions(*args, **kwargs):
"""Define some temporary pretty print options
"""
original = np.get_printoptions()
np.set_printoptions(*args, **kwargs)
yield
np.set_printoptions(**original)
In [40]:
with printoptions(precision=4, suppress=True, threshold=np.nan):
print MY_MODEL._eigen_values
for i in np.arange(MY_MODEL.lattice.width):
print MY_MODEL._unitary_matrix[i]
In [89]:
k_in = 1.0 * np.pi * np.array([1.0, 1.0])
test = MY_MODEL.get_vector_spectral_function_point(k_in,
MY_MODEL.lattice.omega_mesh)
In [90]:
fig, ax = plt.subplots(figsize = (10, 8), dpi=100, frameon=False)
x_axis_ampl = 4.5
xmin = -x_axis_ampl
xmax = x_axis_ampl
ax.set_xlim([xmin, xmax])
#ax.set_ylim([0.0, 1.0])
l_xticks = np.linspace(int(xmin), int(xmax), 9,endpoint=True)
ax.set_xticks(l_xticks)
ax.set_xticklabels(['%1.1f' %elem for elem in l_xticks])
#ax.set_xticklabels([r'$\psi$' for elem in l_xticks])
#ax.set_yticks(np.linspace(xmin, xmax, 5,endpoint=True))
#ax.set_yticklabels(['%1.1f' %elem for elem in np.linspace(xmin, xmax,5,endpoint=True)])
ax.plot(MY_MODEL.lattice.omega_mesh/T_CST, test)
#ax.plot(MY_MODEL.lattice.omega_mesh/T_CST, test_elem)
Out[90]:
In [18]:
T_CST = 0.25
BCS_PARAMS = {"width":4, "chem_potential": 0.0,
"hopping_constant": T_CST, "J_constant": 0.1 * T_CST / 0.89,
"g_constant": 0.25, "delta": 1.0 * T_CST, "use_assaad": True,
"uniform_phase": True, "temperature": 100}
MY_DWAVE_MODEL = DWaveModel(BCS_PARAMS)
In [19]:
print MY_DWAVE_MODEL
In [20]:
BCS_PARAMS = {"width":12, "use_assaad": True,
"uniform_phase": True, "temperature": 1.75*145.0,
"delta": 1.0 * T_CST}
MY_DWAVE_MODEL.set_params(BCS_PARAMS)
print MY_DWAVE_MODEL
print "temp: ", K_to_meV(MY_DWAVE_MODEL.temperature), "meV"
In [129]:
k_in = 9.0 * np.pi * np.array([1.0, 1.0]) / MY_DWAVE_MODEL.lattice.width
test = MY_DWAVE_MODEL.get_vector_spectral_function_point(k_in,
MY_DWAVE_MODEL.lattice.omega_mesh)
In [130]:
test_elem = []
for omega in MY_DWAVE_MODEL.lattice.omega_mesh:
test_elem.append(MY_DWAVE_MODEL.get_spectral_function_point(k_in, omega))
In [128]:
test_index = 105
omega_test = MY_DWAVE_MODEL.lattice.omega_mesh[test_index]
omega = MY_DWAVE_MODEL.lattice.omega_mesh[test_index]
a = MY_DWAVE_MODEL.get_vector_spectral_function_point(k_in, np.array([omega_test]))
c = MY_DWAVE_MODEL.get_spectral_function_point(k_in, omega_test)
print np.allclose(a, c)
In [131]:
fig, ax = plt.subplots(figsize = (10, 8), dpi=100, frameon=False)
x_axis_ampl = 4.5
xmin = -x_axis_ampl
xmax = x_axis_ampl
ax.set_xlim([xmin, xmax])
#ax.set_ylim([0.0, 1.0])
l_xticks = np.linspace(int(xmin), int(xmax), 9,endpoint=True)
ax.set_xticks(l_xticks)
ax.set_xticklabels(['%1.1f' %elem for elem in l_xticks])
#ax.set_xticklabels([r'$\psi$' for elem in l_xticks])
#ax.set_yticks(np.linspace(xmin, xmax, 5,endpoint=True))
#ax.set_yticklabels(['%1.1f' %elem for elem in np.linspace(xmin, xmax,5,endpoint=True)])
ax.plot(MY_DWAVE_MODEL.lattice.omega_mesh/T_CST, test, label = "vector")
ax.plot(MY_DWAVE_MODEL.lattice.omega_mesh/T_CST, test_elem, label = "single")
ax.legend()
Out[131]:
In [132]:
test2 = []
for omega in MY_DWAVE_MODEL.lattice.omega_mesh:
test2.append(MY_DWAVE_MODEL.get_spectral_function_point(np.pi * np.array([1.0, 0.0]),
omega))
In [133]:
k_in = np.pi * np.array([1.0, 0.0])
test2_vector = MY_DWAVE_MODEL.get_vector_spectral_function_point(k_in,
MY_DWAVE_MODEL.lattice.omega_mesh)
In [134]:
fig, ax = plt.subplots(figsize = (10, 8), dpi=100, frameon=False)
x_axis_ampl = 4.5
xmin = -x_axis_ampl
xmax = x_axis_ampl
ax.set_xlim([xmin, xmax])
#ax.set_ylim([0.0, 1.0])
l_xticks = np.linspace(int(xmin), int(xmax), 9,endpoint=True)
ax.set_xticks(l_xticks)
ax.set_xticklabels(['%1.1f' %elem for elem in l_xticks])
#ax.set_xticklabels([r'$\psi$' for elem in l_xticks])
#ax.set_yticks(np.linspace(xmin, xmax, 5,endpoint=True))
#ax.set_yticklabels(['%1.1f' %elem for elem in np.linspace(xmin, xmax,5,endpoint=True)])
ax.plot(MY_DWAVE_MODEL.lattice.omega_mesh/T_CST, test2_vector)
ax.plot(MY_DWAVE_MODEL.lattice.omega_mesh/T_CST, test2)
Out[134]:
In [21]:
all_test_vectors = []
nb_samples = MY_DWAVE_MODEL.lattice.width
for elem in np.arange(nb_samples):
print "handling", elem
k_in = elem * np.pi * np.array([1.0, 1.0]) / nb_samples
test2_vector = MY_DWAVE_MODEL.get_vector_spectral_function_point(k_in,
MY_DWAVE_MODEL.lattice.omega_mesh)
all_test_vectors.append(test2_vector)
In [22]:
array_coords = []
z_values = []
for elem in np.arange(nb_samples):
k_in = elem * np.pi * np.array([1.0, 0.0]) / nb_samples
to_add = [[k_in[0], energy/T_CST] for energy in MY_DWAVE_MODEL.lattice.omega_mesh]
array_coords.extend(to_add)
z_values.extend(all_test_vectors[elem])# / np.amax(all_test_vectors[elem]))
array_coords = np.array(array_coords)
z_values = np.array(z_values)
In [23]:
from scipy.interpolate import griddata
visu_factor = 3
fig, ax = plt.subplots(figsize = (fig_width*visu_factor, fig_height*visu_factor), dpi=400, frameon=False)
xmin = 0.0
xmax = np.pi
ymin = -5.0
ymax = 5.0
#grid_x = np.linspace(xmin, xmax, num = 200)
#grid_y = np.linspace(ymin, ymax, num = 2000)
grid_x, grid_y = np.mgrid[xmin:xmax:100j, ymin:ymax:200j]
grid_z1 = griddata(array_coords, z_values, (grid_x, grid_y), method='nearest', fill_value=0.0)
p = ax.pcolormesh(grid_x, grid_y, grid_z1, cmap=plt.get_cmap('Greys'),rasterized=True)
#for index, theta in np.ndenumerate(thetas):
# ax.plot(theta, resonance_omega_values[index], marker='o', color='k')
cb = fig.colorbar(p, ax=ax)
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
Out[23]:
In [24]:
fig, ax = plt.subplots(figsize = (10, 8), dpi=100, frameon=False)
x_axis_ampl = 4.5
xmin = -x_axis_ampl
xmax = x_axis_ampl
ax.set_xlim([xmin, xmax])
#ax.set_ylim([0.0, 1.0])
l_xticks = np.linspace(int(xmin), int(xmax), 9,endpoint=True)
ax.set_xticks(l_xticks)
ax.set_xticklabels(['%1.1f' %elem for elem in l_xticks])
#ax.set_xticklabels([r'$\psi$' for elem in l_xticks])
#ax.set_yticks(np.linspace(xmin, xmax, 5,endpoint=True))
#ax.set_yticklabels(['%1.1f' %elem for elem in np.linspace(xmin, xmax,5,endpoint=True)])
ax.plot(MY_DWAVE_MODEL.lattice.omega_mesh/T_CST,
MY_DWAVE_MODEL.get_vector_spectral_function_point(np.array([0.6, 0.6]),
MY_DWAVE_MODEL.lattice.omega_mesh))
Out[24]:
In [25]:
all_test_vectors = []
nb_samples = MY_DWAVE_MODEL.lattice.width
for elem in np.arange(nb_samples):
print "handling", elem
k_in = elem * np.pi * np.array([1.0, 0.0]) / nb_samples
test2_vector = MY_DWAVE_MODEL.get_vector_spectral_function_point(k_in,
MY_DWAVE_MODEL.lattice.omega_mesh)
all_test_vectors.append(test2_vector)
In [26]:
array_coords = []
z_values = []
for elem in np.arange(nb_samples):
k_in = elem * np.pi * np.array([1.0, 0.0]) / nb_samples
to_add = [[k_in[0], energy/T_CST] for energy in MY_DWAVE_MODEL.lattice.omega_mesh]
array_coords.extend(to_add)
z_values.extend(all_test_vectors[elem])# / np.amax(all_test_vectors[elem]))
array_coords = np.array(array_coords)
z_values = np.array(z_values)
In [27]:
from scipy.interpolate import griddata
visu_factor = 3
fig, ax = plt.subplots(figsize = (fig_width*visu_factor, fig_height*visu_factor), dpi=400, frameon=False)
xmin = 0.0
xmax = np.pi
ymin = -5.0
ymax = 5.0
#grid_x = np.linspace(xmin, xmax, num = 200)
#grid_y = np.linspace(ymin, ymax, num = 2000)
grid_x, grid_y = np.mgrid[xmin:xmax:100j, ymin:ymax:200j]
grid_z1 = griddata(array_coords, z_values, (grid_x, grid_y), method='nearest', fill_value=0.0)
p = ax.pcolormesh(grid_x, grid_y, grid_z1, cmap=plt.get_cmap('Greys'),rasterized=True)
#for index, theta in np.ndenumerate(thetas):
# ax.plot(theta, resonance_omega_values[index], marker='o', color='k')
cb = fig.colorbar(p, ax=ax)
ax.set_xlim([xmin, xmax])
ax.set_ylim([ymin, ymax])
Out[27]:
In [ ]: