]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Convert to Python 3 and indent Python scripts. 18431/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 7 May 2025 02:14:00 +0000 (20:14 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 27 May 2025 15:11:06 +0000 (09:11 -0600)
contrib/utilities/parse_ctest_output.py
tests/optimization/bfgs_05.py

index 2439d044a545a26be037c706a71bf0166c9991ef..7f71d21b5c1f0e7197a4954957b5f6ff09c92664 100755 (executable)
@@ -25,6 +25,7 @@
 import xml.etree.ElementTree as ET
 import glob
 
+
 class Group:
     def __init__(self, name):
         self.name = name
@@ -33,68 +34,70 @@ class Group:
         self.fail = []
         self.fail_text = {}
         self.fail_status = {}
-        self.n_status = [0,0,0,0,0]
+        self.n_status = [0, 0, 0, 0, 0]
+
 
 class Revision:
     def __init__(self):
         self.groups = {}
         self.number = -1
-        self.name = ''
+        self.name = ""
         self.n_tests = 0
         self.n_fail = 0
 
+
 def parse_revision(dirname):
     rev = Revision()
 
-    if len(glob.glob(dirname+'/Update.xml'))>0:
-        #new format
-        tree = ET.parse(dirname+'/Update.xml')
-        rev.name = tree.getroot().find('BuildName').text
-        rev.number = tree.getroot().find('Revision').text
-    elif len(glob.glob(dirname+'/Notes.xml'))>0:
-        #old format
-        tree = ET.parse(dirname+'/Notes.xml')
-        rev.name = tree.getroot().attrib['BuildName']
-        number = rev.name.split('-')[-1]
+    if len(glob.glob(dirname + "/Update.xml")) > 0:
+        # new format
+        tree = ET.parse(dirname + "/Update.xml")
+        rev.name = tree.getroot().find("BuildName").text
+        rev.number = tree.getroot().find("Revision").text
+    elif len(glob.glob(dirname + "/Notes.xml")) > 0:
+        # old format
+        tree = ET.parse(dirname + "/Notes.xml")
+        rev.name = tree.getroot().attrib["BuildName"]
+        number = rev.name.split("-")[-1]
         rev.number = number[1:]
     else:
         return None
 
-    print dirname, "BUILD: ", rev.name
+    print(dirname, "BUILD: ", rev.name)
 
-    #now Test.xml:
-    tree = ET.parse(dirname+'/Test.xml')
+    # now Test.xml:
+    tree = ET.parse(dirname + "/Test.xml")
     root = tree.getroot()
-    testing = root.find('Testing')
+    testing = root.find("Testing")
 
     for test in testing.findall("Test"):
-        fail=False
-        if test.attrib['Status']=="failed":
-            fail=True
-        name = test.find('Name').text
-        group = name.split('/')[0]
+        fail = False
+        if test.attrib["Status"] == "failed":
+            fail = True
+        name = test.find("Name").text
+        group = name.split("/")[0]
         status = 4
         if fail:
-            text = test.find('Results').find('Measurement').find('Value').text
+            text = test.find("Results").find("Measurement").find("Value").text
             if text is None:
-                text=""
-            failtext = text.encode('utf-8')
-            failtextlines = failtext.replace('"','').split('\n')
-            failstatustxt = failtextlines[0].split(' ')[-1]
-            for i in range(0,len(failtextlines)):
+                text = ""
+            failtext = text.encode("utf-8")
+            failtextlines = failtext.replace('"', "").split("\n")
+            failstatustxt = failtextlines[0].split(" ")[-1]
+            for i in range(0, len(failtextlines)):
                 failtextlines[i] = failtextlines[i][0:80]
-                if failtextlines[i].startswith('FAILED: '):
-                    failtextlines[i]='FAILED: ...'
-            failtext = '\n'.join(failtextlines[4:min(25,len(failtext))])
-            statuslist=['CONFIGURE','BUILD','RUN','DIFF']
+                if failtextlines[i].startswith("FAILED: "):
+                    failtextlines[i] = "FAILED: ..."
+            failtext = "\n".join(failtextlines[4 : min(25, len(failtext))])
+            statuslist = ["CONFIGURE", "BUILD", "RUN", "DIFF"]
             if failstatustxt in statuslist:
                 status = statuslist.index(failstatustxt)
             else:
-                print "unknown status '%s' in test %s "% (failstatustxt,name)
-                status=0
+                print("unknown status '%s' in test %s " % (failstatustxt, name))
+                status = 0
 
         if not group in rev.groups:
-            rev.groups[group]= Group(group)
+            rev.groups[group] = Group(group)
 
         rev.groups[group].n_tests += 1
         rev.n_tests += 1
@@ -103,34 +106,32 @@ def parse_revision(dirname):
             rev.groups[group].n_fail += 1
             rev.n_fail += 1
             rev.groups[group].fail.append(name)
-            rev.groups[group].fail_text[name]=failtext
-            rev.groups[group].fail_status[name]=status
+            rev.groups[group].fail_text[name] = failtext
+            rev.groups[group].fail_status[name] = status
 
     for g in sorted(rev.groups):
         g = rev.groups[g]
-        #print g.name, g.n_tests, g.n_fail, g.fail
+        # print (g.name, g.n_tests, g.n_fail, g.fail)
 
     return rev
 
 
+# from xml.dom import minidom
 
 
-#from xml.dom import minidom
-
-
-n=glob.glob("*/Build.xml")
+n = glob.glob("*/Build.xml")
 n.sort(reverse=True)
-numberofrevisions=10
-n = n[0:min(10,len(n))]
+numberofrevisions = 10
+n = n[0 : min(10, len(n))]
 
 revs = []
 
 allgroups = set()
 
 for f in n:
-    dirname = f.replace('/Build.xml','')
+    dirname = f.replace("/Build.xml", "")
     rev = parse_revision(dirname)
-    if rev!=None:
+    if rev != None:
         revs.append(rev)
         for gr in rev.groups:
             allgroups.add(gr)
@@ -139,9 +140,10 @@ revs.sort(key=lambda x: x.number, reverse=True)
 
 allgroups = sorted(allgroups)
 
-f = open('tests.html', 'w')
-f.write('<html><head></head>')
-f.write("""<style type="text/css">
+f = open("tests.html", "w")
+f.write("<html><head></head>")
+f.write(
+    """<style type="text/css">
 table {
 border-collapse:collapse;
 }
@@ -187,8 +189,10 @@ border: 2px solid;
 .onerow {background: #FFE}
 .otherrow {background: #EEE}
 
-</style>""")
-f.write("""<script>
+</style>"""
+)
+f.write(
+    """<script>
 function toggle_id(obj)
 {
 var e = document.getElementById(obj);
@@ -198,46 +202,62 @@ else
  e.style.display = '';
 }
 </script>
-<body>""")
-f.write('<table>')
+<body>"""
+)
+f.write("<table>")
 
 f.write('<colgroup span="1" class="colgroup""/>')
 for rev in revs:
     f.write('<colgroup span="5" class="colgroup"/>')
-f.write('\n')
+f.write("\n")
 
 
-f.write('<thead><tr>')
+f.write("<thead><tr>")
 f.write('<th style="width:250px">&nbsp;</th>')
 
 for rev in revs:
-    f.write('<th colspan="5"><a href="http://www.dealii.org/websvn/revision.php?repname=deal.II+Repository&rev=%s">r%s</th>'%(rev.number,rev.number))
-f.write('</tr></thead>\n')
-
-f.write('<tbody><tr>')
-f.write('<td>ALL</td>')
+    f.write(
+        '<th colspan="5"><a href="http://www.dealii.org/websvn/revision.php?repname=deal.II+Repository&rev=%s">r%s</th>'
+        % (rev.number, rev.number)
+    )
+f.write("</tr></thead>\n")
+
+f.write("<tbody><tr>")
+f.write("<td>ALL</td>")
 for rev in revs:
-    if (rev.n_fail>0):
-        f.write('<td colspan="5" class="groupALL"><span class="fail">' + str(rev.n_fail) + '</span> / ' + str(rev.n_tests) + '</td>')
+    if rev.n_fail > 0:
+        f.write(
+            '<td colspan="5" class="groupALL"><span class="fail">'
+            + str(rev.n_fail)
+            + "</span> / "
+            + str(rev.n_tests)
+            + "</td>"
+        )
     else:
-        f.write('<td colspan="5" class="groupALL">' + str(rev.n_fail) + ' / ' + str(rev.n_tests) + '</td>')
-f.write('</tr></tbody>\n')
-
-#second header
+        f.write(
+            '<td colspan="5" class="groupALL">'
+            + str(rev.n_fail)
+            + " / "
+            + str(rev.n_tests)
+            + "</td>"
+        )
+f.write("</tr></tbody>\n")
+
+# second header
 f.write('<tbody><tr style="border-bottom: 2px solid">')
-f.write('<td></td>')
+f.write("<td></td>")
 for rev in revs:
-    for c in range(0,5):
+    for c in range(0, 5):
 
-        titles=['Configure','Build','Run','Diff','Pass']
-        caption=['C','B','R','D','P']
-        f.write('<td title="%s" class="test%d">%s</td>'%(titles[c],c,caption[c]))
-f.write('</tr></tbody>\n')
+        titles = ["Configure", "Build", "Run", "Diff", "Pass"]
+        caption = ["C", "B", "R", "D", "P"]
+        f.write('<td title="%s" class="test%d">%s</td>' % (titles[c], c, caption[c]))
+f.write("</tr></tbody>\n")
 
-counter=0
+counter = 0
 for group in allgroups:
-    counter+=1
-    if counter % 2==0:
+    counter += 1
+    if counter % 2 == 0:
         f.write('<tbody class="onerow"><tr>')
     else:
         f.write('<tbody class="otherrow"><tr>')
@@ -248,53 +268,55 @@ for group in allgroups:
             failing |= set(rev.groups[group].fail)
     failing = sorted(failing)
 
-    if (len(failing)>0):
-        f.write('<td><a href="#" onclick="toggle_id(\'group:%s\');return false">%s</a></td>'%(group,group))
+    if len(failing) > 0:
+        f.write(
+            '<td><a href="#" onclick="toggle_id(\'group:%s\');return false">%s</a></td>'
+            % (group, group)
+        )
     else:
-        f.write('<td>' + group + '</td>')
+        f.write("<td>" + group + "</td>")
 
     for rev in revs:
         if group not in rev.groups:
-            for c in range(0,5):
-                f.write('<td></td>')
+            for c in range(0, 5):
+                f.write("<td></td>")
         else:
             gr = rev.groups[group]
-            for c in range(0,5):
-                if gr.n_status[c]==0:
-                    f.write('<td></td>')
+            for c in range(0, 5):
+                if gr.n_status[c] == 0:
+                    f.write("<td></td>")
                 else:
-                    f.write('<td class="test%d">%d</td>'%(c,gr.n_status[c]))
-
-    f.write('</tr></tbody>\n')
+                    f.write('<td class="test%d">%d</td>' % (c, gr.n_status[c]))
 
+    f.write("</tr></tbody>\n")
 
-    #failing tests in group:
-    if len(failing)>0:
-        f.write('<tbody class="togglebody" style="display:none" id="group:%s">'%group)
+    # failing tests in group:
+    if len(failing) > 0:
+        f.write('<tbody class="togglebody" style="display:none" id="group:%s">' % group)
         for fail in failing:
-            f.write('<tr>')
-            name = fail[len(group):] # cut off group name
-            f.write('<td>&nbsp;' + name + '</td>')
+            f.write("<tr>")
+            name = fail[len(group) :]  # cut off group name
+            f.write("<td>&nbsp;" + name + "</td>")
             for rev in revs:
                 if group in rev.groups and fail in rev.groups[group].fail:
-                    status=rev.groups[group].fail_status[fail]
-                    text=rev.groups[group].fail_text[fail]
-                    for c in range(0,5):
-                        if c==status:
-                            f.write('<td class="test%d" title="%s">X</td>'%(c,text))
+                    status = rev.groups[group].fail_status[fail]
+                    text = rev.groups[group].fail_text[fail]
+                    for c in range(0, 5):
+                        if c == status:
+                            f.write('<td class="test%d" title="%s">X</td>' % (c, text))
                         else:
-                            f.write('<td></td>')
+                            f.write("<td></td>")
 
                 else:
                     f.write('<td colspan="5"></td>')
 
-            f.write('</tr>\n')
-        f.write('</tbody>\n')
+            f.write("</tr>\n")
+        f.write("</tbody>\n")
 
-    f.write('\n\n')
+    f.write("\n\n")
 
 
-f.write('</table>')
+f.write("</table>")
 
 
-f.write('</body></html>')
+f.write("</body></html>")
index 6599253bb317557925187489f4897c00af6c28d3..948e62376e0727d7bf3cdb812b5699fafcb01092 100755 (executable)
@@ -24,11 +24,11 @@ from scipy.optimize import rosen_der
 # dimension of Rosenbrok function
 dim = 20
 
-x0 = np.zeros(dim+1)
-one = np.ones(dim+1)
-location = np.zeros(dim+1)
-for i in range(dim+1):
-    location[i] = (1.*i)/dim
+x0 = np.zeros(dim + 1)
+one = np.ones(dim + 1)
+location = np.zeros(dim + 1)
+for i in range(dim + 1):
+    location[i] = (1.0 * i) / dim
 
 
 def v_rosen(theta):
@@ -39,13 +39,13 @@ def g_rosen(theta):
     return rosen_der(theta - location + one)
 
 
-x, min_val, info = fmin_l_bfgs_b(func=v_rosen,x0=x0,fprime=g_rosen,m=3, factr=10)
+x, min_val, info = fmin_l_bfgs_b(func=v_rosen, x0=x0, fprime=g_rosen, m=3, factr=10)
 dx = x - location
 
-print "{0} iterations".format(info['nit'])
-print "function value: {0}".format(min_val)
-print "linf_norm =     {0}".format(np.linalg.norm(dx,ord=np.inf))
-print "Gradient noorm: {0}".format(np.linalg.norm(g_rosen(x)))
-print "function calls: {0}".format(info['funcalls'])
-print "Solution:"
-print x
+print("{0} iterations".format(info["nit"]))
+print("function value: {0}".format(min_val))
+print("linf_norm =     {0}".format(np.linalg.norm(dx, ord=np.inf)))
+print("Gradient noorm: {0}".format(np.linalg.norm(g_rosen(x))))
+print("function calls: {0}".format(info["funcalls"]))
+print("Solution:")
+print(x)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.