master-thesis/python/energy_flow_proper/01_zero_temperature/notebook.org

397 lines
12 KiB
Org Mode
Raw Normal View History

2021-11-11 16:10:25 +01:00
#+PROPERTY: header-args :session zero_temp_new :kernel python :pandoc t
2021-11-05 10:19:19 +01:00
* Configuration and Setup
The main process configuration is to be found [[file:stg.py][here]].
** Stochastic Processes
We then proceed to initialize the stochastic processes.
#+begin_src vterm
python ../hops/sp.py -s stg.py
#+end_src
#+RESULTS:
:RESULTS:
Linux ArLeenUX 5.14.14-zen1 x86_64
2021-11-11 16:10:25 +01:00
16:06:06 up 3 days 23:48, 1 user, load average: 0.81, 1.19, 1.21
2021-11-05 10:19:19 +01:00
impure  ~/D/P/U/m/m/p/e/01_zero_temperature  python ../hops/sp.py -s stg.py
2021-11-11 16:10:25 +01:00
StocProc found in database 'SPCache' at '.'
2021-11-05 10:19:19 +01:00
:END:
The stochastic process is initialized and cached in ~./SPCache~.
* Hops Integration
We can use multiple avenues.
** Local Integration
#+begin_src vterm :term-name integration
python ../hops/hi.py -s stg.py
#+end_src
#+RESULTS:
:RESULTS:
Linux ArLeenUX 5.14.14-zen1 x86_64
2021-11-11 16:10:25 +01:00
16:06:15 up 3 days 23:48, 1 user, load average: 1.07, 1.23, 1.22
2021-11-05 10:19:19 +01:00
impure  ~/D/P/U/m/m/p/e/01_zero_temperature  python ../hops/hi.py -s stg.py
run integrate
init Hi class, use 464 equation
is up event is False
wait ...
[in server process] add args to server ...
[in server process] befor bring him up
2021-11-11 16:10:25 +01:00
JobManager started on ArLeenUX:46870 (bytearray(b'HOPS46870'))
2021-11-05 10:19:19 +01:00
hi server is up
[in server process] set is_up
is up event is now True
2021-11-11 16:10:25 +01:00
[TET 12.69ms [0.0c/s] TTG -- 0.0%
2021-11-05 10:19:19 +01:00
2021-11-11 16:10:25 +01:00
/nix/store/5v3326rzsryzdkk2q5kimqvf0i20wvzv-python3-3.9.4-env/lib/python3.9/site
anager/jobmanager.py:130: UserWarning: num_threads could not be set, MKL / openb
2021-11-05 10:19:19 +01:00
warnings.warn("num_threads could not be set, MKL / openblas not found")
2021-11-11 16:10:25 +01:00
/nix/store/5v3326rzsryzdkk2q5kimqvf0i20wvzv-python3-3.9.4-env/lib/python3.9/site
anager/jobmanager.py:130: UserWarning: num_threads could not be set, MKL / openb
2021-11-05 10:19:19 +01:00
warnings.warn("num_threads could not be set, MKL / openblas not found")
2021-11-11 16:10:25 +01:00
/nix/store/5v3326rzsryzdkk2q5kimqvf0i20wvzv-python3-3.9.4-env/lib/python3.9/site
anager/jobmanager.py:130: UserWarning: num_threads could not be set, MKL / openb
2021-11-05 10:19:19 +01:00
warnings.warn("num_threads could not be set, MKL / openblas not found")
2021-11-11 16:10:25 +01:00
/nix/store/5v3326rzsryzdkk2q5kimqvf0i20wvzv-python3-3.9.4-env/lib/python3.9/site
[TET 1.01s [0.0c/s] TTG -- 0.0%
res_q #0 0/s 0kB|rem.:500, done:0, failed:0, prog.:0
w1:00:00:46 [14.7c/min] #11 - 2.25s [245.0c/s] [==================>
w2:00:00:46 [15.0c/min] #11 - 1.90s [241.6c/s] [===============>
w1:00:00:47 [14.7c/min] #11 - 3.25s [255.6c/s] [============================>
] TTG 1.00s4.8c/min] #11 - 1.33s [221.7c/s] [=========>
w2:00:00:47 [15.0c/min] #11 - 2.91s [243.3c/s] [========================>
] TTG 2.00s [57.3c/min] TTG 00:07:58 8.8% ETA 20211110_16:15:03
w3:00:00:47 [14.7c/min] #11 - 1.67s [264.0c/s] [==============>
] TTG 3.00sGB/s 315.9GB|rem.:452, done:44, failed:0, prog.:4
w4:00:00:47 [14.8c/min] #11 - 2.33s [231.9c/s] [==================>
w1:00:00:48 [14.8c/min] #12 - 292.64ms [160.6c/s] [=>
] TTG 6.00s326.1GB/s
w2:00:00:48 [15.0c/min] #11 - 3.91s [231.6c/s] [==============================>
] TTG 1.00s [57.3c/min] TTG 00:07:58 8.8% ETA 20211110_16:15:04
w3:00:00:48 [14.7c/min] #11 - 2.67s [238.4c/s] [=====================>
w1:00:08:43 [15.9c/min] #126 - [TET 996.21ms [0.0c/s] TTG -- 0.0% ETA -- ORT --]
w2:00:08:43 [15.7c/min] #125 - [TET 2.26s [0.0c/s] TTG -- 0.0% ETA -- ORT --]
w3:00:08:43 [15.5c/min] #124 - [TET 1.69s [0.0c/s] TTG -- 0.0% ETA -- ORT --]
w4:00:08:43 [16.5c/min] #125 - [TET 667.44ms [0.0c/s] TTG -- 0.0% ETA -- ORT --]
local res_q 0 344GB/s
,********************************.00ms---------100%---------ETA-20211110_16:15:01-ORT-00:08:43]
,********************************0, done:500, failed:0, prog.:0
,** the client has finished early! stop the server
,********************************
,********************************
[TET-00:08:44-----[1.0c/s]-TTG-0.00ms---------100%---------ETA-20211110_16:15:02-ORT-00:08:44]
res_q #0 7.918GB/s 3.506TB|rem.:0, done:500, failed:0, prog.:0
[in server process] server has joined!
2021-11-05 10:19:19 +01:00
############## in JM SERVER EXIT
2021-11-11 16:10:25 +01:00
HI_Server start at 2021-11-10 16:06:18.129421 | runtime 5.260e+02s
HI_Server total number of jobs : 500
| processed : 500
| succeeded : 500
| failed : 0
| timing in sec: min 2.973e+00 | max 7.906e+00 | avr 4.164e+00
| not processed : 0
| queried : 0
| not queried yet : 0
2021-11-05 10:19:19 +01:00
,* has joined
2021-11-11 16:10:25 +01:00
server process is not running anymore (exit with 0)
2021-11-05 10:19:19 +01:00
:END:
And there we go. It is better to run the above command in a
vterm-session.
** Remote/Distributed Integration
We start the server locally.
#+begin_src vterm :term-name local-server
python ../hops/hi.py -s stg.py server
#+end_src
#+RESULTS:
:RESULTS:
Linux ArLeenUX 5.14.14-zen1 x86_64
2021-11-11 16:10:25 +01:00
18:00:32 up 4 days 1:42, 1 user, load average: 2.45, 2.86, 2.99
2021-11-05 10:19:19 +01:00
impure  ~/D/P/U/m/m/p/e/01_zero_temperature  python ../hops/hi.py -s stg.py server
run server
init Hi class, use 464 equation
2021-11-11 16:10:25 +01:00
JobManager started on ArLeenUX:35254 (bytearray(b'SBM2'))
2021-11-05 10:19:19 +01:00
hi server is running
2021-11-11 16:10:25 +01:00
[TET-00:06:01-----[2.5c/s]-TTG-0.00ms---------100%---------ETA-20211110_18:06:38-ORT-00:06:01]
res_q #0 17.85GB/s 3.506TB|rem.:0, done:500, failed:0, prog.:0
2021-11-05 10:19:19 +01:00
############## in JM SERVER EXIT
2021-11-11 16:10:25 +01:00
HI_Server start at 2021-11-10 18:00:36.345825 | runtime 3.640e+02s
HI_Server total number of jobs : 500
| processed : 500
| succeeded : 500
2021-11-05 10:19:19 +01:00
| failed : 0
2021-11-11 16:10:25 +01:00
| timing in sec: min 3.446e+00 | max 6.235e+00 | avr 5.008e+00
| not processed : 0
2021-11-05 10:19:19 +01:00
| queried : 0
2021-11-11 16:10:25 +01:00
| not queried yet : 0
2021-11-05 10:19:19 +01:00
:END:
And jack in with a remote client. In this case my box at home.
* Using the Data
2021-11-11 16:10:25 +01:00
** Jupyter Setup
#+begin_src jupyter-python
%load_ext autoreload
%autoreload 2
import matplotlib.pyplot as plt
2021-11-11 16:39:02 +01:00
%config InlineBackend.figure_formats = ['svg']
%matplotlib inline
2021-11-11 16:10:25 +01:00
import numpy as np
plt.style.use('ggplot')
import qutip
#+end_src
#+RESULTS:
2021-11-11 16:39:02 +01:00
: The autoreload extension is already loaded. To reload it, use:
: %reload_ext autoreload
2021-11-11 16:10:25 +01:00
** Check the Freshness of the Data
This doesn't check for modifications in this file though!
#+begin_src jupyter-python
from deps import deps
deps.report()
#+end_src
#+RESULTS:
: Is fresh: True
: Overall Hash: b69f09d7a1ad29b11fe2af2e1574161333632d46
~True~ means that no important code has changed. In this case it even
checks if we have all the samples.
** Load the Data
Stghelper seems to be what we want.
#+begin_src jupyter-python
import stg_helper
import stg
import hopsflow
from hopsflow import util
#+end_src
#+RESULTS:
Now let's load the system parameters.
#+begin_src jupyter-python
system_params = stg_helper.get_system_param(stg)
system_params
#+end_src
#+RESULTS:
#+begin_example
H_dynamic : []
H_sys : Operator with format 'coo' and shape(2, 2)
(0, 0) -0.5
(1, 1) 0.5
L : Operator with format 'coo' and shape(2, 2)
(0, 1) 0.5
(1, 0) 0.5
bcf_scale : 0.8
g : [-0.06469402-0.02291455j -0.51837826-0.63817493j -0.9180341 -0.03207301j
0.79032868-3.79162312j 0.92537272+5.45668527j 7.74372319-0.97260702j]
psi0 : [0 1]
w : [ 0.33112135 +0.0369207j 1.4655583 +0.35463741j
20.83418848+27.9612112j 3.94583654 +1.66419407j
13.81649632+13.01348981j 8.09528316 +5.28092745j]
--- extra info ---
T : 0.0
T_method : stoc_pot
gw_info : None
len_gw : None
#+end_example
Now we read the trajectory data.
#+begin_src jupyter-python
class result:
with stg_helper.get_hierarchy_data(stg, read_only=True) as hd:
N = hd.get_samples()
τ = hd.get_time()
ρ = hd.get_rho_t()
ψ_1 = np.array(hd.aux_states)[0:N]
ψ = np.array(hd.stoc_traj)[0:N]
#+end_src
#+RESULTS:
** Calculate System Energy
Simple sanity check.
#+begin_src jupyter-python
e_sys = util.operator_expectation(result.ρ, system_params.H_sys.todense())
plt.plot(result.τ, e_sys)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88c86eb80> |
[[file:./.ob-jupyter/5b677bedf5ac789f36752d1ab34a08c7967f7e54.svg]]
2021-11-11 16:10:25 +01:00
:END:
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.
#+begin_src jupyter-python
np.linalg.eig(system_params.H_sys.todense())[0]
#+end_src
#+RESULTS:
: array([-0.5, 0.5])
The begin and and values of the system energy expectation are.
#+begin_src jupyter-python
e_sys[0], e_sys[-1]
#+end_src
#+RESULTS:
| 0.5 | -0.44786036208449925 |
And the total energy lost is:
#+begin_src jupyter-python
e_sys[0] - e_sys[-1]
#+end_src
#+RESULTS:
: 0.9478603620844992
We do start in the state.
#+begin_src jupyter-python
system_params.psi0
#+end_src
#+RESULTS:
: 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.
#+begin_src jupyter-python
hf_system = hopsflow.SystemParams(
system_params.L.todense(), stg.__g, stg.__w, stg.__bcf_scale, stg.__HI_nonlinear
)
#+end_src
#+RESULTS:
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)
first_flow = hopsflow.flow_trajectory_coupling(hf_sample_run, hf_system)
plt.plot(result.τ, first_flow)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88c94aa00> |
[[file:./.ob-jupyter/960bb80995da8078fd443f2f22142c6b1ebb6286.svg]]
2021-11-11 16:10:25 +01:00
:END:
And now for all trajectories.
#+begin_src jupyter-python
full_flow = hopsflow.heat_flow_ensemble(result.ψ, result.ψ_1, hf_system)
plt.plot(result.τ, full_flow)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88cb9ec10> |
[[file:./.ob-jupyter/d25ba1fef373188a056f2e0d6a4c5f4a92510ea4.svg]]
2021-11-11 16:10:25 +01:00
:END:
We can integrate the energy change in the bath:
#+begin_src jupyter-python
e_bath = util.integrate_array(-full_flow, result.τ)
plt.plot(result.τ, e_bath)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88ebd6220> |
[[file:./.ob-jupyter/90dd6b7d95f9dad5d70aea5d76c16a1ce4a37c06.svg]]
2021-11-11 16:10:25 +01:00
:END:
** Calculate the Interaction Energy
First we calculate it from energy conservation.
#+begin_src jupyter-python
e_int = 1/2 - e_sys - e_bath
plt.plot(result.τ, e_int)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88eaca400> |
[[file:./.ob-jupyter/6d558a7d7d44f57dc0d2887138d004ae28e89c3d.svg]]
2021-11-11 16:10:25 +01:00
:END:
And then from first principles:
#+begin_src jupyter-python
e_int_ex = hopsflow.interaction_energy_ensemble(result.ψ, result.ψ_1, hf_system)
plt.plot(result.τ, e_int_ex)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88cb120d0> |
[[file:./.ob-jupyter/c97181cc348cc23ea6d58a6e438142e93720e021.svg]]
2021-11-11 16:10:25 +01:00
:END:
And both together:
#+begin_src jupyter-python
plt.plot(result.τ, e_int)
plt.plot(result.τ, e_int_ex)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88cb09160> |
[[file:./.ob-jupyter/0af49b86e497454d433dc6b73558e7ab843e62c5.svg]]
2021-11-11 16:10:25 +01:00
:END:
** Scratch
So the ~G~ and ~W~ do function as expected
#+begin_src jupyter-python
t = np.linspace(0, stg.t_max, 100)
#plt.plot(t, stg.__bcf(t).real)
plt.plot(t, stg.__bcf(t).imag)
plt.plot(t, hopsflow.util.α_apprx(t, stg.__g, stg.__w).imag)
#+end_src
#+RESULTS:
:RESULTS:
2021-11-11 16:39:02 +01:00
| <matplotlib.lines.Line2D | at | 0x7fb88c76ca00> |
[[file:./.ob-jupyter/bcde1eb021f8bf933d77cec89f448be7707205c8.svg]]
2021-11-11 16:10:25 +01:00
:END:
#+begin_src jupyter-python
import os
path = os.path.dirname(hopsflow.__file__)
path
#+end_src
#+RESULTS:
: /home/hiro/Documents/Projects/UNI/master/masterarb/python/energy_flow_proper/hopsflow
* Update Dependency Hash
When we're done we update the dependency hash. This helps us to check
if we have to recompute anything later on.
#+begin_src jupyter-python
deps.write_hash()
deps.get_hash()[0]
#+end_src
#+RESULTS:
: b69f09d7a1ad29b11fe2af2e1574161333632d46