mailr24078 - /branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 18, 2014 - 11:31:
Author: bugman
Date: Wed Jun 18 11:31:35 2014
New Revision: 24078

URL: http://svn.gna.org/viewcvs/relax?rev=24078&view=rev
Log:
Created a super script for profiling the relaxation dispersion models.

This script will execute all of the current profiling scripts in the directory
test_suite/shared_data/dispersion/profiling for both the current version of 
relax and any other
specified version (current set to the 3.2.2 relax tag).  It will run the 
scripts and relax versions
interleaved N=10 times and extract the func_*() target function call profile 
timings.  This
interleaving makes the numbers much more consistent.  Averages and standard 
deviations are then
calculated, as well as the speed up between the two relax versions.  The 
results are printed out in
a format suitable for the relax release messages.


Added:
    
branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py

Added: 
branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py?rev=24078&view=auto
==============================================================================
--- 
branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py
    (added)
+++ 
branches/disp_spin_speed/test_suite/shared_data/dispersion/profiling/disp_profile_all.py
    Wed Jun 18 11:31:35 2014
@@ -0,0 +1,164 @@
+#!/usr/bin/env python
+
+###############################################################################
+#                                                                            
 #
+# Copyright (C) 2014 Edward d'Auvergne                                       
 #
+#                                                                            
 #
+# This file is part of the program relax (http://www.nmr-relax.com).         
 #
+#                                                                            
 #
+# This program is free software: you can redistribute it and/or modify       
 #
+# it under the terms of the GNU General Public License as published by       
 #
+# the Free Software Foundation, either version 3 of the License, or          
 #
+# (at your option) any later version.                                        
 #
+#                                                                            
 #
+# This program is distributed in the hope that it will be useful,            
 #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of             
 #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              
 #
+# GNU General Public License for more details.                               
 #
+#                                                                            
 #
+# You should have received a copy of the GNU General Public License          
 #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.      
 #
+#                                                                            
 #
+###############################################################################
+
+# Python script for obtaining profiling statistics for multiple models 
between the current and an alternative version of relax.
+
+# Python module imports.
+from numpy import average, float64, std, zeros
+from os import sep
+from re import search
+from shutil import copyfile
+from subprocess import PIPE, Popen
+import sys
+
+
+# The number of iterations to run each script for the statistics.
+N = 10
+
+# The models.
+models = [
+    'CR72',
+    'TSMFK01',
+    'B14'
+]
+
+# The current scripts.
+scripts = [
+    'profiling_cr72.py',
+    'profiling_tsmfk01.py',
+    'profiling_b14.py'
+]
+
+# Path to relax 3.2.2, or any other version.
+alt_path = '/data/relax/tags/3.2.2'
+
+# The Python executable name.
+python = 'python'
+
+
+# Copy the current scripts to the base directory of the alternative relax 
version.
+for script in scripts:
+    copyfile(script, alt_path+sep+script)
+
+# Initialise structures for the timing statistics.
+timings_new = {}
+timings_alt = {}
+for model in models:
+    timings_new[model] = zeros((2, N), float64)
+    timings_alt[model] = zeros((2, N), float64)
+timings = [timings_new, timings_alt]
+
+# Loop over the execution iterations.
+for exec_iter in range(N):
+    # Printout.
+    print("\n\nExecution iteration %i\n" % (exec_iter+1))
+
+    # Loop over each model.
+    for i in range(len(models)):
+        # The commands to run.
+        cmds = [
+            "%s %s" % (python, scripts[i]),
+            "%s %s %s" % (python, alt_path+sep+scripts[i], alt_path),
+        ]
+
+        # Loop over the commands.
+        for cmd_index in range(2):
+            # Printout.
+            print("$ %s" % cmds[cmd_index])
+
+            # Execute the current script.
+            pipe = Popen(cmds[cmd_index], shell=True, stdin=PIPE, 
stdout=PIPE, stderr=PIPE, close_fds=False)
+
+            # Close the pipe.
+            pipe.stdin.close()
+
+            # Write all errors to stderr.
+            err_lines = pipe.stderr.readlines()
+            for line in err_lines:
+                # Decode Python 3 byte arrays.
+                if hasattr(line, 'decode'):
+                    line = line.decode()
+
+                # Write.
+                sys.stderr.write(line)
+
+            # Process the output.
+            index = 0
+            for line in pipe.stdout.readlines():
+                # Decode Python 3 byte arrays.
+                if hasattr(line, 'decode'):
+                    line = line.decode()
+
+                # Find the profiling stats for the target function method.
+                if not search('func_', line):
+                    continue
+
+                # Printout for the record.
+                print(line[:-1])
+
+                # Split the line.
+                row = line.split()
+
+                # The timing.
+                timings[cmd_index][models[i]][index, exec_iter] = 
float(row[3])
+
+                # Increment the index.
+                index += 1
+
+# Statistics.
+ave_new = {}
+ave_new_cluster = {}
+ave_alt = {}
+ave_alt_cluster = {}
+sd_new = {}
+sd_new_cluster = {}
+sd_alt = {}
+sd_alt_cluster = {}
+speed_up = {}
+speed_up_cluster = {}
+
+# Loop over the models.
+for model in models:
+    # The averages.
+    ave_new[model] = average(timings_new[model][0])
+    ave_new_cluster[model] = average(timings_new[model][1])
+    ave_alt[model] = average(timings_alt[model][0])
+    ave_alt_cluster[model] = average(timings_alt[model][1])
+
+    # The SD.
+    sd_new[model] = std(timings_new[model][0])
+    sd_new_cluster[model] = std(timings_new[model][1])
+    sd_alt[model] = std(timings_alt[model][0])
+    sd_alt_cluster[model] = std(timings_alt[model][1])
+
+    # The speed up.
+    speed_up[model] = ave_alt[model] / ave_new[model]
+    speed_up_cluster[model] = ave_alt_cluster[model] / ave_new_cluster[model]
+
+# Final printout.
+print("\n\nSingle spin analysis:")
+for model in models:
+    print("%-10s:  %.3f+/-%.3f -> %.3f+/-%.3f, %.3fx faster." % (model, 
ave_new[model], sd_new[model], ave_alt[model], sd_alt[model], 
speed_up[model]))
+print("\nCluster of 100 spins analysis:")
+for model in models:
+    print("%-10s:  %.3f+/-%.3f -> %.3f+/-%.3f, %.3fx faster." % (model, 
ave_new_cluster[model], sd_new_cluster[model], ave_alt_cluster[model], 
sd_alt_cluster[model], speed_up_cluster[model]))




Related Messages


Powered by MHonArc, Updated Wed Jun 18 11:40:02 2014