Skip to content

Commit 60e3370

Browse files
committed
Now the test should work
1 parent e222d06 commit 60e3370

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

tests/test_gradient_evolution/test_relax.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@ def test_gradient_comparison(verbose = False):
3535
minim.meaningful_factor = 1e-10
3636
minim.max_ka = 5
3737

38-
ka = 0
39-
def compare_gradients(dyn_grad, struct_grad):
40-
if not os.path.exists("grad_{}.dat".format(ka)):
41-
np.savetxt("grad_{}.dat".format(ka), dyn_grad[0,:,:])
42-
else:
43-
correct_grad = np.loadtxt("grad_{}.dat".format(ka))
44-
diff = np.max(np.abs(dyn_grad - correct_grad))
45-
print("KA = {} | difference = {}".format(ka, diff))
38+
class CG:
39+
def __init__(self):
40+
self.ka = 0
41+
def compare_gradients(self, dyn_grad, struct_grad):
42+
ka = self.ka
4643

47-
44+
if not os.path.exists("grad_{}.dat".format(ka)):
45+
np.savetxt("grad_{}.dat".format(ka), dyn_grad[0,:,:])
46+
else:
47+
correct_grad = np.loadtxt("grad_{}.dat".format(ka))
48+
diff = np.max(np.abs(dyn_grad - correct_grad))
49+
print("KA = {} | difference = {}".format(ka, diff))
50+
self.ka += 1
51+
52+
cg = CG()
4853

4954
minim.init()
50-
minim.run(custom_function_gradient = compare_gradients)
55+
minim.run(custom_function_gradient = cg.compare_gradients)
5156
minim.finalize()
5257

5358

0 commit comments

Comments
 (0)