|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "a803e43a", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [ |
| 9 | + { |
| 10 | + "name": "stderr", |
| 11 | + "output_type": "stream", |
| 12 | + "text": [ |
| 13 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > already registered; second conversion method ignored.\n", |
| 14 | + " return f(*args, **kwds)\n", |
| 15 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::python::detail::container_element<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, false> > already registered; second conversion method ignored.\n", |
| 16 | + " return f(*args, **kwds)\n", |
| 17 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > > already registered; second conversion method ignored.\n", |
| 18 | + " return f(*args, **kwds)\n", |
| 19 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::python::detail::container_element<std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::vector<std::vector<float, std::allocator<float> >, std::allocator<std::vector<float, std::allocator<float> > > >, false> > already registered; second conversion method ignored.\n", |
| 20 | + " return f(*args, **kwds)\n", |
| 21 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > already registered; second conversion method ignored.\n", |
| 22 | + " return f(*args, **kwds)\n", |
| 23 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::python::detail::container_element<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, false> > already registered; second conversion method ignored.\n", |
| 24 | + " return f(*args, **kwds)\n", |
| 25 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for std::vector<std::vector<std::complex<double>, std::allocator<std::complex<double> > >, std::allocator<std::vector<std::complex<double>, std::allocator<std::complex<double> > > > > already registered; second conversion method ignored.\n", |
| 26 | + " return f(*args, **kwds)\n", |
| 27 | + "/home/alexey/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::python::detail::container_element<std::vector<std::vector<std::complex<double>, std::allocator<std::complex<double> > >, std::allocator<std::vector<std::complex<double>, std::allocator<std::complex<double> > > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::vector<std::vector<std::complex<double>, std::allocator<std::complex<double> > >, std::allocator<std::vector<std::complex<double>, std::allocator<std::complex<double> > > > >, false> > already registered; second conversion method ignored.\n", |
| 28 | + " return f(*args, **kwds)\n" |
| 29 | + ] |
| 30 | + } |
| 31 | + ], |
| 32 | + "source": [ |
| 33 | + "import numpy as np\n", |
| 34 | + "import math\n", |
| 35 | + "import matplotlib.pyplot as plt\n", |
| 36 | + "import imageio\n", |
| 37 | + "import os\n", |
| 38 | + "import time\n", |
| 39 | + "import sys\n", |
| 40 | + "\n", |
| 41 | + "from liblibra_core import *\n", |
| 42 | + "import libra_py.models.Holstein as Holstein\n", |
| 43 | + "import util.libutil as comn\n", |
| 44 | + "from libra_py import data_outs\n", |
| 45 | + "import libra_py.data_savers as data_savers\n", |
| 46 | + "\n", |
| 47 | + "import libra_py.dynamics.qtag.qtag_calc as qtag_calc\n", |
| 48 | + "import libra_py.dynamics.qtag.qtag_init as qtag_init\n", |
| 49 | + "import libra_py.dynamics.qtag.qtag_mom as qtag_mom\n", |
| 50 | + "import libra_py.dynamics.qtag.qtag_prop as qtag_prop\n", |
| 51 | + "import libra_py.dynamics.qtag.save as save" |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": 2, |
| 57 | + "id": "fc9c9952", |
| 58 | + "metadata": {}, |
| 59 | + "outputs": [], |
| 60 | + "source": [ |
| 61 | + "class tmp:\n", |
| 62 | + " pass\n", |
| 63 | + "\n", |
| 64 | + "#Holstein5 from libra_py/models/Hostein.py\n", |
| 65 | + "def holstein_mimic(q, params, full_id):\n", |
| 66 | + " critical_params = [\"E_n\", \"x_n\", \"k_n\" ]\n", |
| 67 | + " default_params = { \"V\": [ [0.001, 0.001, 0.001, 0.001], [0.001, 0.001, 0.001, 0.001],\n", |
| 68 | + " [0.001, 0.001, 0.001, 0.001], [0.001, 0.001, 0.001, 0.001] ],\n", |
| 69 | + " \"alpha\": [ [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00],\n", |
| 70 | + " [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00] ],\n", |
| 71 | + " \"x_nm\": [ [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00],\n", |
| 72 | + " [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00] ],\n", |
| 73 | + " }\n", |
| 74 | + " comn.check_input(params, default_params, critical_params)\n", |
| 75 | + "\n", |
| 76 | + " E_n = params[\"E_n\"]\n", |
| 77 | + " x_n = params[\"x_n\"]\n", |
| 78 | + " k_n = params[\"k_n\"]\n", |
| 79 | + " V = params[\"V\"]\n", |
| 80 | + " alpha = params[\"alpha\"]\n", |
| 81 | + " x_nm = params[\"x_nm\"]\n", |
| 82 | + " \n", |
| 83 | + " n = len(E_n)\n", |
| 84 | + "\n", |
| 85 | + " Hdia = CMATRIX(n,n)\n", |
| 86 | + " Sdia = CMATRIX(n,n)\n", |
| 87 | + " d1ham_dia = CMATRIXList(); d1ham_dia.append( CMATRIX(n,n) )\n", |
| 88 | + " dc1_dia = CMATRIXList(); dc1_dia.append( CMATRIX(n,n) )\n", |
| 89 | + "\n", |
| 90 | + " #indx = 0\n", |
| 91 | + " Id = Cpp2Py(full_id)\n", |
| 92 | + " indx = Id[-1]\n", |
| 93 | + "\n", |
| 94 | + " x = q.col(indx).get(0)\n", |
| 95 | + "\n", |
| 96 | + " Sdia.identity()\n", |
| 97 | + "\n", |
| 98 | + " for i in range(n):\n", |
| 99 | + " Hdia.set(i,i, (E_n[i] + 0.5*k_n[i]*(x - x_n[i])**2) * (1.0+0.0j) )\n", |
| 100 | + "\n", |
| 101 | + " for i in range(n):\n", |
| 102 | + " for j in range(n):\n", |
| 103 | + " if i!=j:\n", |
| 104 | + " Hdia.set(i,j, V[i][j] * math.exp(-alpha[i][j] * (x-x_nm[i][j])**2 ) * (1.0+0.0j) )\n", |
| 105 | + "\n", |
| 106 | + " for k in [0]:\n", |
| 107 | + " # d Hdia / dR_0\n", |
| 108 | + " for i in range(n):\n", |
| 109 | + " d1ham_dia[k].set(i,i, (k_n[i] * (x - x_n[i]))*(1.0+0.0j) )\n", |
| 110 | + "\n", |
| 111 | + " for k in [0]:\n", |
| 112 | + " for i in range(n):\n", |
| 113 | + " for j in range(n):\n", |
| 114 | + " if i!=j:\n", |
| 115 | + " d1ham_dia[k].set(i,j, -2.0*alpha[i][j] * (x-x_nm[i][j]) * V[i][j] * math.exp(-alpha[i][j] * (x-x_nm[i][j])**2 ) * (1.0+0.0j) )\n", |
| 116 | + "\n", |
| 117 | + " obj = tmp()\n", |
| 118 | + " obj.ham_dia = Hdia\n", |
| 119 | + " obj.ovlp_dia = Sdia\n", |
| 120 | + " obj.d1ham_dia = d1ham_dia\n", |
| 121 | + " obj.dc1_dia = dc1_dia\n", |
| 122 | + "\n", |
| 123 | + " return obj" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": 3, |
| 129 | + "id": "5cbf0e12", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
| 133 | + "def compute_model(q, model_params, full_id):\n", |
| 134 | + "\n", |
| 135 | + " model = model_params[\"model\"]\n", |
| 136 | + " res = None\n", |
| 137 | + " \n", |
| 138 | + " if model==1:\n", |
| 139 | + " #res = Holstein.Holstein2(q, model_params, full_id)\n", |
| 140 | + " res = holstein_mimic(q, model_params, full_id)\n", |
| 141 | + " else:\n", |
| 142 | + " print(\"Unrecognized model! Check for correct model import statement.\")\n", |
| 143 | + "\n", |
| 144 | + " return res" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 4, |
| 150 | + "id": "7ebfd1ca", |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [], |
| 153 | + "source": [ |
| 154 | + "def run_qtag(dyn_params, _compute_model, _model_params, prefix):\n", |
| 155 | + "\n", |
| 156 | + " default_params = {\n", |
| 157 | + " \"hdf5_output_level\":-1, \"prefix\":prefix, \"use_compression\":0, \"compression_level\":[0,0,0], \n", |
| 158 | + " \"mem_output_level\":4, \"txt2_output_level\":0, \"properties_to_save\": [], \"progress_frequency\": 1\n", |
| 159 | + " }\n", |
| 160 | + " critical_params = []\n", |
| 161 | + " \n", |
| 162 | + " comn.check_input(dyn_params, default_params, critical_params)\n", |
| 163 | + "# qtag_checks.user_input(dyn_params, model_params)\n", |
| 164 | + " #Define function objects to be used in various parts of the calculation...\n", |
| 165 | + " #initialize, basis_props, vapprox, mom_calc, propagate = qtag_checks.assign_fobj(qtag_params)\n", |
| 166 | + "\n", |
| 167 | + " #basis_props = qtag_checks.set_basis_updates(dyn_params)\n", |
| 168 | + " \n", |
| 169 | + " #Rename variables locally for convenience...\n", |
| 170 | + " ndof = dyn_params[\"ndof\"]\n", |
| 171 | + " nstates = dyn_params[\"nstates\"]\n", |
| 172 | + " active_state = dyn_params[\"active_state\"]\n", |
| 173 | + " nsteps = dyn_params[\"nsteps\"]\n", |
| 174 | + " dt = dyn_params[\"dt\"]\n", |
| 175 | + " mass = dyn_params[\"mass\"]\n", |
| 176 | + " iM = dyn_params[\"iM\"]\n", |
| 177 | + " #iM = MATRIX(1, 1); iM.set(0,0, 1.0);\n", |
| 178 | + "\n", |
| 179 | + " #Initialize the basis parameters {q,p,a,s} and create initial b-matrix...\n", |
| 180 | + " ntraj, qpas = qtag_init.initialize(dyn_params)\n", |
| 181 | + "\n", |
| 182 | + " #Create initial projection vector b...\n", |
| 183 | + " bt = qtag_init.coeffs(dyn_params, qpas, active_state)\n", |
| 184 | + "\n", |
| 185 | + " #Initialize savers...\n", |
| 186 | + " dyn_params['prefix'] = prefix\n", |
| 187 | + " properties_to_save = dyn_params['properties_to_save']\n", |
| 188 | + " _savers = save.init_qtag_savers(dyn_params, _model_params, nsteps, ntraj, ndof, nstates)\n", |
| 189 | + " \n", |
| 190 | + " #Start simulation and walltime variables...\n", |
| 191 | + " walltime_start = time.time()\n", |
| 192 | + " t=0.0\n", |
| 193 | + "\n", |
| 194 | + " \n", |
| 195 | + " ham = nHamiltonian(nstates, nstates, ndof)\n", |
| 196 | + " ham.add_new_children(nstates, nstates, ndof, ntraj) \n", |
| 197 | + " ham.init_all(2,1)\n", |
| 198 | + " _model_params.update({\"timestep\":0})\n", |
| 199 | + " \n", |
| 200 | + " ovlp = CMATRIX(ntraj, ntraj)\n", |
| 201 | + " hmat = CMATRIX(ntraj, ntraj)\n", |
| 202 | + " \n", |
| 203 | + " coeff = CMATRIX(nstates, ntraj)\n", |
| 204 | + " \n", |
| 205 | + " \n", |
| 206 | + " for step in range(nsteps):\n", |
| 207 | + " \n", |
| 208 | + " qtag_hamiltonian_and_overlap(qpas[0], qpas[1], qpas[2], qpas[3], coeff, \n", |
| 209 | + " Py2Cpp_int(qpas[4]), iM, ham, \n", |
| 210 | + " _compute_model, _model_params, dyn_params,\n", |
| 211 | + " ovlp, hmat)\n", |
| 212 | + " \n", |
| 213 | + " #Compute the new coefficient vector c_new...\n", |
| 214 | + " ct_new = qtag_calc.basis_diag(ntraj,dt,hmat,ovlp,bt)\n", |
| 215 | + " \n", |
| 216 | + " etot = qtag_calc.energy(ct_new,hmat)\n", |
| 217 | + " pops = qtag_calc.norm(qpas[4],ct_new,ovlp,\n", |
| 218 | + " [state for state in range(nstates)])\n", |
| 219 | + "\n", |
| 220 | + " print(etot)\n", |
| 221 | + " #Update the basis parameters according to the new wavefunction (ct_new)...\n", |
| 222 | + " qpas, bt = qtag_prop.propagate(dyn_params, qpas, ct_new, pops)\n", |
| 223 | + " \n", |
| 224 | + " save.save_qtag_data(_savers, dyn_params, step, etot, 0, pops, \n", |
| 225 | + " ct_new, qpas[0], qpas[1], qpas[2], qpas[3]) \n", |
| 226 | + " if _savers[\"txt2_saver\"]!=None:\n", |
| 227 | + " _savers[\"txt2_saver\"].save_data_txt( F\"{prefix}\", properties_to_save, \"a\", 0)\n", |
| 228 | + " \n", |
| 229 | + " print(pops)\n", |
| 230 | + " walltime_end = time.time()\n", |
| 231 | + " print(\"Total wall time: \",walltime_end-walltime_start)\n" |
| 232 | + ] |
| 233 | + }, |
| 234 | + { |
| 235 | + "cell_type": "code", |
| 236 | + "execution_count": 5, |
| 237 | + "id": "1f3c7126", |
| 238 | + "metadata": {}, |
| 239 | + "outputs": [ |
| 240 | + { |
| 241 | + "data": { |
| 242 | + "text/plain": [ |
| 243 | + "[[2, -0.03], [1, -0.02], [0, 0.01]]" |
| 244 | + ] |
| 245 | + }, |
| 246 | + "execution_count": 5, |
| 247 | + "metadata": {}, |
| 248 | + "output_type": "execute_result" |
| 249 | + } |
| 250 | + ], |
| 251 | + "source": [ |
| 252 | + "merge_sort([ [0, 0.01], [1, -0.02], [2, -0.03 ]])" |
| 253 | + ] |
| 254 | + }, |
| 255 | + { |
| 256 | + "cell_type": "code", |
| 257 | + "execution_count": 6, |
| 258 | + "id": "7119d8e8", |
| 259 | + "metadata": { |
| 260 | + "scrolled": true |
| 261 | + }, |
| 262 | + "outputs": [ |
| 263 | + { |
| 264 | + "name": "stdout", |
| 265 | + "output_type": "stream", |
| 266 | + "text": [ |
| 267 | + "15.050030925787372\n", |
| 268 | + " step= 0\n", |
| 269 | + "15.050030925787382\n", |
| 270 | + "15.050030925787397\n", |
| 271 | + "15.05003092578742\n", |
| 272 | + "15.050030925787441\n", |
| 273 | + "15.050030925787452\n", |
| 274 | + "15.050030925787473\n", |
| 275 | + "15.05003092578749\n", |
| 276 | + "15.050030925787501\n", |
| 277 | + "15.050030925787519\n", |
| 278 | + "15.050030925787526\n", |
| 279 | + "15.050030925787553\n", |
| 280 | + "15.050030925787569\n", |
| 281 | + "15.05003092578759\n", |
| 282 | + "15.050030925787606\n", |
| 283 | + "15.050030925787624\n", |
| 284 | + "15.050030925787647\n", |
| 285 | + "15.050030925787663\n", |
| 286 | + "15.050030925787684\n", |
| 287 | + "15.050030925787706\n", |
| 288 | + "[0.8743601549642422, 8.70075639668817e-09]\n", |
| 289 | + "Total wall time: 0.24504971504211426\n" |
| 290 | + ] |
| 291 | + } |
| 292 | + ], |
| 293 | + "source": [ |
| 294 | + "iM = MATRIX(1, 1); iM.set(0,0, 1.0);\n", |
| 295 | + "\n", |
| 296 | + "#Parameters for general simulation\n", |
| 297 | + "dyn_params = {\n", |
| 298 | + " \"ndof\" : 1, \"nstates\" : 2, \"active_state\" : 0,\n", |
| 299 | + " \"dt\":10., \"nsteps\":20, \"mass\":[1.0], \"iM\":iM,\n", |
| 300 | + " \"hdf5_output_level\" : 0, \"txt2_output_level\": 3, \n", |
| 301 | + " \"properties_to_save\" : [\"time\",\"Etot\",\"pops\",\"q\"],\n", |
| 302 | + " \"init_placement\":0, \"grid_dims\" : [5], \"alp_scl\":[6.0], \"rho_cut\":1e-12,\n", |
| 303 | + " \"q_update_method\" : 1, \"p_update_method\" : 1, \"a_update_method\" : 1, \"s_update_method\" : 0,\n", |
| 304 | + " \"q_sync_method\":1, \"p_sync_method\":0, \"a_sync_method\":0, \"s_sync_method\":0,\n", |
| 305 | + " \"wfc_q0\" : [-2.0], \"wfc_p0\" : [0.0], \"wfc_a0\" : [1.0], \"wfc_s0\" : [0.0],\n", |
| 306 | + " \"decpl_den\" : 0.3,\n", |
| 307 | + " \"mom_calc_type\" : 1, \"linfit_beta\" : 1e-3,\n", |
| 308 | + " \"qtag_pot_approx_method\":0\n", |
| 309 | + "}\n", |
| 310 | + "\n", |
| 311 | + "#Potential parameters for Holstein5\n", |
| 312 | + "model_params = {\n", |
| 313 | + " \"model\":1,\n", |
| 314 | + " \"E_n\":[0.0,15.8114],\n", |
| 315 | + " \"x_n\":[0.0,1.0],\n", |
| 316 | + " \"k_n\":[10.0,10.0],\n", |
| 317 | + " \"V\":[[0.0,1.0],[1.0,0.0]],\n", |
| 318 | + " \"alpha\":[[0.0,1.5811],[1.5811,0.0]],\n", |
| 319 | + " \"x_nm\":[[0.0,2.0],[2.0,0.0]]\n", |
| 320 | + "}\n", |
| 321 | + "\n", |
| 322 | + "run_qtag(dyn_params, compute_model, model_params, \"qtag\")" |
| 323 | + ] |
| 324 | + }, |
| 325 | + { |
| 326 | + "cell_type": "code", |
| 327 | + "execution_count": null, |
| 328 | + "id": "c98981c9", |
| 329 | + "metadata": {}, |
| 330 | + "outputs": [], |
| 331 | + "source": [] |
| 332 | + } |
| 333 | + ], |
| 334 | + "metadata": { |
| 335 | + "kernelspec": { |
| 336 | + "display_name": "Python 3", |
| 337 | + "language": "python", |
| 338 | + "name": "python3" |
| 339 | + }, |
| 340 | + "language_info": { |
| 341 | + "codemirror_mode": { |
| 342 | + "name": "ipython", |
| 343 | + "version": 3 |
| 344 | + }, |
| 345 | + "file_extension": ".py", |
| 346 | + "mimetype": "text/x-python", |
| 347 | + "name": "python", |
| 348 | + "nbconvert_exporter": "python", |
| 349 | + "pygments_lexer": "ipython3", |
| 350 | + "version": "3.6.13" |
| 351 | + } |
| 352 | + }, |
| 353 | + "nbformat": 4, |
| 354 | + "nbformat_minor": 5 |
| 355 | +} |
0 commit comments