17 KiB
Configuration and Setup
This will be tangled into the config file that can be used with the HOPS cli.
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 = 2
s = 1
# The BCF fit
bcf_terms = 5
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.5,
T=0,
)
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=.5 * g, w=w, p=1, q=0.5, kfac=1.7
),
),
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-5,
intpl_tol=1e-5,
negative_frequencies=False,
),
EtaTherm=None,
)
Hops Integration
We can use multiple avenues.
Local Integration
hi 500 integrate
Linux ArLeenUX 5.16.8-zen1 x86_64 15:57:39 up 1 day 5:47, 1 user, load average: 1.55, 1.58, 1.91 impure ~/D/P/U/m/m/p/e/01_zero_temperature hi 500 integrate Loading the configuration from config.py. This might take a while… -
And there we go. It is better to run the above command in a vterm-session.
Remote/Distributed Integration
We start the server locally.
hi 1000 start-server
Linux ArLeenUX 5.15.11-zen1 x86_64 16:34:02 up 2 days 19:58, 1 user, load average: 1.08, 1.67, 2.52 impure ~/D/P/U/m/m/p/e/01_zero_temperature hi 1000 start-server Loading the configuration from config.py. This might take a while… / JobManager started on ArLeenUX:42524 (bytearray(b'hierarchy')) [TET-00:12:05–[43.6c/min]-TTG-0.00ms————————-100%————————-ETA-20220117_16:46:11-ORT-00:12:05] res_q #0 14.84GB/s 10.51TB|rem.:0, done:500, failed:0, prog.:0
############## in JM SERVER EXIT
HIServer start at 2022-01-17 16:34:05.075876 | runtime 7.280e+02s HIServer total number of jobs : 500
processed : 500 | ||
succeeded : 500 | ||
failed : 0 | ||
timing in sec: min 1.386e+01 | max 4.145e+01 | avr 2.478e+01 |
not processed : 0 | ||
queried : 0 | ||
not queried yet : 0 |
And jack in with a remote client. In this case my box at home.
Client
Starting a client is trivial.
client localhost
Linux ArLeenUX 5.16.8-zen1 x86_64 16:06:00 up 5:55, 1 user, load average: 1.29, 0.91, 1.18 impure ~/D/P/U/m/m/p/e/01_zero_temperature client localhost connection to (('localhost', 42524), 'hierarchy') could not be established due to '<class 'ConnectionRefusedError' >' File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/jobmanager/jobmana ger.py", line 343, in connect self.manager_objects = self.create_manager_objects() connection refused error FAILED to connect to (('localhost', 42524), 'hierarchy') Traceback (most recent call last): File "nix/store/cphpkvyd3ni0b3b9nfvbnh1xc3cqc4i2-python3.9-hops-1.0/bin.client-wrapped", line 9, in <module> sys.exit(main()) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/cli/client.py", line 86, in main typer.run(start_client) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 864, in run app() File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 214, in call return get_command(self)(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1128, in call return self.main(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/typer/main.py", line 500, in wrapper return callback(**use_params) # type: ignore File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/cli/client.py", line 82, in start_client cl.start() File "/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/jobmanager/jobma nager.py", line 657, in start raise JMConnectionError("Can not start Client with no connection to server (shared objetcs are not available)" ) ConnectionError: Can not start Client with no connection to server (shared objetcs are not available)
Using the Data
Jupyter Setup
import matplotlib.pyplot as plt
import numpy as np
import utilities as ut
import figsaver as fs
Let's export some infos about the model to TeX.
fs.tex_value(system.bcf_scale, prec=1, save="bcf_scale", prefix="η="), fs.tex_value(
wc, prec=0, save="cutoff_freq", prefix="ω_c="
)
\(η=0.5\) | \(ω_c=2\) |
\(η=0.5\) | \(ω_c=2\) |
Load the Data
from hopsflow import hopsflow, util
from hops.core.hierarchyData import HIMetaData
Now we read the trajectory data.
class result:
hd = HIMetaData("data", ".").get_HIData(params, read_only=True)
N = 8000
τ = hd.get_time()
ψ_1 = hd.aux_states
ψ = hd.stoc_traj
fs.tex_value(result.N, prefix="N=", save="samples")
\(N=8000\) \(N=8000\)
with fs.hiro_style():
ts = np.linspace(0, 4, 1000)
fs.plot_complex(ts, hops.util.bcf.OhmicBCF_zeroTemp(
s,
1,
wc,
)(ts))
plt.title(r"$α$")
plt.xlabel(r"$τ$")
plt.title(rf"$J=η Γ(s+1) / (1 + iω_c τ)^{{s+1}}$")
plt.text(1, 1, rf"$ω_c={wc}$, $s={s}$")
plt.gcf().set_size_inches(fs.get_figsize(200, 1, .8))
fs.export_fig("ohmic_bcf")
with fs.hiro_style():
ωs = np.linspace(0, 50, 1000)
plt.plot(ωs, hops.util.bcf.OhmicSD_zeroTemp(
s,
1,
wc,
)(ωs))
plt.gcf().set_size_inches(fs.get_figsize(200, 1, .8))
plt.title(rf"$J=η e^{{-ω/ω_c}} ω^s$")
plt.text(25, .5, rf"$ω_c={wc}$, $s={s}$")
plt.xlabel(r"$ω$")
fs.export_fig("ohmic_sd")
Calculate System Energy
Simple sanity check.
_, e_sys, σ_e_sys = util.operator_expectation_ensemble(
iter(result.ψ),
system.H_sys,
result.N,
params.HiP.nonlinear,
save="./results/energy.npy"
)
with fs.hiro_style():
plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
plt.errorbar(result.τ, e_sys.real, yerr=σ_e_sys.real, ecolor="yellow")
plt.ylabel(r"$\langle H_S\rangle$")
plt.xlabel(r"$τ$")
fs.export_fig("system_energy")
The energy bleeds out of the system. We don't reach the steady state yet. Also we don't loose all the energy.
The energy eigenvalues of the system are.
np.linalg.eig(system.H_sys)[0]
array([-0.5, 0.5]) array([-0.5, 0.5])
The begin and and values of the system energy expectation are.
e_sys[0].real, e_sys[-1].real
0.5 | -0.47523035186448653 |
0.5 | -0.47523035186448653 |
And the total energy lost is:
e_sys[0].real - e_sys[-1].real
0.9752303518644865 0.9752303518644865
We do start in the state.
system.psi0
array([0, 1]) array([0, 1])
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.
hf_system = hopsflow.SystemParams(
system.L, system.g, system.w, system.bcf_scale, params.HiP.nonlinear
)
Now we can apply our tooling to one trajectory for testing.
hf_sample_run = hopsflow.HOPSRun(result.ψ[0], result.ψ_1[0], hf_system)
first_flow = hopsflow.flow_trajectory_coupling(hf_sample_run, hf_system)
with fs.hiro_style():
plt.plot(result.τ, first_flow)
And now for all trajectories.
full_flow = hopsflow.heat_flow_ensemble(
result.ψ, result.ψ_1, hf_system, result.N, every=result.N // 2, save="results/flow_1.npy"
)
with fs.hiro_style():
fig, ax = fs.plot_convergence(result.τ, full_flow, transform=lambda y: -y)
fig.set_size_inches(fs.get_figsize(239, 1, .8))
ax.legend()
ax.set_xlabel("$τ$")
ax.set_ylabel("$-J$")
fs.export_fig("flow", fig)
We can integrate the energy change in the bath:
import scipy.integrate
e_bath = np.array([0] + [
scipy.integrate.simpson(-full_flow[-1][1][:i], result.τ[:i])
for i in range(1, len(result.τ))
])
plt.plot(result.τ, e_bath)
σ_e_bath = np.sqrt(np.array([0] + [
scipy.integrate.simpson(full_flow[-1][2][:i]**2, result.τ[:i])
for i in range(1, len(result.τ))
])).real
plt.errorbar(result.τ, e_bath, yerr=σ_e_bath, ecolor="yellow")
<ErrorbarContainer object of 3 artists>
<ErrorbarContainer object of 3 artists>
Initial Slip
bcf_im = hops.util.bcf.OhmicBCF_zeroTemp(
s,
1,
wc,
)(result.τ).imag
plt.plot(result.τ, bcf_im / np.abs(bcf_im).max())
plt.plot(result.τ, first_flow / np.abs(first_flow).max())
<matplotlib.lines.Line2D | at | 0x7f055991c700> |
<matplotlib.lines.Line2D | at | 0x7f055a2a5520> |
plt.plot(result.τ, bcf_im / np.abs(bcf_im).max())
plt.plot(result.τ, full_flow[-1][1] / np.abs(full_flow[-1][1]).max())
np.abs(bcf_im).max() / np.abs(full_flow[-1][1]).max()
3.3334210815243313
3.3334210815243313
_, L_exp_sys, σ_L_exp = util.operator_expectation_ensemble(
iter(result.ψ),
system.L @ system.L,
result.N,
params.HiP.nonlinear,
save="./results/L2.npy"
)
plt.plot(result.τ, bcf_im * L_exp_sys.real * system.bcf_scale * 2)
plt.plot(result.τ, full_flow[-1][1], linestyle="--")
<matplotlib.lines.Line2D | at | 0x7f055987d3d0> |
<matplotlib.lines.Line2D | at | 0x7f055922a880> |
import scipy.optimize
maxind = np.argmax(np.abs(full_flow[-1][1]))
res = scipy.optimize.minimize(
lambda s: np.sum(
((bcf_im * L_exp_sys.real * s * system.bcf_scale * 2 - full_flow[-1][1]) ** 2)[
0:maxind - 15
]
),
1,
tol=1e-4,
)
scale = res.x
res
fun: 0.00019313991029083397 hess_inv: array([[1.38958965]]) jac: array([3.63797881e-12]) message: 'Optimization terminated successfully.' nfev: 6 nit: 2 njev: 3 status: 0 success: True x: array([1.0465576]) fun: 0.00019313991029083397 hess_inv: array([[1.38958965]]) jac: array([3.63797881e-12]) message: 'Optimization terminated successfully.' nfev: 6 nit: 2 njev: 3 status: 0 success: True x: array([1.0465576])
plt.plot(result.τ, -bcf_im * L_exp_sys.real * 2 * system.bcf_scale * scale)
#plt.plot(result.τ, -bcf_im * L_exp_sys.real * 2 * system.bcf_scale)
plt.plot(result.τ, -full_flow[-1][1], linestyle="--")
plt.yscale('log')
plt.plot(result.τ, np.abs(-bcf_im * L_exp_sys.real * 2 * system.bcf_scale * scale + full_flow[-1][1]))
plt.plot(result.τ, np.abs(-bcf_im * L_exp_sys.real * 2 * system.bcf_scale + full_flow[-1][1]), linestyle="--")
plt.xlim((0, .4))
plt.yscale('log')
Unscaled actually fits better for small times :P.
Calculate the Interaction Energy
First we calculate it from energy conservation.
e_int = (1/2 - e_sys - e_bath).real
σ_e_int = np.sqrt(σ_e_sys ** 2 + σ_e_bath ** 2).real
plt.errorbar(result.τ, e_int, yerr=σ_e_int, ecolor="yellow")
<ErrorbarContainer object of 3 artists>
<ErrorbarContainer object of 3 artists>
And then from first principles:
_, e_int_ex, σ_e_int_ex = hopsflow.interaction_energy_ensemble(result.ψ, result.ψ_1, hf_system, result.N, save="inten")
with fs.hiro_style():
plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, ecolor="yellow")
100% 7999/7999 [00:26<00:00, 305.42it/s]
And both together:
with fs.hiro_style():
plt.errorbar(result.τ, e_int, yerr=σ_e_int, label="from energy conservation", ecolor="yellow")
plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, label="direct", ecolor="pink")
plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
plt.legend()
plt.ylabel(r"$\langle H_I\rangle$")
plt.xlabel(r"$τ$")
fs.export_fig("interaction")