2021-11-15 13:34:35 +01:00
|
|
|
|
#+PROPERTY: header-args :session finite_temp_new :kernel python :pandoc yes :async yes
|
2021-11-12 17:49:23 +01:00
|
|
|
|
|
|
|
|
|
* Configuration and Setup
|
2022-01-17 17:40:51 +01:00
|
|
|
|
This will be tangled into the [[file:config.py][config file]] that can be used with the HOPS cli.
|
|
|
|
|
|
|
|
|
|
#+begin_src jupyter-python :results none :tangle config.py
|
|
|
|
|
from hops.core.hierarchy_parameters import HIParams, HiP, IntP, SysP, ResultType
|
|
|
|
|
from hops.core.hierarchyLib import HI
|
|
|
|
|
from hops.util.bcf_fits import get_ohm_g_w
|
|
|
|
|
from hops.util.truncation_schemes import TruncationScheme_Power_multi
|
|
|
|
|
import hops.util.bcf
|
|
|
|
|
import numpy as np
|
|
|
|
|
import hops.util.matrixLib as ml
|
|
|
|
|
from stocproc import StocProc_FFT
|
|
|
|
|
|
|
|
|
|
wc = 5
|
|
|
|
|
s = 1
|
|
|
|
|
|
|
|
|
|
# The BCF fit
|
|
|
|
|
bcf_terms = 7
|
|
|
|
|
g, w = get_ohm_g_w(bcf_terms, s, wc)
|
|
|
|
|
|
|
|
|
|
integration = IntP(t_max=30, t_steps=int(30 // 0.01))
|
|
|
|
|
system = SysP(
|
|
|
|
|
H_sys=0.5 * np.array([[-1, 0], [0, 1]]),
|
|
|
|
|
L=0.5 * np.array([[0, 1], [1, 0]]),
|
|
|
|
|
psi0=np.array([0, 1]),
|
|
|
|
|
g=g,
|
|
|
|
|
w=w,
|
|
|
|
|
bcf_scale=0.8,
|
|
|
|
|
T=0.1,
|
|
|
|
|
)
|
2021-11-12 17:49:23 +01:00
|
|
|
|
|
2022-01-17 17:40:51 +01:00
|
|
|
|
params = HIParams(
|
|
|
|
|
SysP=system,
|
|
|
|
|
IntP=integration,
|
|
|
|
|
HiP=HiP(
|
|
|
|
|
nonlinear=True,
|
|
|
|
|
normalized_by_hand=True,
|
|
|
|
|
result_type=ResultType.ZEROTH_AND_FIRST_ORDER,
|
|
|
|
|
truncation_scheme=TruncationScheme_Power_multi.from_g_w(
|
|
|
|
|
g=g, w=w, p=1, q=0.5, kfac=1.4
|
|
|
|
|
),
|
|
|
|
|
save_therm_rng_seed=True,
|
|
|
|
|
),
|
|
|
|
|
Eta=StocProc_FFT(
|
|
|
|
|
spectral_density=hops.util.bcf.OhmicSD_zeroTemp(
|
|
|
|
|
s,
|
|
|
|
|
1,
|
|
|
|
|
wc,
|
|
|
|
|
),
|
|
|
|
|
alpha=hops.util.bcf.OhmicBCF_zeroTemp(
|
|
|
|
|
s,
|
|
|
|
|
1,
|
|
|
|
|
wc,
|
|
|
|
|
),
|
|
|
|
|
t_max=integration.t_max,
|
|
|
|
|
intgr_tol=1e-4,
|
|
|
|
|
intpl_tol=1e-4,
|
|
|
|
|
negative_frequencies=False,
|
|
|
|
|
),
|
|
|
|
|
EtaTherm=StocProc_FFT(
|
|
|
|
|
spectral_density=hops.util.bcf.Ohmic_StochasticPotentialDensity(
|
|
|
|
|
s, 1, wc, beta=1 / system.__non_key__["T"]
|
|
|
|
|
),
|
|
|
|
|
alpha=hops.util.bcf.Ohmic_StochasticPotentialCorrelations(
|
|
|
|
|
s, 1, wc, beta=1 / system.__non_key__["T"]
|
|
|
|
|
),
|
|
|
|
|
t_max=integration.t_max,
|
|
|
|
|
intgr_tol=1e-4,
|
|
|
|
|
intpl_tol=1e-4,
|
|
|
|
|
negative_frequencies=False,
|
|
|
|
|
),
|
|
|
|
|
)
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
* Using the Data
|
|
|
|
|
** Jupyter Setup
|
2022-01-17 17:40:51 +01:00
|
|
|
|
#+begin_src jupyter-python :results none
|
2021-11-12 17:49:23 +01:00
|
|
|
|
import numpy as np
|
|
|
|
|
import matplotlib.pyplot as plt
|
2022-01-17 17:40:51 +01:00
|
|
|
|
import utilities as ut
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
** Load the Data
|
2022-01-17 17:40:51 +01:00
|
|
|
|
#+begin_src jupyter-python :results none
|
|
|
|
|
from hopsflow import hopsflow, util
|
|
|
|
|
from hops.core.hierarchyData import HIMetaData
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
Now we read the trajectory data.
|
|
|
|
|
#+begin_src jupyter-python
|
|
|
|
|
class result:
|
2022-01-17 17:40:51 +01:00
|
|
|
|
hd = HIMetaData("data", ".").get_HIData(params, read_only=True)
|
|
|
|
|
N = hd.samples
|
2021-11-12 17:49:23 +01:00
|
|
|
|
τ = hd.get_time()
|
|
|
|
|
ψ_1 = hd.aux_states
|
|
|
|
|
ψ = hd.stoc_traj
|
2022-01-17 17:40:51 +01:00
|
|
|
|
seeds = hd.rng_seed
|
2022-01-18 15:17:22 +01:00
|
|
|
|
|
|
|
|
|
result.N
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
: 10000
|
2021-11-12 17:49:23 +01:00
|
|
|
|
|
|
|
|
|
** Calculate System Energy
|
|
|
|
|
Simple sanity check.
|
|
|
|
|
#+begin_src jupyter-python
|
2022-01-17 17:40:51 +01:00
|
|
|
|
_, e_sys, σ_e_sys = util.operator_expectation_ensemble(
|
2022-01-18 15:17:22 +01:00
|
|
|
|
iter(result.ψ),
|
|
|
|
|
system.H_sys,
|
|
|
|
|
result.N,
|
|
|
|
|
params.HiP.nonlinear,
|
|
|
|
|
save="./results/energy.npy",
|
|
|
|
|
)
|
2022-01-17 17:40:51 +01:00
|
|
|
|
|
|
|
|
|
plt.errorbar(result.τ, e_sys.real, yerr=σ_e_sys.real, ecolor="yellow")
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
:RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
: 100% 9999/9999 [00:23<00:00, 433.45it/s]
|
2022-01-17 17:40:51 +01:00
|
|
|
|
: <ErrorbarContainer object of 3 artists>
|
2022-01-18 15:17:22 +01:00
|
|
|
|
[[file:./.ob-jupyter/bff3797a8e0a2044163cbb09ac605a140b1d3e61.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
** Calculate the Heat Flow
|
|
|
|
|
Now let's calculate the heatflow. In this simple case it is engouh to
|
|
|
|
|
know the first hierarchy states.
|
|
|
|
|
|
|
|
|
|
First we set up some parameter objects for the alogrithm.
|
2022-01-17 17:40:51 +01:00
|
|
|
|
#+begin_src jupyter-python :results none
|
2021-11-12 17:49:23 +01:00
|
|
|
|
hf_system = hopsflow.SystemParams(
|
2022-01-17 17:40:51 +01:00
|
|
|
|
system.L, system.g, system.w, system.bcf_scale, params.HiP.nonlinear
|
2021-11-12 17:49:23 +01:00
|
|
|
|
)
|
|
|
|
|
|
2022-01-17 17:40:51 +01:00
|
|
|
|
η = params.Eta
|
|
|
|
|
ξ = params.EtaTherm
|
2021-11-12 17:49:23 +01:00
|
|
|
|
ξ.calc_deriv = True
|
2022-01-17 17:40:51 +01:00
|
|
|
|
ξ.set_scale(1)
|
|
|
|
|
|
2021-11-12 17:49:23 +01:00
|
|
|
|
hf_therm = hopsflow.ThermalParams(ξ=ξ, τ=result.τ, num_deriv=False)
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
Now we can apply our tooling to one trajectory for testing.
|
|
|
|
|
#+begin_src jupyter-python
|
|
|
|
|
hf_sample_run = hopsflow.HOPSRun(result.ψ[0], result.ψ_1[0], hf_system)
|
2022-01-17 17:40:51 +01:00
|
|
|
|
hf_sample_run_therm = hopsflow.ThermalRunParams(hf_therm, result.seeds[0])
|
2021-11-12 17:49:23 +01:00
|
|
|
|
first_flow = hopsflow.flow_trajectory_coupling(hf_sample_run, hf_system)
|
|
|
|
|
first_flow_therm = hopsflow.flow_trajectory_therm(hf_sample_run, hf_sample_run_therm)
|
|
|
|
|
plt.plot(result.τ, first_flow)
|
|
|
|
|
plt.plot(result.τ, first_flow_therm)
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
:RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
| <matplotlib.lines.Line2D | at | 0x7fb5394c5070> |
|
|
|
|
|
[[file:./.ob-jupyter/24faa804549a4784f9a9c00671fb2deac9bfda98.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
And now for all trajectories.
|
|
|
|
|
#+begin_src jupyter-python
|
|
|
|
|
full_flow = hopsflow.heat_flow_ensemble(
|
2022-01-17 17:40:51 +01:00
|
|
|
|
iter(result.ψ),
|
|
|
|
|
iter(result.ψ_1),
|
|
|
|
|
hf_system,
|
|
|
|
|
result.N,
|
|
|
|
|
(iter(result.seeds), hf_therm),
|
|
|
|
|
every=result.N // 10,
|
|
|
|
|
save="results/flow.npy",
|
2021-11-12 17:49:23 +01:00
|
|
|
|
)
|
|
|
|
|
|
2022-01-17 17:40:51 +01:00
|
|
|
|
with ut.hiro_style():
|
|
|
|
|
_, ax = ut.plot_convergence(result.τ, full_flow, transform=lambda y: -y)
|
|
|
|
|
ax.legend()
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
[[file:./.ob-jupyter/8fee0d1878264a802901feb92d199a282705ddd4.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
|
2022-01-17 17:40:51 +01:00
|
|
|
|
|
2021-11-12 17:49:23 +01:00
|
|
|
|
We can integrate the energy change in the bath:
|
|
|
|
|
#+begin_src jupyter-python
|
2022-01-17 17:40:51 +01:00
|
|
|
|
e_bath = util.integrate_array(-full_flow[-1][1], result.τ)
|
2021-11-12 17:49:23 +01:00
|
|
|
|
plt.plot(result.τ, e_bath)
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
:RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
| <matplotlib.lines.Line2D | at | 0x7fb528bcf130> |
|
|
|
|
|
[[file:./.ob-jupyter/5111182f49976baafa76e776cae21ad1f0f1d7a3.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
** Calculate the Interaction Energy
|
|
|
|
|
First we calculate it from energy conservation.
|
|
|
|
|
#+begin_src jupyter-python
|
2022-01-17 17:40:51 +01:00
|
|
|
|
e_int = (1/2 - e_sys - e_bath).real
|
2021-11-12 17:49:23 +01:00
|
|
|
|
plt.plot(result.τ, e_int)
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
:RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
| <matplotlib.lines.Line2D | at | 0x7fb528ab1400> |
|
|
|
|
|
[[file:./.ob-jupyter/f469dd77c5ee1ce66a175653df1cb91b64170bcd.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
And then from first principles:
|
|
|
|
|
#+begin_src jupyter-python
|
2022-01-17 17:40:51 +01:00
|
|
|
|
_, e_int_ex, _ = hopsflow.interaction_energy_ensemble(
|
2022-01-18 15:17:22 +01:00
|
|
|
|
result.ψ,
|
|
|
|
|
result.ψ_1,
|
|
|
|
|
hf_system,
|
|
|
|
|
result.N,
|
|
|
|
|
(result.seeds, hf_therm),
|
|
|
|
|
save="results/interaction_energy.npy",
|
2021-11-12 17:49:23 +01:00
|
|
|
|
)
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
|
|
|
|
|
And both together:
|
|
|
|
|
#+begin_src jupyter-python
|
|
|
|
|
plt.plot(result.τ, e_int, label="integrated")
|
|
|
|
|
plt.plot(result.τ, e_int_ex, label="exact")
|
|
|
|
|
plt.legend()
|
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
|
|
#+RESULTS:
|
|
|
|
|
:RESULTS:
|
2022-01-18 15:17:22 +01:00
|
|
|
|
: <matplotlib.legend.Legend at 0x7fb51f5cac70>
|
|
|
|
|
[[file:./.ob-jupyter/d3c14fd1c02823517a67914c92cb951ded6fac15.svg]]
|
2021-11-12 17:49:23 +01:00
|
|
|
|
:END:
|
|
|
|
|
|
|
|
|
|
Seems to work :P.
|
|
|
|
|
|
2022-01-17 17:40:51 +01:00
|
|
|
|
* Close the Data File
|
|
|
|
|
We need to release the hold on the file.
|
|
|
|
|
#+begin_src jupyter-python :results none
|
|
|
|
|
result.hd.close()
|
2021-11-12 17:49:23 +01:00
|
|
|
|
#+end_src
|