Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional Tests for Trsh, Common and Gaussian #714

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arc/job/adapters/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ def combine_parameters(input_dict: dict, terms: list) -> Tuple[dict, List]:

for key, value in input_dict_copy.items():
if isinstance(value, str):
for term in terms:
# Sort terms by length in descending order to handle overlapping terms
for term in sorted(terms, key=len, reverse=True):
matches = re.findall(term, value)
for match in matches:
if match:
Expand Down
24 changes: 24 additions & 0 deletions arc/job/adapters/common_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,30 @@ def test_combine_parameters_no_match(self):
self.assertEqual(modified_dict, expected_dict)
self.assertEqual(parameters, expected_parameters)

def test_combine_parameters_multiple_occurrences(self):
"""Test the combine_parameters function with multiple occurrences of the same term."""
input_dict = {'param1': 'value1 term1 value2 term1', 'param2': 'another term2 value term2'}
terms = ['term1', 'term2']
expected_dict = {'param1': 'value1 value2 ', 'param2': 'another value '}
expected_parameters = ['term1', 'term2']

modified_dict, parameters = common.combine_parameters(input_dict, terms)

self.assertEqual(modified_dict, expected_dict)
self.assertEqual(sorted(parameters), expected_parameters)

def test_combine_parameters_overlapping_terms(self):
"""Test the combine_parameters function with overlapping terms."""
input_dict = {'param1': 'value term1 term123', 'param2': 'another term2 value'}
terms = ['term1', 'term123', 'term2']
expected_dict = {'param1': 'value ', 'param2': 'another value'}
expected_parameters = ['term1', 'term123', 'term2']

modified_dict, parameters = common.combine_parameters(input_dict, terms)

self.assertEqual(modified_dict, expected_dict)
self.assertEqual(sorted(parameters), expected_parameters)

def test_input_dict_strip(self):
"""Test the input_dict_strip() function"""
input_dict = {
Expand Down
50 changes: 50 additions & 0 deletions arc/job/adapters/gaussian_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ def setUpClass(cls):
args=args
)

# Gaussian: Checkfile error and SCF error
# First SCF error - qc,nosymm
job_status = {'keywords': ['SCF', 'NoSymm', 'GL301']}
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)
args = {'keyword': {}, 'block': {}}
if trsh_keyword:
args['trsh'] = {'trsh': trsh_keyword}
cls.job_16 = GaussianAdapter(execution_type='local',
job_type='sp',
level=Level(method='wb97xd'),
fine=True,
ess_trsh_methods=ess_trsh_methods,
project='test',
project_directory=os.path.join(ARC_PATH, 'arc', 'testing', 'test_GaussianAdapter'),
species=[spc_11],
testing=True,
args=args
)

def test_set_cpu_and_mem(self):
"""Test assigning number of cpu's and memory"""
self.job_8.input_file_memory = None
Expand Down Expand Up @@ -619,6 +641,34 @@ def test_trsh_write_input_file(self):
"""
self.assertEqual(content_15, job_15_expected_input_file)

self.job_16.write_input_file()
with open(os.path.join(self.job_16.local_path, input_filenames[self.job_16.job_adapter]), 'r') as f:
content_16 = f.read()

job_16_expected_input_file = """%chk=check.chk
%mem=14336mb
%NProcShared=8

#P opt=(cartesian) integral=(grid=ultrafine, Acc2E=14) guess=mix wb97xd IOp(2/9=2000) nosymm scf=(NDump=30,NoDIIS,direct,tight,xqc)

ethanol

0 1
C 1.16582100 -0.40435500 0.00000000
C 0.00000000 0.55180500 0.00000000
O -1.18946000 -0.21419400 0.00000000
H -1.94125800 0.37518500 0.00000000
H 2.10540200 0.14511600 0.00000000
H 1.13062400 -1.03878500 0.88303200
H 1.13062400 -1.03878500 -0.88303200
H 0.04768200 1.19305700 0.88359100
H 0.04768200 1.19305700 -0.88359100


"""

self.assertEqual(content_16, job_16_expected_input_file)

@classmethod
def tearDownClass(cls):
"""
Expand Down
2 changes: 1 addition & 1 deletion arc/job/trsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ def trsh_keyword_nosymm(job_status, ess_trsh_methods, trsh_keyword, couldnt_trsh
"""
Check if the job requires change of nosymm
"""
if 'NoSymm' in job_status['keywords'] and 'nosymm' not in ess_trsh_methods:
if 'NoSymm' in job_status['keywords'] and 'NoSymm' not in ess_trsh_methods:
ess_trsh_methods.append('NoSymm')
trsh_keyword.append('nosymm')
couldnt_trsh = False
Expand Down
22 changes: 22 additions & 0 deletions arc/job/trsh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,30 @@ def test_trsh_ess_job(self):
num_heavy_atoms, cpu_cores, ess_trsh_methods)

self.assertTrue(remove_checkfile)
self.assertEqual(ess_trsh_methods, ['change_node', 'int=(Acc2E=14)', 'checkfile=None', 'cartesian', 'NoSymm'])
self.assertEqual(trsh_keyword, ['opt=(cartesian)', 'int=(Acc2E=14)', 'nosymm'] )

# Gaussian: test 3
job_status = {'keywords': ['SCF', 'GL502', 'NoSymm']}
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)

self.assertTrue(remove_checkfile)
self.assertIn('scf=(qc)', ess_trsh_methods)
self.assertFalse(couldnt_trsh)

# Gaussian: test 5
job_status = {'keywords': ['DiskSpace']}
output_errors, ess_trsh_methods, remove_checkfile, level_of_theory, software, job_type, fine, trsh_keyword, \
memory, shift, cpu_cores, couldnt_trsh = trsh.trsh_ess_job(label, level_of_theory, server, job_status,
job_type, software, fine, memory_gb,
num_heavy_atoms, cpu_cores, ess_trsh_methods)

self.assertTrue(couldnt_trsh)
self.assertIn('Error: Could not troubleshoot opt for ethanol! The job ran out of disc space on server1; ', output_errors)

# Test Q-Chem
software = 'qchem'
ess_trsh_methods = ['change_node']
Expand Down
Loading