master-thesis/python/richard_hops/run_Fulu.py

134 lines
4.2 KiB
Python
Raw Normal View History

2021-10-15 16:18:03 +02:00
import hierarchyLib
import hierarchyData
import numpy as np
import pickle
from scipy.special import gamma as gamma_func
from stocproc.stocproc import StocProc_FFT
import bcf
t_max = 25
alpha = 0.266
T = 2.09
numExpFit = 5
s = 1
wc = 0.531
2021-10-18 18:40:50 +02:00
with open("good_fit_data_abs_brute_force", "rb") as f:
2021-10-15 16:18:03 +02:00
good_fit_data_abs = pickle.load(f)
_, g_tilde, w_tilde = good_fit_data_abs[(numExpFit, s)]
2021-10-18 18:40:50 +02:00
g = 1 / np.pi * gamma_func(s + 1) * wc ** (s + 1) * np.asarray(g_tilde)
2021-10-15 16:18:03 +02:00
w = wc * np.asarray(w_tilde)
2021-10-18 18:40:50 +02:00
bcf_scale = np.pi / 2 * alpha * wc ** (1 - s)
2021-10-15 16:18:03 +02:00
# setup hierarchy parameters, here use a simple triangular hierarchy up to level 5
# the comments show the default values
# NOTE! the normalized version of HOPS is still buggy !!!
2021-10-18 18:40:50 +02:00
HierachyParam = hierarchyData.HiP(
k_max=5,
# g_scale=None,
# sample_method='random',
# seed=0,
# nonlinear=True,
# normalized=False,
# terminator=False,
# result_type= hierarchyData.RESULT_TYPE_ZEROTH_ORDER_ONLY,
# accum_only=None,
# rand_skip=None
)
2021-10-15 16:18:03 +02:00
# setup the integration parameters (see scipy ode)
2021-10-18 18:40:50 +02:00
IntegrationParam = hierarchyData.IntP(
t_max=t_max,
t_steps=500,
# integrator_name='zvode',
# atol=1e-8,
# rtol=1e-8,
# order=5,
# nsteps=5000,
# method='bdf',
# t_steps_skip=1
)
2021-10-15 16:18:03 +02:00
# setup the system parameters
# here a simple Spin Boson system, single qubit coupled to a sub-ohmic environment
# how to get the g, w is a different story
2021-10-18 18:40:50 +02:00
SystemParam = hierarchyData.SysP(
H_sys=np.asarray([[0, 1], [1, 0]]), # SIGMA X
L=np.asarray([[-1, 0], [0, 1]]), # SIGME Z
psi0=np.asarray([0, 1]), # excited qubit
g=np.asarray(g),
w=np.asarray(w),
H_dynamic=[],
bcf_scale=bcf_scale, # some coupling strength (scaling of the fit parameters 'g_i')
gw_hash=None, # this is used to load g,w from some database
len_gw=None,
)
2021-10-15 16:18:03 +02:00
# setup the stochastic process for the subohmic SD
# for each sample, the StocProc_FFT class is seeded differently which results in a different realization.
# for the HOPS solver, this looks like a simple callable z(t) returning complex values
2021-10-18 18:40:50 +02:00
Eta = StocProc_FFT(
spectral_density=bcf.OSD(s=s, eta=1, gamma=wc),
t_max=t_max,
alpha=bcf.OBCF(s=s, eta=1, gamma=wc),
intgr_tol=1e-3,
intpl_tol=1e-3,
seed=None,
negative_frequencies=False,
scale=bcf_scale,
)
2021-10-15 16:18:03 +02:00
# thermal noise
2021-10-18 18:40:50 +02:00
EtaTherm = StocProc_FFT(
spectral_density=bcf.OFTDens(s=s, eta=1, gamma=wc, beta=1 / T),
t_max=t_max,
alpha=bcf.OFTCorr(s=s, eta=1, gamma=wc, beta=1 / T),
intgr_tol=1e-3,
intpl_tol=1e-3,
seed=None,
negative_frequencies=False,
scale=bcf_scale,
)
2021-10-15 16:18:03 +02:00
# this guy must be digestable by the 'binfootprint' class, generating a unique binary representation of hi_key
# this allows to generate a hash value of the binary to access the produced data from some hdf5 data (see hierarchyData.py)
# NOTE! this requires that the ENTIRE sub-structure of 'hi_key' is digestable by 'binfootprint', therefore the special classes
# representing the spectral density and bath correlation function defined in bcf.py
# I developed 'binfootprit' since pickle and co. are not guaranteed to lead to unique binary data,
2021-10-18 18:40:50 +02:00
hi_key = hierarchyData.HIMetaKey_type(
HiP=HierachyParam,
IntP=IntegrationParam,
SysP=SystemParam,
Eta=Eta,
EtaTherm=EtaTherm,
)
2021-10-15 16:18:03 +02:00
# here the hierarchy structure it set up ...
2021-10-18 18:40:50 +02:00
myHierarchy = hierarchyLib.HI(hi_key, number_of_samples=100, desc="run a test case")
2021-10-15 16:18:03 +02:00
# ... which allows to perform the integration, the data is stored in a file called 'myHierarchy.data'
# running the script again only crunches samples not done before!
2021-10-18 18:40:50 +02:00
myHierarchy.integrate_simple(data_name="myHierarchy.data")
2021-10-15 16:18:03 +02:00
# to access the data the 'hi_key' is used to find the data in the hdf5 file
2021-10-18 18:40:50 +02:00
with hierarchyData.HIMetaData(hid_name="myHierarchy.data", hid_path=".") as metaData:
2021-10-15 16:18:03 +02:00
with metaData.get_HIData(hi_key, read_only=True) as data:
smp = data.get_samples()
print("{} samples found in database".format(smp))
t = data.get_time()
rho_t = data.get_rho_t()
# to show some dynamics
import matplotlib.pyplot as plt
2021-10-18 18:40:50 +02:00
plt.plot(t, rho_t[:, 1, 1].real, label="average ({})".format(smp))
2021-10-15 16:18:03 +02:00
plt.ylabel("rho_(0,0)")
plt.xlabel("time")
plt.legend()
plt.show()