Skip to content

Commit 1d76554

Browse files
committed
Minor changes. Removed some comments, tried to improve the convergence for Ge atom
1 parent 5675bd7 commit 1d76554

File tree

2 files changed

+60
-83
lines changed

2 files changed

+60
-83
lines changed

dft.ipynb

+47-59
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,10 @@
4141
"source": [
4242
"import math as m\n",
4343
"import numpy as np\n",
44-
"#impurt cupy as np\n",
4544
"import scipy as sp\n",
4645
"import scipy.linalg as splalg\n",
47-
"#import skcuda.linalg as splalg\n",
4846
"import matplotlib.pyplot as plt\n",
49-
"%matplotlib inline\n",
50-
"#import os\n",
51-
"#os.environ['CUDA_VISIBLE_DEVICES'] = '-1' #disable gpu usage"
47+
"%matplotlib inline"
5248
]
5349
},
5450
{
@@ -3176,9 +3172,9 @@
31763172
"name": "stdout",
31773173
"output_type": "stream",
31783174
"text": [
3179-
"State: 0 Energy: -0.2315937694988972\n",
3175+
"State: 0 Energy: -0.23159376856708852\n",
31803176
"\n",
3181-
"Total energy: -0.4452697411031219 NIST value: -0.445671\n"
3177+
"Total energy: -0.4452697411031217 NIST value: -0.445671\n"
31823178
]
31833179
}
31843180
],
@@ -3198,10 +3194,10 @@
31983194
"W = np.random.randn(np.prod(S),Ns) + 1j * np.random.randn(np.prod(S),Ns)\n",
31993195
"W = orthogonalize(W)\n",
32003196
"\n",
3201-
"W, Elist = sd(W, 25, False)\n",
3197+
"W, Elist = sd(W, 30, False)\n",
32023198
"W = orthogonalize(W)\n",
32033199
"\n",
3204-
"W, Elist = pccg(W,25,1, False)\n",
3200+
"W, Elist = pccg(W, 30, 1, False)\n",
32053201
"\n",
32063202
"Psi, epsilon = getPsi(W)\n",
32073203
"\n",
@@ -3266,9 +3262,9 @@
32663262
"name": "stdout",
32673263
"output_type": "stream",
32683264
"text": [
3269-
"State: 0 Energy: -0.3659044983263073\n",
3265+
"State: 0 Energy: -0.36590449791075863\n",
32703266
"\n",
3271-
"Total energy: -1.135952510684748 Expected: -1.136\n"
3267+
"Total energy: -1.135952510684747 Expected: -1.136\n"
32723268
]
32733269
}
32743270
],
@@ -3288,10 +3284,10 @@
32883284
"W = np.random.randn(np.prod(S),Ns) + 1j * np.random.randn(np.prod(S),Ns)\n",
32893285
"W = orthogonalize(W)\n",
32903286
"\n",
3291-
"W, Elist = sd(W, 25, False)\n",
3287+
"W, Elist = sd(W, 30, False)\n",
32923288
"W = orthogonalize(W)\n",
32933289
"\n",
3294-
"W, Elist = pccg(W,25,1, False)\n",
3290+
"W, Elist = pccg(W, 30, 1, False)\n",
32953291
"\n",
32963292
"Psi, epsilon = getPsi(W)\n",
32973293
"\n",
@@ -3484,9 +3480,9 @@
34843480
"name": "stdout",
34853481
"output_type": "stream",
34863482
"text": [
3487-
"State: 0 Energy: -0.22926194992364968\n",
3483+
"State: 0 Energy: -0.22926194992322046\n",
34883484
"\n",
3489-
"Total energy: -0.44048365378580023 NIST value: -0.445671\n"
3485+
"Total energy: -0.4404836537858003 NIST value: -0.445671\n"
34903486
]
34913487
}
34923488
],
@@ -3506,10 +3502,10 @@
35063502
"W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)\n",
35073503
"W = orthogonalize(W)\n",
35083504
"\n",
3509-
"W, Elist = sd(W, 25, False)\n",
3505+
"W, Elist = sd(W, 30, False)\n",
35103506
"W = orthogonalize(W)\n",
35113507
"\n",
3512-
"W, Elist = pccg(W,25,1, False)\n",
3508+
"W, Elist = pccg(W, 30, 1, False)\n",
35133509
"\n",
35143510
"Psi, epsilon = getPsi(W)\n",
35153511
"\n",
@@ -3591,7 +3587,7 @@
35913587
"name": "stdout",
35923588
"output_type": "stream",
35933589
"text": [
3594-
"State: 0 Energy: -0.22926194991947513\n",
3590+
"State: 0 Energy: -0.22926194992399263\n",
35953591
"\n",
35963592
"Total energy: -0.4404836537858002 NIST value: -0.445671\n"
35973593
]
@@ -3603,10 +3599,10 @@
36033599
"W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)\n",
36043600
"W = orthogonalize(W)\n",
36053601
"\n",
3606-
"W, Elist = sd(W, 25, False)\n",
3602+
"W, Elist = sd(W, 30, False)\n",
36073603
"W = orthogonalize(W)\n",
36083604
"\n",
3609-
"W, Elist = pccg(W,25,1, False)\n",
3605+
"W, Elist = pccg(W, 30, 1, False)\n",
36103606
"\n",
36113607
"Psi, epsilon = getPsi(W)\n",
36123608
"\n",
@@ -4144,71 +4140,70 @@
41444140
},
41454141
{
41464142
"cell_type": "code",
4147-
"execution_count": 117,
4143+
"execution_count": 125,
41484144
"metadata": {},
41494145
"outputs": [
41504146
{
41514147
"name": "stdout",
41524148
"output_type": "stream",
41534149
"text": [
4154-
"Niter: 0 E: -1.608521644539682\n",
4155-
"Anglecos: -0.8818111992133328\n",
4156-
"Niter: 1 E: -1.611714513927931\n",
4157-
"Anglecos: 0.016723575818258063\n",
4158-
"Niter: 2 E: -1.6121626772712896\n",
4159-
"Anglecos: 0.0006891945788002626\n",
4160-
"Niter: 3 E: -1.6123732286351387\n",
4161-
"Anglecos: 0.0015528432070223807\n",
4162-
"Niter: 4 E: -1.61250256728854\n",
4163-
"Anglecos: 0.00035037897018077305\n",
4164-
"Niter: 5 E: -1.6125878678459544\n",
4165-
"Anglecos: 0.0012822070416834707\n",
4166-
"Niter: 6 E: -1.612649347656511\n",
4167-
"Anglecos: 0.0011010389937777308\n",
4168-
"Niter: 7 E: -1.6126859609706246\n",
4169-
"Anglecos: 0.0015406748730367463\n",
4170-
"Niter: 8 E: -1.6127136471665966\n",
4171-
"Anglecos: 0.0016314534283183447\n",
4172-
"Niter: 9 E: -1.6127184773929353\n"
4150+
"Niter: 0 E: -1.6126669126024666\n",
4151+
"Anglecos: -0.8768535387313062\n",
4152+
"Niter: 1 E: -1.612928646844911\n",
4153+
"Anglecos: -0.0004790704270254443\n",
4154+
"Niter: 2 E: -1.6129837551172024\n",
4155+
"Anglecos: 0.00012053526888059705\n",
4156+
"Niter: 3 E: -1.613007241417608\n",
4157+
"Anglecos: 5.327052421027639e-06\n",
4158+
"Niter: 4 E: -1.61302262536089\n",
4159+
"Anglecos: 3.495269976882052e-05\n",
4160+
"Niter: 5 E: -1.61303297781298\n",
4161+
"Anglecos: 0.0001073010117246911\n",
4162+
"Niter: 6 E: -1.613040436632165\n",
4163+
"Anglecos: 2.2757597129762557e-06\n",
4164+
"Niter: 7 E: -1.6130461102323566\n",
4165+
"Anglecos: 0.00016698870886137226\n",
4166+
"Niter: 8 E: -1.6130506881869784\n",
4167+
"Anglecos: 2.869190160151949e-05\n",
4168+
"Niter: 9 E: -1.6130540511326215\n"
41734169
]
41744170
}
41754171
],
41764172
"source": [
41774173
"np.random.seed(100)\n",
41784174
"\n",
4179-
"#something is not exactly right here\n",
41804175
"W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)\n",
41814176
"W = orthogonalize(W)\n",
41824177
"\n",
4183-
"W, Elist = sd(W, 300, False)\n",
4178+
"W, Elist = sd(W, 600, False)\n",
41844179
"W = orthogonalize(W)\n",
41854180
"\n",
4186-
"W, Elist = lm(W, 300, False)\n",
4181+
"W, Elist = lm(W, 600, False)\n",
41874182
"\n",
41884183
"# the preconditioned variants do not work so well here\n",
41894184
"W = orthogonalize(W)\n",
41904185
"W, Elist = pclm(W, 10, True)\n",
41914186
"\n",
4192-
"#W, Elist = pccg(W, 10, 1, True, 0.000000001)"
4187+
"#W, Elist = pccg(W, 10, 1, True)"
41934188
]
41944189
},
41954190
{
41964191
"cell_type": "code",
4197-
"execution_count": 118,
4192+
"execution_count": 126,
41984193
"metadata": {},
41994194
"outputs": [
42004195
{
42014196
"name": "stdout",
42024197
"output_type": "stream",
42034198
"text": [
4204-
"State: 0 Energy: -0.36206660142973934\n",
4205-
"State: 1 Energy: -0.08179735273075626\n",
4206-
"State: 2 Energy: -0.08179050361480827\n",
4207-
"State: 3 Energy: -0.08158806374169289\n",
4199+
"State: 0 Energy: -0.3618190185599205\n",
4200+
"State: 1 Energy: -0.08160355959823264\n",
4201+
"State: 2 Energy: -0.08160195312004917\n",
4202+
"State: 3 Energy: -0.08156312259730072\n",
42084203
"\n",
4209-
"Total energy: -3.7297263666803318\n",
4210-
"Electronic energy: -1.6127184773929353\n",
4211-
"Energy dif beteen s and p orbitals: 0.28026924869898306 Expected (from NIST data): 0.276641\n"
4204+
"Total energy: -3.7300619404200184\n",
4205+
"Electronic energy: -1.6130540511326215\n",
4206+
"Energy dif beteen s and p orbitals: 0.28021545896168787 Expected (from NIST data): 0.276641\n"
42124207
]
42134208
}
42144209
],
@@ -4224,13 +4219,6 @@
42244219
"print('Electronic energy:', E)\n",
42254220
"print('Energy dif beteen s and p orbitals:', epsilon[1] - epsilon[0], 'Expected (from NIST data): 0.276641')"
42264221
]
4227-
},
4228-
{
4229-
"cell_type": "code",
4230-
"execution_count": null,
4231-
"metadata": {},
4232-
"outputs": [],
4233-
"source": []
42344222
}
42354223
],
42364224
"metadata": {

dft.py

+13-24
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,10 @@
2525

2626
import math as m
2727
import numpy as np
28-
#impurt cupy as np
2928
import scipy as sp
3029
import scipy.linalg as splalg
31-
#import skcuda.linalg as splalg
3230
import matplotlib.pyplot as plt
3331
get_ipython().run_line_magic('matplotlib', 'inline')
34-
#import os
35-
#os.environ['CUDA_VISIBLE_DEVICES'] = '-1' #disable gpu usage
3632

3733

3834
# In[2]:
@@ -1097,10 +1093,10 @@ def pccg(Win, Nit, cgform, fillE = True, alphat = 0.00003):
10971093
W = np.random.randn(np.prod(S),Ns) + 1j * np.random.randn(np.prod(S),Ns)
10981094
W = orthogonalize(W)
10991095

1100-
W, Elist = sd(W, 25, False)
1096+
W, Elist = sd(W, 30, False)
11011097
W = orthogonalize(W)
11021098

1103-
W, Elist = pccg(W,25,1, False)
1099+
W, Elist = pccg(W, 30, 1, False)
11041100

11051101
Psi, epsilon = getPsi(W)
11061102

@@ -1156,10 +1152,10 @@ def pccg(Win, Nit, cgform, fillE = True, alphat = 0.00003):
11561152
W = np.random.randn(np.prod(S),Ns) + 1j * np.random.randn(np.prod(S),Ns)
11571153
W = orthogonalize(W)
11581154

1159-
W, Elist = sd(W, 25, False)
1155+
W, Elist = sd(W, 30, False)
11601156
W = orthogonalize(W)
11611157

1162-
W, Elist = pccg(W,25,1, False)
1158+
W, Elist = pccg(W, 30, 1, False)
11631159

11641160
Psi, epsilon = getPsi(W)
11651161

@@ -1315,10 +1311,10 @@ def cIdag(inp):
13151311
W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)
13161312
W = orthogonalize(W)
13171313

1318-
W, Elist = sd(W, 25, False)
1314+
W, Elist = sd(W, 30, False)
13191315
W = orthogonalize(W)
13201316

1321-
W, Elist = pccg(W,25,1, False)
1317+
W, Elist = pccg(W, 30, 1, False)
13221318

13231319
Psi, epsilon = getPsi(W)
13241320

@@ -1385,10 +1381,10 @@ def H(W):
13851381
W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)
13861382
W = orthogonalize(W)
13871383

1388-
W, Elist = sd(W, 25, False)
1384+
W, Elist = sd(W, 30, False)
13891385
W = orthogonalize(W)
13901386

1391-
W, Elist = pccg(W,25,1, False)
1387+
W, Elist = pccg(W, 30, 1, False)
13921388

13931389
Psi, epsilon = getPsi(W)
13941390

@@ -1730,28 +1726,27 @@ def getgrad(W):
17301726
Vdual = cJ(Vps * Sf)
17311727

17321728

1733-
# In[117]:
1729+
# In[125]:
17341730

17351731

17361732
np.random.seed(100)
17371733

1738-
#something is not exactly right here
17391734
W = np.random.randn(active[0].size,Ns) + 1j * np.random.randn(active[0].size,Ns)
17401735
W = orthogonalize(W)
17411736

1742-
W, Elist = sd(W, 300, False)
1737+
W, Elist = sd(W, 600, False)
17431738
W = orthogonalize(W)
17441739

1745-
W, Elist = lm(W, 300, False)
1740+
W, Elist = lm(W, 600, False)
17461741

17471742
# the preconditioned variants do not work so well here
17481743
W = orthogonalize(W)
17491744
W, Elist = pclm(W, 10, True)
17501745

1751-
#W, Elist = pccg(W, 10, 1, True, 0.000000001)
1746+
#W, Elist = pccg(W, 10, 1, True)
17521747

17531748

1754-
# In[118]:
1749+
# In[126]:
17551750

17561751

17571752
Psi, epsilon = getPsi(W)
@@ -1765,9 +1760,3 @@ def getgrad(W):
17651760
print('Electronic energy:', E)
17661761
print('Energy dif beteen s and p orbitals:', epsilon[1] - epsilon[0], 'Expected (from NIST data): 0.276641')
17671762

1768-
1769-
# In[ ]:
1770-
1771-
1772-
1773-

0 commit comments

Comments
 (0)