Skip to content

Commit

Permalink
Removed deprecated test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvakimov committed Mar 25, 2022
2 parents 1342b3e + a5023b7 commit 01c7f4d
Show file tree
Hide file tree
Showing 239 changed files with 7,132 additions and 64,874 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.ipynb_checkpoints
*.xyz
.ipynb_checkpoints
qtag*
355 changes: 355 additions & 0 deletions notebooks/Example21_qtag/LibraQTAG-Python.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,355 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a803e43a",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n",
"/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",
" return f(*args, **kwds)\n"
]
}
],
"source": [
"import numpy as np\n",
"import math\n",
"import matplotlib.pyplot as plt\n",
"import imageio\n",
"import os\n",
"import time\n",
"import sys\n",
"\n",
"from liblibra_core import *\n",
"import libra_py.models.Holstein as Holstein\n",
"import util.libutil as comn\n",
"from libra_py import data_outs\n",
"import libra_py.data_savers as data_savers\n",
"\n",
"import libra_py.dynamics.qtag.qtag_calc as qtag_calc\n",
"import libra_py.dynamics.qtag.qtag_init as qtag_init\n",
"import libra_py.dynamics.qtag.qtag_mom as qtag_mom\n",
"import libra_py.dynamics.qtag.qtag_prop as qtag_prop\n",
"import libra_py.dynamics.qtag.save as save"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fc9c9952",
"metadata": {},
"outputs": [],
"source": [
"class tmp:\n",
" pass\n",
"\n",
"#Holstein5 from libra_py/models/Hostein.py\n",
"def holstein_mimic(q, params, full_id):\n",
" critical_params = [\"E_n\", \"x_n\", \"k_n\" ]\n",
" default_params = { \"V\": [ [0.001, 0.001, 0.001, 0.001], [0.001, 0.001, 0.001, 0.001],\n",
" [0.001, 0.001, 0.001, 0.001], [0.001, 0.001, 0.001, 0.001] ],\n",
" \"alpha\": [ [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00],\n",
" [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00] ],\n",
" \"x_nm\": [ [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00],\n",
" [0.00, 0.00, 0.00, 0.00], [0.00, 0.00, 0.00, 0.00] ],\n",
" }\n",
" comn.check_input(params, default_params, critical_params)\n",
"\n",
" E_n = params[\"E_n\"]\n",
" x_n = params[\"x_n\"]\n",
" k_n = params[\"k_n\"]\n",
" V = params[\"V\"]\n",
" alpha = params[\"alpha\"]\n",
" x_nm = params[\"x_nm\"]\n",
" \n",
" n = len(E_n)\n",
"\n",
" Hdia = CMATRIX(n,n)\n",
" Sdia = CMATRIX(n,n)\n",
" d1ham_dia = CMATRIXList(); d1ham_dia.append( CMATRIX(n,n) )\n",
" dc1_dia = CMATRIXList(); dc1_dia.append( CMATRIX(n,n) )\n",
"\n",
" #indx = 0\n",
" Id = Cpp2Py(full_id)\n",
" indx = Id[-1]\n",
"\n",
" x = q.col(indx).get(0)\n",
"\n",
" Sdia.identity()\n",
"\n",
" for i in range(n):\n",
" Hdia.set(i,i, (E_n[i] + 0.5*k_n[i]*(x - x_n[i])**2) * (1.0+0.0j) )\n",
"\n",
" for i in range(n):\n",
" for j in range(n):\n",
" if i!=j:\n",
" Hdia.set(i,j, V[i][j] * math.exp(-alpha[i][j] * (x-x_nm[i][j])**2 ) * (1.0+0.0j) )\n",
"\n",
" for k in [0]:\n",
" # d Hdia / dR_0\n",
" for i in range(n):\n",
" d1ham_dia[k].set(i,i, (k_n[i] * (x - x_n[i]))*(1.0+0.0j) )\n",
"\n",
" for k in [0]:\n",
" for i in range(n):\n",
" for j in range(n):\n",
" if i!=j:\n",
" 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",
"\n",
" obj = tmp()\n",
" obj.ham_dia = Hdia\n",
" obj.ovlp_dia = Sdia\n",
" obj.d1ham_dia = d1ham_dia\n",
" obj.dc1_dia = dc1_dia\n",
"\n",
" return obj"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "5cbf0e12",
"metadata": {},
"outputs": [],
"source": [
"def compute_model(q, model_params, full_id):\n",
"\n",
" model = model_params[\"model\"]\n",
" res = None\n",
" \n",
" if model==1:\n",
" #res = Holstein.Holstein2(q, model_params, full_id)\n",
" res = holstein_mimic(q, model_params, full_id)\n",
" else:\n",
" print(\"Unrecognized model! Check for correct model import statement.\")\n",
"\n",
" return res"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "7ebfd1ca",
"metadata": {},
"outputs": [],
"source": [
"def run_qtag(dyn_params, _compute_model, _model_params, prefix):\n",
"\n",
" default_params = {\n",
" \"hdf5_output_level\":-1, \"prefix\":prefix, \"use_compression\":0, \"compression_level\":[0,0,0], \n",
" \"mem_output_level\":4, \"txt2_output_level\":0, \"properties_to_save\": [], \"progress_frequency\": 1\n",
" }\n",
" critical_params = []\n",
" \n",
" comn.check_input(dyn_params, default_params, critical_params)\n",
"# qtag_checks.user_input(dyn_params, model_params)\n",
" #Define function objects to be used in various parts of the calculation...\n",
" #initialize, basis_props, vapprox, mom_calc, propagate = qtag_checks.assign_fobj(qtag_params)\n",
"\n",
" #basis_props = qtag_checks.set_basis_updates(dyn_params)\n",
" \n",
" #Rename variables locally for convenience...\n",
" ndof = dyn_params[\"ndof\"]\n",
" nstates = dyn_params[\"nstates\"]\n",
" active_state = dyn_params[\"active_state\"]\n",
" nsteps = dyn_params[\"nsteps\"]\n",
" dt = dyn_params[\"dt\"]\n",
" mass = dyn_params[\"mass\"]\n",
" iM = dyn_params[\"iM\"]\n",
" #iM = MATRIX(1, 1); iM.set(0,0, 1.0);\n",
"\n",
" #Initialize the basis parameters {q,p,a,s} and create initial b-matrix...\n",
" ntraj, qpas = qtag_init.initialize(dyn_params)\n",
"\n",
" #Create initial projection vector b...\n",
" bt = qtag_init.coeffs(dyn_params, qpas, active_state)\n",
"\n",
" #Initialize savers...\n",
" dyn_params['prefix'] = prefix\n",
" properties_to_save = dyn_params['properties_to_save']\n",
" _savers = save.init_qtag_savers(dyn_params, _model_params, nsteps, ntraj, ndof, nstates)\n",
" \n",
" #Start simulation and walltime variables...\n",
" walltime_start = time.time()\n",
" t=0.0\n",
"\n",
" \n",
" ham = nHamiltonian(nstates, nstates, ndof)\n",
" ham.add_new_children(nstates, nstates, ndof, ntraj) \n",
" ham.init_all(2,1)\n",
" _model_params.update({\"timestep\":0})\n",
" \n",
" ovlp = CMATRIX(ntraj, ntraj)\n",
" hmat = CMATRIX(ntraj, ntraj)\n",
" \n",
" coeff = CMATRIX(nstates, ntraj)\n",
" \n",
" \n",
" for step in range(nsteps):\n",
" \n",
" qtag_hamiltonian_and_overlap(qpas[0], qpas[1], qpas[2], qpas[3], coeff, \n",
" Py2Cpp_int(qpas[4]), iM, ham, \n",
" _compute_model, _model_params, dyn_params,\n",
" ovlp, hmat)\n",
" \n",
" #Compute the new coefficient vector c_new...\n",
" ct_new = qtag_calc.basis_diag(ntraj,dt,hmat,ovlp,bt)\n",
" \n",
" etot = qtag_calc.energy(ct_new,hmat)\n",
" pops = qtag_calc.norm(qpas[4],ct_new,ovlp,\n",
" [state for state in range(nstates)])\n",
"\n",
" print(etot)\n",
" #Update the basis parameters according to the new wavefunction (ct_new)...\n",
" qpas, bt = qtag_prop.propagate(dyn_params, qpas, ct_new, pops)\n",
" \n",
" save.save_qtag_data(_savers, dyn_params, step, etot, 0, pops, \n",
" ct_new, qpas[0], qpas[1], qpas[2], qpas[3]) \n",
" if _savers[\"txt2_saver\"]!=None:\n",
" _savers[\"txt2_saver\"].save_data_txt( F\"{prefix}\", properties_to_save, \"a\", 0)\n",
" \n",
" print(pops)\n",
" walltime_end = time.time()\n",
" print(\"Total wall time: \",walltime_end-walltime_start)\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1f3c7126",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[2, -0.03], [1, -0.02], [0, 0.01]]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"merge_sort([ [0, 0.01], [1, -0.02], [2, -0.03 ]])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "7119d8e8",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"15.050030925787372\n",
" step= 0\n",
"15.050030925787382\n",
"15.050030925787397\n",
"15.05003092578742\n",
"15.050030925787441\n",
"15.050030925787452\n",
"15.050030925787473\n",
"15.05003092578749\n",
"15.050030925787501\n",
"15.050030925787519\n",
"15.050030925787526\n",
"15.050030925787553\n",
"15.050030925787569\n",
"15.05003092578759\n",
"15.050030925787606\n",
"15.050030925787624\n",
"15.050030925787647\n",
"15.050030925787663\n",
"15.050030925787684\n",
"15.050030925787706\n",
"[0.8743601549642422, 8.70075639668817e-09]\n",
"Total wall time: 0.24504971504211426\n"
]
}
],
"source": [
"iM = MATRIX(1, 1); iM.set(0,0, 1.0);\n",
"\n",
"#Parameters for general simulation\n",
"dyn_params = {\n",
" \"ndof\" : 1, \"nstates\" : 2, \"active_state\" : 0,\n",
" \"dt\":10., \"nsteps\":20, \"mass\":[1.0], \"iM\":iM,\n",
" \"hdf5_output_level\" : 0, \"txt2_output_level\": 3, \n",
" \"properties_to_save\" : [\"time\",\"Etot\",\"pops\",\"q\"],\n",
" \"init_placement\":0, \"grid_dims\" : [5], \"alp_scl\":[6.0], \"rho_cut\":1e-12,\n",
" \"q_update_method\" : 1, \"p_update_method\" : 1, \"a_update_method\" : 1, \"s_update_method\" : 0,\n",
" \"q_sync_method\":1, \"p_sync_method\":0, \"a_sync_method\":0, \"s_sync_method\":0,\n",
" \"wfc_q0\" : [-2.0], \"wfc_p0\" : [0.0], \"wfc_a0\" : [1.0], \"wfc_s0\" : [0.0],\n",
" \"decpl_den\" : 0.3,\n",
" \"mom_calc_type\" : 1, \"linfit_beta\" : 1e-3,\n",
" \"qtag_pot_approx_method\":0\n",
"}\n",
"\n",
"#Potential parameters for Holstein5\n",
"model_params = {\n",
" \"model\":1,\n",
" \"E_n\":[0.0,15.8114],\n",
" \"x_n\":[0.0,1.0],\n",
" \"k_n\":[10.0,10.0],\n",
" \"V\":[[0.0,1.0],[1.0,0.0]],\n",
" \"alpha\":[[0.0,1.5811],[1.5811,0.0]],\n",
" \"x_nm\":[[0.0,2.0],[2.0,0.0]]\n",
"}\n",
"\n",
"run_qtag(dyn_params, compute_model, model_params, \"qtag\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c98981c9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 0 additions & 1 deletion notebooks/Example4_md/Example1_lattice/.gitignore

This file was deleted.

Loading

0 comments on commit 01c7f4d

Please sign in to comment.