Skip to content

Commit 84967c0

Browse files
committed
Environment stuff
1 parent 4f0f3d0 commit 84967c0

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

tutorials-v5/time-evolution/023_v5_paper-mesolve.md

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ In this notebook we will consider several examples illustrating the usage of the
3434
```python
3535
import matplotlib.pyplot as plt
3636
import numpy as np
37-
from qutip import (SESolver, about, basis, brmesolve, fidelity, mesolve, qeye,
38-
sigmam, sigmax, sigmaz, spost, spre, sprepost)
37+
from qutip import (QobjEvo, SESolver, UnderDampedEnvironment,
38+
about, basis, brmesolve, fidelity, mesolve,
39+
qeye, sigmam, sigmax, sigmaz, spost, spre, sprepost)
3940

40-
# from qutip.solver.heom import HEOMSolver, BosonicBath
41+
from qutip.solver.heom import HEOMSolver
4142

4243
%matplotlib inline
4344
```
@@ -442,26 +443,32 @@ driv_br_res = brmesolve(H, psi0, tlist, a_ops, sec_cutoff=-1, e_ops=e_ops)
442443
### With `HEOMSolver`
443444

444445
```python
446+
max_depth = 4 # number of hierarchy levels
447+
445448
wsamp = 2 * np.pi
446449
w0 = 5 * 2 * np.pi
447-
448450
gamma_heom = 1.9 * w0
449451

450-
451452
lambd = np.sqrt(
452-
0.5
453-
* gamma
453+
0.5 * gamma / (gamma_heom * wsamp)
454454
* ((w0**2 - wsamp**2) ** 2 + (gamma_heom**2) * ((wsamp) ** 2))
455-
/ (gamma_heom * wsamp)
456455
)
457456
```
458457

459458
```python
460-
# TODO UnderDampedEnvironment is in a big separate on Overleaf, how to handle?
461-
462459
# Create Environment
463-
# bath = UnderDampedEnvironment(lam=lambd, w0=w0, gamma=gamma_heom, T=1e-30)
460+
bath = UnderDampedEnvironment(lam=lambd, w0=w0, gamma=gamma_heom, T=1e-10)
464461
fit_times = np.linspace(0, 5, 1000) # range for correlation function fit
462+
463+
# Fit correlation function with exponentials
464+
exp_bath, fit_info = bath.approx_by_cf_fit(fit_times, Ni_max=1, Nr_max=2, target_rsme=None)
465+
print(fit_info["summary"])
466+
```
467+
468+
```python
469+
HEOM_corr_fit = HEOMSolver(QobjEvo(H), (exp_bath, sigmax()), max_depth=max_depth,
470+
options={'nsteps': 15000, 'rtol': 1e-12, 'atol': 1e-12})
471+
results_corr_fit = HEOM_corr_fit.run(psi0 * psi0.dag(), tlist, e_ops=e_ops)
465472
```
466473

467474
### Comparison of Solver Results
@@ -471,7 +478,7 @@ plt.figure()
471478

472479
plt.plot(tlist, driv_res.expect[0], "-", label="mesolve (time-dep)")
473480
plt.plot(tlist, driv_RWA_res.expect[0], "-.", label="mesolve (rwa)")
474-
# plt.plot(tlist, results_corr_fit.expect[0], '--', label=r'heomsolve')
481+
plt.plot(tlist, np.real(results_corr_fit.expect[0]), '--', label=r'heomsolve')
475482
plt.plot(tlist, driv_br_res.expect[0], ":", linewidth=3, label="brmesolve")
476483

477484
plt.xlabel(r"$t\, /\, \Delta^{-1}$")
@@ -494,61 +501,50 @@ If the drive is slow enough, we expect the bath to respond to this change and tr
494501
omega_d = 0.05 * Delta # drive frequency
495502
A = Delta # drive amplitude
496503
H_adi = [[A / 2.0 * sigmaz(), f]]
497-
# H = [H0]
498504

499505
# Bath parameters
500506
gamma = 0.05 * Delta / (2 * np.pi)
501507

502508
# Simulation parameters
509+
T = 2 * np.pi / omega_d # period length
503510
tlist = np.linspace(0, 2 * T, 400)
504511
```
505512

506513
```python
507514
# Simple mesolve
515+
c_ops_me = [np.sqrt(gamma) * sigmam()]
508516
adi_me_res = mesolve(H_adi, psi0, tlist, c_ops=c_ops_me, e_ops=e_ops)
509517
```
510518

511519
```python
512-
# bath = UnderDampedEnvironment(lam=lambd, w0=w0, gamma=gamma_heom, T=1e-30)
513-
# fit_times = np.linspace(0, 5, 1000) # range for correlation function fit
514-
515-
# cfit, fit_info = bath.approx_by_cf_fit(fit_times,
516-
# Ni_max=1, Nr_max=2, target_rsme=None)
517-
# print(fit_info["summary"])
518-
# Convert to a HEOM bath
519-
# heombath = cfit.to_bath(sigmax())
520-
521-
522-
# HEOM_corr_fit = HEOMSolver(
523-
# qt.QobjEvo(H),
524-
# heombath,
525-
# max_depth=max_depth,
526-
# options={"nsteps": 15000, "rtol": 1e-12, "atol": 1e-12},
527-
# )
528-
# results_corr_fit = HEOM_corr_fit.run(psi0 * psi0.dag(), tlist, e_ops=e_ops)
520+
# HEOM
521+
HEOM_corr_fit = HEOMSolver(QobjEvo(H_adi), (exp_bath, sigmax()), max_depth=max_depth,
522+
options={"nsteps": 15000, "rtol": 1e-12, "atol": 1e-12})
523+
results_corr_fit = HEOM_corr_fit.run(psi0 * psi0.dag(), tlist, e_ops=e_ops)
529524
```
530525

531526
```python
532527
# BRSolve
533-
brme_result2 = brmesolve(H, psi0, tlist, a_ops=a_ops, e_ops=e_ops)
528+
brme_result2 = brmesolve(H_adi, psi0, tlist, a_ops=a_ops, e_ops=e_ops)
534529
```
535530

536531
```python
537532
# BRSolve non-flat power spectrum
538-
# a_ops_non_flat = [[sigmax(), lambda w: cfit.power_spectrum(w).item()]]
539-
# brme_result = brmesolve(H, psi0, tlist, a_ops=a_ops_non_flat, e_ops=e_ops)
533+
a_ops_non_flat = [[sigmax(), lambda w: exp_bath.power_spectrum(w)]]
534+
brme_result = brmesolve(H_adi, psi0, tlist, a_ops=a_ops_non_flat, e_ops=e_ops)
540535
```
541536

542537
```python
543538
plt.plot(tlist, adi_me_res.expect[0], "-", label="mesolve")
544-
# plt.plot(tlist, results_corr_fit.expect[0], '--', label=r'heomsolve')
545-
# plt.plot(tlist, brme_result.expect[0], ":", linewidth=6,
546-
# label="brmesolve non-flat")
539+
plt.plot(tlist, np.real(results_corr_fit.expect[0]), '--', label=r'heomsolve')
540+
plt.plot(tlist, brme_result.expect[0], ":", linewidth=6,
541+
label="brmesolve non-flat")
547542
plt.plot(tlist, brme_result2.expect[0], ":", linewidth=6, label="brmesolve")
548543

549544
plt.xlabel(r"$t\, /\, \Delta^{-1}$", fontsize=18)
550545
plt.ylabel(r"$\langle \sigma_z \rangle$", fontsize=18)
551546
plt.legend()
547+
plt.show()
552548
```
553549

554550
## References

0 commit comments

Comments
 (0)