-
Notifications
You must be signed in to change notification settings - Fork 15
/
test_exampleJob_non_modal.py
81 lines (70 loc) · 3.07 KB
/
test_exampleJob_non_modal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
import unittest
import numpy as np
import os
from pyiron_base import Project
class TestExampleJob(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.count = 12
cls.file_location = os.path.dirname(os.path.abspath(__file__))
cls.project = Project(
os.path.join(cls.file_location, "random_testing_non_modal")
)
cls.project.remove_jobs_silently(recursive=True)
cls.project.set_logging_level("INFO")
@classmethod
def tearDownClass(cls):
# print('tear down')
file_location = os.path.dirname(os.path.abspath(__file__))
project = Project(os.path.join(file_location, "random_testing_non_modal"))
project.remove_jobs_silently()
project.remove(enable=True)
def test_non_modal_run(self):
ham_non_modal = self.project.create_job(
self.project.job_type.ExampleJob, "job_non_modal"
)
ham_non_modal.input["count"] = self.count
ham_non_modal.server.run_mode.non_modal = True
ham_non_modal.run()
self.assertFalse(ham_non_modal.status.finished)
self.project.wait_for_job(ham_non_modal, interval_in_s=5, max_iterations=50)
self.assertTrue(ham_non_modal.status.finished)
lines = self.project["job_non_modal/input.inp"]
input_lst = [
"alat 3.2 #lattice constant (would be in a more realistic example in the structure file)\n",
"alpha 0.1 #noise amplitude\n",
"a_0 3 #equilibrium lattice constant\n",
"a_1 0\n",
"a_2 1.0 #2nd order in energy (corresponds to bulk modulus)\n",
"a_3 0.0 #3rd order\n",
"a_4 0.0 #4th order\n",
"count " + str(self.count) + " #number of calls (dummy)\n",
"epsilon 0.2 #energy prefactor of lennard jones\n",
"sigma 2.4 #distance unit of lennard jones\n",
"cutoff 4.0 #cutoff length (relative to sigma)\n",
"write_restart True\n",
"read_restart False\n"
]
self.assertEqual(input_lst, lines)
lines = self.project["job_non_modal/restart.out"]
restart_lst = ["count " + str(self.count) + " \n"]
self.assertEqual(restart_lst, lines)
energy_lst = ham_non_modal.get("output/generic/energy_tot")
self.assertEqual(len(energy_lst), self.count)
lines = self.project["job_non_modal/output.log"]
output_lst = [
"exampleExecutable logFile \n",
"alat 3.2 \n",
"count " + str(self.count) + " \n",
]
self.assertEqual(output_lst, lines[0:3])
energy_output_lst = np.array([float(line.split(" ")[1]) for line in lines[3:]])
for e_1, e_2 in zip(energy_lst, energy_output_lst):
self.assertTrue(1 > e_1 > 0)
self.assertEqual(e_1, e_2)
ham_non_modal.remove()
if __name__ == "__main__":
unittest.main()