-
Notifications
You must be signed in to change notification settings - Fork 1
/
qa_test_convergence.py
85 lines (64 loc) · 2.51 KB
/
qa_test_convergence.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
82
83
84
85
"""
Created on Wed Jan 8 14:10:00 2020
@author: rleone
"""
import sys
import re
import os
import time
import subprocess
import textwrap
import csv
import shutil
import configparser
from h5py import *
import numpy as np
from qa_swapper import Swapper
from qa_debug import *
from qa_common import *
from qa_solution_comparison import *
from qa_test_doc import *
from qa_regression_test import QARegressionTest
from qa_test import QATest
class QATestConvergence(QATest):
def __init__(self,name,root_dir,section_dict=None):
super().__init__(name,root_dir,section_dict)
self.num_tries = 1
self.test_pass = False
def process_convergence_options(self):
tolerance = qa_lookup(self._convergence_options, 'tolerance','fail_on_missing_keyword')
self._verbose = qa_lookup(self._convergence_options, 'verbose','True')
self._convergence_observation = qa_lookup(self._convergence_options, 'observation','False')
self._tolerance = string_to_number(tolerance)
plot_error = qa_lookup(self._output_options,'plot_error',False)
print_error = qa_lookup(self._output_options,'print_error',False)
if not plot_error:
self._output_options['plot_error'] = True
if not print_error:
self._output_options['print_error'] = True
def run(self,list_of_swap_dict):
debug_push('QASolutionConvergence run')
self.process_convergence_options()
for i in range(len(list_of_swap_dict)):
doc_run = self.run_single(i,list_of_swap_dict)
if self._convergence_observation:
max_error = self.compare_solutions.get_observation_max_error()
else:
max_error = self.compare_solutions.get_time_slice_max_error()
print('Max Error = {}'.format(max_error))
print('Attempt # = {}'.format(self.num_tries))
if max_error > self._tolerance:
if self._verbose:
self.doc.add_run(doc_run)
print('Max error above tolerance')
self.num_tries += 1
else:
print('converged, aborting test')
self.test_pass = True
self.doc.add_run(doc_run)
break
if self._verbose:
self.doc.write()
elif self.test_pass:
self.doc.write()
debug_pop()