|
5 | 5 | This module contains unit tests for the arc.scheduler module |
6 | 6 | """ |
7 | 7 |
|
| 8 | +import math |
8 | 9 | import unittest |
9 | 10 | from unittest.mock import MagicMock, patch |
10 | 11 | import os |
|
18 | 19 | from arc.plotter import save_conformers_file |
19 | 20 | from arc.scheduler import Scheduler, species_has_freq, species_has_geo, species_has_sp, species_has_sp_and_freq |
20 | 21 | from arc.imports import settings |
| 22 | +from arc.settings.settings import input_filenames |
21 | 23 | from arc.reaction import ARCReaction |
22 | 24 | from arc.species.converter import str_to_xyz |
23 | 25 | from arc.species.species import ARCSpecies, TSGuess |
@@ -865,6 +867,63 @@ def test_troubleshoot_ess_orca_increases_total_memory_when_not_capped(self): |
865 | 867 | self.assertEqual(kwargs['cpu_cores'], 24) |
866 | 868 | self.assertEqual(kwargs['memory'], 250) |
867 | 869 | self.assertIn('memory', kwargs['ess_trsh_methods']) |
| 870 | + |
| 871 | + def test_troubleshoot_ess_orca_rewrites_input_with_reduced_cores_and_higher_maxcore(self): |
| 872 | + """Test ORCA troubleshooting end-to-end from failure to rewritten input file.""" |
| 873 | + label = 'methylamine' |
| 874 | + self.sched1.output = dict() |
| 875 | + self.sched1.initialize_output_dict() |
| 876 | + |
| 877 | + job = MagicMock() |
| 878 | + job.job_name = 'sp_a205' |
| 879 | + job.job_type = 'sp' |
| 880 | + job.job_adapter = 'orca' |
| 881 | + job.level = Level(repr={'method': 'dlpno-ccsd(T)'}) |
| 882 | + job.server = 'server1' |
| 883 | + job.fine = True |
| 884 | + job.cpu_cores = 32 |
| 885 | + job.job_memory_gb = 250 |
| 886 | + job.ess_trsh_methods = list() |
| 887 | + job.torsions = None |
| 888 | + job.dihedrals = None |
| 889 | + job.directed_scan_type = None |
| 890 | + job.rotor_index = None |
| 891 | + job.job_status = ['done', {'status': 'errored', |
| 892 | + 'keywords': ['MDCI', 'Memory', 'max_total_job_memory'], |
| 893 | + 'error': 'Orca suggests to increase per cpu core memory to 10218 MB.', |
| 894 | + 'line': 'Please increase MaxCore'}] |
| 895 | + |
| 896 | + with patch.object(self.sched1, 'run_job') as mock_run_job, \ |
| 897 | + patch.object(self.sched1, 'save_restart_dict'): |
| 898 | + self.sched1.troubleshoot_ess(label=label, job=job, level_of_theory=job.level) |
| 899 | + |
| 900 | + kwargs = mock_run_job.call_args.kwargs |
| 901 | + temp_project_dir = os.path.join(ARC_TESTING_PATH, 'test_scheduler_orca_trsh_input') |
| 902 | + try: |
| 903 | + rerun_job = job_factory(job_adapter=kwargs['job_adapter'], |
| 904 | + project='project_test_scheduler_orca_trsh_input', |
| 905 | + ess_settings=self.ess_settings, |
| 906 | + species=[self.spc1], |
| 907 | + xyz=self.spc1.get_xyz(), |
| 908 | + job_type=kwargs['job_type'], |
| 909 | + level=kwargs['level_of_theory'], |
| 910 | + project_directory=temp_project_dir, |
| 911 | + cpu_cores=kwargs['cpu_cores'], |
| 912 | + job_memory_gb=kwargs['memory'], |
| 913 | + ess_trsh_methods=kwargs['ess_trsh_methods'], |
| 914 | + execution_type='incore', |
| 915 | + fine=kwargs['fine'], |
| 916 | + server=job.server, |
| 917 | + testing=True) |
| 918 | + rerun_job.write_input_file() |
| 919 | + with open(os.path.join(rerun_job.local_path, input_filenames[rerun_job.job_adapter]), 'r') as f: |
| 920 | + content = f.read() |
| 921 | + original_maxcore = math.ceil(rerun_job.job_memory_gb * 1024 / job.cpu_cores) |
| 922 | + self.assertIn('%pal nprocs 24 end', content) |
| 923 | + self.assertIn(f'%maxcore {rerun_job.input_file_memory}', content) |
| 924 | + self.assertGreater(rerun_job.input_file_memory, original_maxcore) |
| 925 | + finally: |
| 926 | + shutil.rmtree(temp_project_dir, ignore_errors=True) |
868 | 927 |
|
869 | 928 | @patch('arc.scheduler.Scheduler.run_opt_job') |
870 | 929 | def test_switch_ts_cleanup(self, mock_run_opt): |
|
0 commit comments