Skip to content

Commit 3e94d8f

Browse files
committed
my play file
1 parent dbe3fad commit 3e94d8f

File tree

1 file changed

+378
-0
lines changed

1 file changed

+378
-0
lines changed

ayush.ipynb

+378
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,378 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"id": "d09f6604",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stderr",
11+
"output_type": "stream",
12+
"text": [
13+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
14+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll\n",
15+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll\n",
16+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll\n",
17+
" warnings.warn(\"loaded more than 1 DLL from .libs:\"\n"
18+
]
19+
},
20+
{
21+
"ename": "SyntaxError",
22+
"evalue": "invalid syntax (util.py, line 757)",
23+
"output_type": "error",
24+
"traceback": [
25+
"Traceback \u001b[1;36m(most recent call last)\u001b[0m:\n",
26+
"\u001b[0m File \u001b[0;32m~\\anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:3508\u001b[0m in \u001b[0;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\u001b[0m\n",
27+
"\u001b[1;36m Cell \u001b[1;32mIn[1], line 10\u001b[1;36m\n\u001b[1;33m import util\u001b[1;36m\n",
28+
"\u001b[1;36m File \u001b[1;32m~\\Documents\\GitHub\\Advance-Computational-Physics\\hmc_python\\util.py:757\u001b[1;36m\u001b[0m\n\u001b[1;33m print(global no_even_sites)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
29+
]
30+
}
31+
],
32+
"source": [
33+
"import numpy as np\n",
34+
"import scipy\n",
35+
"import sklearn as sk\n",
36+
"import matplotlib.pyplot as plt\n",
37+
"import sys\n",
38+
"import os\n",
39+
"import math\n",
40+
"\n",
41+
"# from util import *\n",
42+
"import util\n",
43+
"\n",
44+
"PI = math.pi\n",
45+
"COLDLAT = 0\n",
46+
"HOTLAT = 1\n",
47+
"PLUS = 1\n",
48+
"MINUS = -1\n",
49+
"EVEN = 0x02\n",
50+
"ODD = 0x01\n",
51+
"EVENANDODD = 0x03\n",
52+
"LSIZE = 16 # Change LSIZE to 16/32 accordingly\n",
53+
"DELTAMAX = 50.0\n",
54+
"\n",
55+
"# acl parameters for switch = 0\n",
56+
"\n",
57+
"T_cut = 5\n",
58+
"D_cut = 5\n",
59+
"MAXT_cut = 25\n",
60+
"NOT_cut = 5\n",
61+
"\n",
62+
"#------------------------------------------------\n",
63+
"#Declared external variables in the header file\n",
64+
"#------------------------------------------------\n",
65+
"\n",
66+
"nx = None\n",
67+
"nt = None\n",
68+
"volume = None\n",
69+
"nf = None\n",
70+
"mdstep = None\n",
71+
"cgiter1 = None\n",
72+
"cgiter2 = None\n",
73+
"# long *iseed # Check this later !!!!\n",
74+
"g = None\n",
75+
"step = None\n",
76+
"residue1 = None\n",
77+
"residue2 = None\n",
78+
"mid = None\n",
79+
"no_even_sites = None\n",
80+
"no_odd_sites = None\n",
81+
"no_garbage = None\n",
82+
"bin_length = None\n",
83+
"no_bin = None\n",
84+
"meas_loop = None\n",
85+
"meas_length = None\n",
86+
"prop_length = None\n",
87+
"no_meas = None\n",
88+
"seg_length = None\n",
89+
"no_a_seg = None\n",
90+
"no_prop_seg = None\n",
91+
"hmc_it = None\n",
92+
"counter = None\n",
93+
"sw_flag = None #flag to switch action between garbage and\n",
94+
"# # autocorln. loops and measurement loops.\n",
95+
"# # sw_flag = 0 => garbage & autocorln. loop;\n",
96+
"# # sw_flag = 1 => measurement loop; */\n",
97+
"\n",
98+
"lattice = None\n",
99+
"store = None\n",
100+
"conf = None\n",
101+
"con = None\n",
102+
"garbage = None\n",
103+
"ac_store = None\n",
104+
"ac_prop = None\n",
105+
"bin_av = None\n",
106+
"psi = None\n",
107+
"psi_acl = None\n",
108+
"G_prop = None\n",
109+
"G_store = None\n",
110+
"G_temp = None\n",
111+
"prop = None\n",
112+
"tprop = None\n",
113+
"T_int = None\n",
114+
"T_int_prop = None\n",
115+
"gen_pt = None\n",
116+
"neighbor = None # neighbour stores the index of the neighbouring site in place of the pointer\n",
117+
"\n"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 1,
123+
"id": "2a767831",
124+
"metadata": {},
125+
"outputs": [
126+
{
127+
"name": "stderr",
128+
"output_type": "stream",
129+
"text": [
130+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\_distributor_init.py:30: UserWarning: loaded more than 1 DLL from .libs:\n",
131+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.FB5AE2TYXYH2IJRDKGDGQ3XBKLKTF43H.gfortran-win_amd64.dll\n",
132+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll\n",
133+
"C:\\Users\\cdipt\\anaconda3\\lib\\site-packages\\numpy\\.libs\\libopenblas64__v0.3.21-gcc_10_3_0.dll\n",
134+
" warnings.warn(\"loaded more than 1 DLL from .libs:\"\n"
135+
]
136+
}
137+
],
138+
"source": [
139+
"import hmc_python"
140+
]
141+
},
142+
{
143+
"cell_type": "code",
144+
"execution_count": 2,
145+
"id": "dcbeef11",
146+
"metadata": {},
147+
"outputs": [],
148+
"source": [
149+
"h"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 4,
155+
"id": "ffb449f2",
156+
"metadata": {},
157+
"outputs": [
158+
{
159+
"ename": "FileNotFoundError",
160+
"evalue": "[Errno 2] No such file or directory: './hmc_python/sigma1.in'",
161+
"output_type": "error",
162+
"traceback": [
163+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
164+
"\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
165+
"Cell \u001b[1;32mIn[4], line 4\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m#------------------------------------------------\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# File IO Defined in the code\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m#------------------------------------------------\u001b[39;00m\n\u001b[1;32m----> 4\u001b[0m pin \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m./hmc_python/sigma1.in\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 5\u001b[0m ptout \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m./hmc_python/sigma1.out\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 6\u001b[0m ptacl \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m./hmc_python/sigma1.acl\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m);\n",
166+
"File \u001b[1;32m~\\anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:284\u001b[0m, in \u001b[0;36m_modified_open\u001b[1;34m(file, *args, **kwargs)\u001b[0m\n\u001b[0;32m 277\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[0;32m 278\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 279\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 280\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 281\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 282\u001b[0m )\n\u001b[1;32m--> 284\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mio_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
167+
"\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: './hmc_python/sigma1.in'"
168+
]
169+
}
170+
],
171+
"source": [
172+
"#------------------------------------------------\n",
173+
"# File IO Defined in the code\n",
174+
"#------------------------------------------------\n",
175+
"pin = open(\"./hmc_python/hmc_python/sigma1.in\",\"r\")\n",
176+
"ptout = open(\"./hmc_python/sigma1.out\", \"a\")\n",
177+
"ptacl = open(\"./hmc_python/sigma1.acl\", \"a\");\n",
178+
"ptlat = open(\"./hmc_python/sigma1.lat\", \"a\");\n",
179+
"ptprop = open(\"./hmc_python/sigma1.prop\", \"w\");\n",
180+
"ptpropacl = open(\"./hmc_python/sigma1.propacl\", \"w\");\n",
181+
"\n",
182+
"prompt = setup_gn()\n",
183+
"readin(prompt)\n"
184+
]
185+
},
186+
{
187+
"cell_type": "code",
188+
"execution_count": 2,
189+
"id": "c25295a6",
190+
"metadata": {},
191+
"outputs": [],
192+
"source": []
193+
},
194+
{
195+
"cell_type": "code",
196+
"execution_count": 2,
197+
"id": "78751a84",
198+
"metadata": {},
199+
"outputs": [
200+
{
201+
"name": "stdout",
202+
"output_type": "stream",
203+
"text": [
204+
"None\n"
205+
]
206+
},
207+
{
208+
"ename": "TypeError",
209+
"evalue": "unsupported operand type(s) for /: 'NoneType' and 'int'",
210+
"output_type": "error",
211+
"traceback": [
212+
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
213+
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
214+
"Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mhmc_python\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mutil\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlayout\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
215+
"File \u001b[1;32m~\\Documents\\GitHub\\Advance-Computational-Physics\\hmc_python\\util.py:759\u001b[0m, in \u001b[0;36mlayout\u001b[1;34m()\u001b[0m\n\u001b[0;32m 757\u001b[0m \u001b[38;5;28;01mglobal\u001b[39;00m volume\n\u001b[0;32m 758\u001b[0m \u001b[38;5;28mprint\u001b[39m(no_even_sites)\n\u001b[1;32m--> 759\u001b[0m no_even_sites \u001b[38;5;241m=\u001b[39m \u001b[43mvolume\u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m2\u001b[39;49m\n\u001b[0;32m 760\u001b[0m no_odd_sites \u001b[38;5;241m=\u001b[39m volume\u001b[38;5;241m/\u001b[39m\u001b[38;5;241m2\u001b[39m\n",
216+
"\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'NoneType' and 'int'"
217+
]
218+
}
219+
],
220+
"source": [
221+
"hmc_python.util.layout()"
222+
]
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": null,
227+
"id": "d57ab71d",
228+
"metadata": {
229+
"collapsed": true
230+
},
231+
"outputs": [],
232+
"source": [
233+
"\n",
234+
"# randomize() # Not defined here but present in the original code\n",
235+
"\n",
236+
"# filelat(pin) # Getting converted will be merged later\n",
237+
"\n",
238+
"av_sigma = 0.0 # grand average of <sigma>\n",
239+
"av_psi = 0.0 # grand average of <psi_bar-psi>\n",
240+
"t_ex_sigma = 0.0 # grand sum over all <sigma>s\n",
241+
"seg_av_sigma = 0.0 # segment-average of <sigma> for tau_int\n",
242+
"seg_av_prop = 0.0 # segment-average of <propagator[m]>\n",
243+
"\n",
244+
"no_hmc = 0 # # of hmc steps calculated\n",
245+
"no_acc = 0 # # of accepted configurations\n",
246+
"counter = 0 # counter used in hmc.c\n",
247+
"meas = 0 # meas is a switch for measurements\n",
248+
"no_auto = 0 # no_auto is the index for autocoreln. measurement\n",
249+
"no_prop = 0 # no_prop is the index for Prop-Acl calculation\n",
250+
"\n",
251+
"a = 0 # a index used in tau_int measurements\n",
252+
"ac = 0 # ac configuration index to ac_prop[ac]\n",
253+
"acc = 0 # acc index used in G_temp[][acc] i.e. # of data point and also used as index in ac_store\n",
254+
"bin = 0 # bin is index to bin_average\n",
255+
"g = 0 # g configuration index to garbage i.e. garbage[g]\n",
256+
"k = 0 # k configuration index to store i.e. store[k]\n",
257+
"j = 0 # j configuration index to store[j], during measurements\n",
258+
"\n",
259+
"if sw_flag == 0:\n",
260+
" # GARBAGE LOOPS AND AUTOCORELATION MEASUREMENTS LOOPS\n",
261+
" for n in range(hmc_it):\n",
262+
" no_acc += 1\n",
263+
" no_hmc += hmc()\n",
264+
"\n",
265+
" if no_acc<=no_garbage:\n",
266+
" garbage[g] = average_sigma()\n",
267+
" g += 1\n",
268+
" bin +=1\n",
269+
" if bin%bin_length == 0:\n",
270+
" for m in range((g-bin),g):\n",
271+
" bin_av[k] +=garbage[m]/bin_length\n",
272+
" k += 1\n",
273+
" bin = 0\n",
274+
"\n",
275+
" if no_acc>no_garbage:\n",
276+
" ac_store[acc] = average_sigma()\n",
277+
" acc += 1\n",
278+
" no_auto += 1\n",
279+
"\n",
280+
" if no_auto%seg_length == 0:\n",
281+
" lbd = acc - no_auto\n",
282+
" for m in range(lbd,acc):\n",
283+
" seg_av_sigma += ac_store[m]/seg_length\n",
284+
" autocorel(seg_av_sigma,lbd,a)\n",
285+
" a += 1\n",
286+
" seg_av_sigma = 0\n",
287+
" no_auto = 0\n",
288+
"\n",
289+
" for i in range(0,volume):\n",
290+
" con[i] = conf[i]\n",
291+
" for i in range(0,volume):\n",
292+
" conf[i] = lattice[i].sigma\n",
293+
"\n",
294+
" acc_rate = no_acc/no_hmc\n",
295+
"\n",
296+
" for n in range(0, MAXT_cut):\n",
297+
" ptacl.write(f\"{n+1}\")\n",
298+
" for u in range(NOT_cut):\n",
299+
" d_t_int = 0\n",
300+
" av_t_int = 0\n",
301+
"\n",
302+
" for a in range(no_a_seg):\n",
303+
" av_t_int += T_int[u][n][a]/no_a_seg\n",
304+
" for a in range(no_a_seg):\n",
305+
" d_t_int += (T_int[u][n][a] - av_t_int)**2\n",
306+
"\n",
307+
" d_t_int = math.sqrt(d_t_int/(no_a_seg-1))\n",
308+
"\n",
309+
" ptacl.write(f\"\\t{av_t_int}\\t{d_t_int}\")\n",
310+
" ptacl.write(\"\\n\")\n",
311+
"\n",
312+
" print(f\"\\n\\n no_acc_traj={no_acc} \\t no_hmc={no_hmc} \\t acc_rate={acc_rate}\")\n",
313+
"\n",
314+
" for k in range(0,no_bin):\n",
315+
" ptout.write(f\"{k+1}\\t{bin_av[k]}\\n\")\n",
316+
" for i in range(0,volume):\n",
317+
" ptlat.write(f\"{lattice[i].sigma}\\n\")\n",
318+
"\n",
319+
"\n",
320+
"\n",
321+
"if sw_flag == 1:\n",
322+
" for n in range(meas_loop):\n",
323+
" no_acc += 1\n",
324+
" no_hmc += hmc()\n",
325+
"\n",
326+
" meas = meas + 1\n",
327+
" no_prop = no_prop + 1\n",
328+
"\n",
329+
" if meas%meas_length == 0:\n",
330+
" store[j] += average_sigma()\n",
331+
" t_ex_sigma += store[j]\n",
332+
" j += 1\n",
333+
"\n",
334+
" if meas%prop_length == 0:\n",
335+
" pass\n",
336+
"\n",
337+
" av_sigma = t_ex_sigma / no_meas\n",
338+
" sqdev = 0\n",
339+
" for k in range(no_meas):\n",
340+
" sqdev += (store[k]-av_sigma)**2\n",
341+
" d_av_sigma = sqrt(sqdev/(no_meas-1))\n",
342+
"\n",
343+
" acc_rate = no_acc/no_hmc\n",
344+
"\n",
345+
" print(f\"\\n\\n\\ no_acc_traj = {no_acc} \\t no_hmc = {no_hmc} \\t acc_rate = {acc_rate} \\n\\n\")\n",
346+
" print(f\"av_sigma={av_sigma} \\t av_psi{av_psi}\\n\\n\")\n",
347+
" print(f\"d_av_sigma={d_av_sigma} \\t d_av_psi{d_av_psi}\\n\\n\")\n",
348+
"\n",
349+
" for i in range(0,volume):\n",
350+
" ptlat.write(f\"{lattice[i].sigma}\\n\")\n",
351+
"\n",
352+
"else:\n",
353+
" print(\"KILL YOURSELF, PLEASE !!!\")\n"
354+
]
355+
}
356+
],
357+
"metadata": {
358+
"kernelspec": {
359+
"display_name": "Python 3 (ipykernel)",
360+
"language": "python",
361+
"name": "python3"
362+
},
363+
"language_info": {
364+
"codemirror_mode": {
365+
"name": "ipython",
366+
"version": 3
367+
},
368+
"file_extension": ".py",
369+
"mimetype": "text/x-python",
370+
"name": "python",
371+
"nbconvert_exporter": "python",
372+
"pygments_lexer": "ipython3",
373+
"version": "3.8.8"
374+
}
375+
},
376+
"nbformat": 4,
377+
"nbformat_minor": 5
378+
}

0 commit comments

Comments
 (0)