15 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
z16zulpojyom5baq0jum
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.8\) | \(ω_c=2\) |
Load the Data
from hopsflow import hopsflow, util
from hops.core.hierarchyLib import HI
Now we read the trajectory data.
class result:
with HI(params, 500).get_data(read_only=True) as hd:
N = hd.samples
τ = hd.get_time()
ρ = hd.get_rho_t()
ψ_1 = np.array(hd.aux_states)[0:N]
ψ = np.array(hd.stoc_traj)[0:N]
fs.tex_value(result.N, prefix="N=", save="samples")
[0;31m---------------------------------------------------------------------------[0m [0;31mRuntimeError[0m Traceback (most recent call last) [0;32m/tmp/ipykernel_86433/975144810.py[0m in [0;36m<module>[0;34m[0m [0;32m----> 1[0;31m [0;32mclass[0m [0mresult[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 2[0m [0;32mwith[0m [0mHI[0m[0;34m([0m[0mparams[0m[0;34m,[0m [0;36m500[0m[0;34m)[0m[0;34m.[0m[0mget_data[0m[0;34m([0m[0mread_only[0m[0;34m=[0m[0;32mTrue[0m[0;34m)[0m [0;32mas[0m [0mhd[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [1;32m 3[0m [0mN[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0msamples[0m[0;34m[0m[0;34m[0m[0m [1;32m 4[0m [0mτ[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0mget_time[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 5[0m [0mρ[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0mget_rho_t[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0;32m/tmp/ipykernel_86433/975144810.py[0m in [0;36mresult[0;34m()[0m [1;32m 2[0m [0;32mwith[0m [0mHI[0m[0;34m([0m[0mparams[0m[0;34m,[0m [0;36m500[0m[0;34m)[0m[0;34m.[0m[0mget_data[0m[0;34m([0m[0mread_only[0m[0;34m=[0m[0;32mTrue[0m[0;34m)[0m [0;32mas[0m [0mhd[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [1;32m 3[0m [0mN[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0msamples[0m[0;34m[0m[0;34m[0m[0m [0;32m----> 4[0;31m [0mτ[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0mget_time[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 5[0m [0mρ[0m [0;34m=[0m [0mhd[0m[0;34m.[0m[0mget_rho_t[0m[0;34m([0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [1;32m 6[0m [0mψ_1[0m [0;34m=[0m [0mnp[0m[0;34m.[0m[0marray[0m[0;34m([0m[0mhd[0m[0;34m.[0m[0maux_states[0m[0;34m)[0m[0;34m[[0m[0;36m0[0m[0;34m:[0m[0mN[0m[0;34m][0m[0;34m[0m[0;34m[0m[0m [0;32m/nix/store/xyw00clxkmn0hgfw4lr7plyn61clhxyy-python3-3.9.9-env/lib/python3.9/site-packages/hops/core/hierarchyData.py[0m in [0;36mget_time[0;34m(self)[0m [1;32m 757[0m [0;34m[0m[0m [1;32m 758[0m [0;32mif[0m [0;32mnot[0m [0mself[0m[0;34m.[0m[0mtime_set[0m[0;34m:[0m[0;34m[0m[0;34m[0m[0m [0;32m--> 759[0;31m [0;32mraise[0m [0mRuntimeError[0m[0;34m([0m[0;34m"can not get time, time has not been set yet."[0m[0;34m)[0m[0;34m[0m[0;34m[0m[0m [0m[1;32m 760[0m [0;32mreturn[0m [0mself[0m[0;34m.[0m[0mtime[0m[0;34m[[0m[0;34m:[0m[0;34m][0m [0;31m# type: ignore[0m[0;34m[0m[0;34m[0m[0m [1;32m 761[0m [0;34m[0m[0m [0;31mRuntimeError[0m: can not get time, time has not been set yet.
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])
The begin and and values of the system energy expectation are.
e_sys[0].real, e_sys[-1].real
0.5 | -0.44770384926040235 |
And the total energy lost is:
e_sys[0].real - e_sys[-1].real
0.9477038492604024
We do start in the state.
system.psi0
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 // 4, 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:
e_bath = util.integrate_array(-full_flow[-1][1], result.τ)
plt.plot(result.τ, e_bath)
<matplotlib.lines.Line2D | at | 0x7f21fed6e550> |
Calculate the Interaction Energy
First we calculate it from energy conservation.
e_int = (1/2 - e_sys - e_bath).real
with fs.hiro_style():
plt.plot(result.τ, e_int)
And then from first principles:
_, e_int_ex, σ_e_int_ex = hopsflow.interaction_energy_ensemble(result.ψ, result.ψ_1, hf_system, result.N)
with fs.hiro_style():
plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, ecolor="yellow")
100% 999/999 [00:06<00:00, 166.19it/s]
And both together:
with fs.hiro_style():
plt.errorbar(result.τ, e_int_ex, yerr=σ_e_int_ex, ecolor="yellow", label="direct")
plt.xlabel("$τ$")
plt.ylabel(r"$\langle H_I\rangle$")
plt.plot(result.τ, e_int, label="from energy conservation")
plt.legend()
plt.gcf().set_size_inches(fs.get_figsize(239, 1, .8))
fs.export_fig("interaction")