Repository: systemml
Updated Branches:
  refs/heads/master 31580f52d -> f4a399730


[MINOR] Fix flaky jmlc test (potential side effects over tmp files)

Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/f4a39973
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/f4a39973
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/f4a39973

Branch: refs/heads/master
Commit: f4a399730e8b98e11e5421cec2b123b1dabac1c7
Parents: 31580f5
Author: Matthias Boehm <[email protected]>
Authored: Mon May 14 20:49:32 2018 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Mon May 14 20:49:32 2018 -0700

----------------------------------------------------------------------
 .../functions/jmlc/MulticlassSVMScoreTest.java  | 74 ++++++--------------
 src/test/scripts/functions/jmlc/m-svm-score.dml | 17 ++---
 2 files changed, 26 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/f4a39973/src/test/java/org/apache/sysml/test/integration/functions/jmlc/MulticlassSVMScoreTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/sysml/test/integration/functions/jmlc/MulticlassSVMScoreTest.java
 
b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/MulticlassSVMScoreTest.java
index d082b41..b51dc14 100644
--- 
a/src/test/java/org/apache/sysml/test/integration/functions/jmlc/MulticlassSVMScoreTest.java
+++ 
b/src/test/java/org/apache/sysml/test/integration/functions/jmlc/MulticlassSVMScoreTest.java
@@ -53,10 +53,6 @@ public class MulticlassSVMScoreTest extends AutomatedTestBase
        private final static double sparsity1 = 0.7;
        private final static double sparsity2 = 0.1;
        
-       //This testcase recently caused intermittent test failures on jenkins 
that are not 
-       //reproducible in local environments; hence we perform additional 
sanity checks here.
-       private final static boolean CHECK_IN_OUT = true;
-       
        @Override
        public void setUp() {
                addTestConfiguration(TEST_NAME, new 
TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] { "predicted_y" }) ); 
@@ -89,57 +85,42 @@ public class MulticlassSVMScoreTest extends 
AutomatedTestBase
                loadTestConfiguration(config);
        
                //generate inputs
-               ArrayList<double[][]> Xset = generateInputs(nRuns, rows, cols, 
sparse?sparsity2:sparsity1);
-               if( CHECK_IN_OUT )
-                       checkSelfEquivalence(Xset, rows, cols);
+               ArrayList<double[][]> Xset = generateInputs(nRuns, rows, cols, 
sparse?sparsity2:sparsity1, 7);
                
                //run DML via JMLC
                ArrayList<double[][]> Yset = execDMLScriptviaJMLC( Xset, flags 
);
-               if( CHECK_IN_OUT )
-                       checkSelfEquivalence(Yset, rows, 1);
                
-               //run R and compare results to DML result
+               //write out R input and model once
+               MatrixBlock mb = DataConverter.readMatrixFromHDFS(SCRIPT_DIR + 
TEST_DIR + MODEL_FILE,
+                       InputInfo.TextCellInputInfo, rows, cols, 1000, 1000);
+               writeInputMatrix("X", Xset.get(0), true);
+               writeInputMatrix("W", DataConverter.convertToDoubleMatrix(mb), 
true);
+               
+               //run R test once
                String HOME = SCRIPT_DIR + TEST_DIR;
                fullRScriptName = HOME + TEST_NAME + ".R";
                rCmd = getRCmd(inputDir(), expectedDir());
-
-               //write model data once
-               MatrixBlock mb = DataConverter.readMatrixFromHDFS(SCRIPT_DIR + 
TEST_DIR + MODEL_FILE,
-                               InputInfo.TextCellInputInfo, rows, cols, 1000, 
1000);
-               double[][] W = DataConverter.convertToDoubleMatrix( mb );
-               writeInputMatrix("W", W, true);
+               runRScript(true);
                
-               //for each input data set
-               int lnRuns = CHECK_IN_OUT ? 1 : nRuns;
-               for( int i=0; i<lnRuns; i++ ) {
-                       //write input data
-                       writeInputMatrix("X", Xset.get(i), true);
-                       
-                       //run the R script
-                       runRScript(true); 
-                       
-                       //compare results
-                       HashMap<CellIndex, Double> rfile = 
readRMatrixFromFS("predicted_y");
-                       double[][] expected = 
TestUtils.convertHashMapToDoubleArray(rfile, rows, 1);
-                       
+               //read and convert R output
+               HashMap<CellIndex, Double> rfile = 
readRMatrixFromFS("predicted_y");
+               double[][] expected = 
TestUtils.convertHashMapToDoubleArray(rfile, rows, 1);
+               
+               //for each input data set compare results
+               for( int i=0; i<nRuns; i++ )
                        TestUtils.compareMatrices(expected, Yset.get(i), rows, 
1, eps);
-               }
        }
 
        private static ArrayList<double[][]> 
execDMLScriptviaJMLC(ArrayList<double[][]> X, boolean flags) 
                throws IOException
        {
                Timing time = new Timing(true);
-               
                ArrayList<double[][]> ret = new ArrayList<double[][]>();
                
-               //establish connection to SystemML
-               Connection conn = !flags ? new Connection():
+               try( Connection conn = !flags ? new Connection():
                        new Connection(ConfigType.PARALLEL_CP_MATRIX_OPERATIONS,
-                               ConfigType.PARALLEL_LOCAL_OR_REMOTE_PARFOR,
-                               ConfigType.ALLOW_DYN_RECOMPILATION);
-               
-               try
+                       ConfigType.PARALLEL_LOCAL_OR_REMOTE_PARFOR,
+                       ConfigType.ALLOW_DYN_RECOMPILATION) )
                {
                        // For now, JMLC pipeline only allows dml
                        boolean parsePyDML = false;
@@ -168,31 +149,18 @@ public class MulticlassSVMScoreTest extends 
AutomatedTestBase
                        }
                }
                catch(Exception ex) {
-                       ex.printStackTrace();
                        throw new IOException(ex);
                }
-               finally {
-                       if( conn != null )
-                               conn.close();
-               }
                
                System.out.println("JMLC scoring w/ "+nRuns+" runs in 
"+time.stop()+"ms.");
                
                return ret;
        }
 
-       private ArrayList<double[][]> generateInputs( int num, int rows, int 
cols, double sparsity ) {
+       private ArrayList<double[][]> generateInputs( int num, int rows, int 
cols, double sparsity, int seed ) {
                ArrayList<double[][]> ret = new ArrayList<double[][]>();
                for( int i=0; i<num; i++ )
-                       ret.add(getRandomMatrix(rows, cols, -1, 1, sparsity, 
7));
+                       ret.add(getRandomMatrix(rows, cols, -1, 1, sparsity, 
seed));
                return ret;
        }
-       
-       private void checkSelfEquivalence(ArrayList<double[][]> data, int rows, 
int cols) {
-               if( data == null || data.size() < 2 )
-                       return;
-               double[][] data0 = data.get(0);
-               for(int i=1; i<data.size(); i++)
-                       TestUtils.compareMatrices(data0, data.get(i), rows, 
cols, eps);
-       }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/f4a39973/src/test/scripts/functions/jmlc/m-svm-score.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/jmlc/m-svm-score.dml 
b/src/test/scripts/functions/jmlc/m-svm-score.dml
index a371e53..58eba75 100644
--- a/src/test/scripts/functions/jmlc/m-svm-score.dml
+++ b/src/test/scripts/functions/jmlc/m-svm-score.dml
@@ -19,17 +19,10 @@
 #
 #-------------------------------------------------------------
 
-X = read("./tmp/X", rows=-1, cols=-1);
-W = read("./tmp/W", rows=-1, cols=-1);
-
-Nt = nrow(X);
-num_classes = ncol(W)
-n = ncol(X);
-
-b = W[n+1,]
-ones = matrix(1, rows=Nt, cols=1)
-scores = X %*% W[1:n,] + ones %*% b;
+X = read($1);
+W = read($2);
 
+scores = X %*% W[1:ncol(X),] + W[ncol(X)+1,];
 predicted_y = rowIndexMax(scores);
-write(predicted_y, "./tmp", format="text");
-  
\ No newline at end of file
+
+write(predicted_y, $3);

Reply via email to