Search in sources :

Example 76 with RUNTIME_PLATFORM

use of org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM in project incubator-systemml by apache.

the class CholeskyTest method runTestCholesky.

private void runTestCholesky(int rows, int cols, RUNTIME_PLATFORM rt) {
    RUNTIME_PLATFORM rtold = rtplatform;
    rtplatform = rt;
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    try {
        getAndLoadTestConfiguration(TEST_NAME);
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME + ".dml";
        programArgs = new String[] { "-args", input("A"), output("D") };
        double[][] A = getRandomMatrix(rows, cols, 0, 1, sparsity, 10);
        MatrixCharacteristics mc = new MatrixCharacteristics(rows, cols, -1, -1, -1);
        writeInputMatrixWithMTD("A", A, false, mc);
        // run tests and compare results
        runTest(true, false, null, -1);
        Assert.assertEquals(0, readDMLMatrixFromHDFS("D").get(new CellIndex(1, 1)), 1e-5);
    } finally {
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        rtplatform = rtold;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Example 77 with RUNTIME_PLATFORM

use of org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM in project incubator-systemml by apache.

the class EigenFactorizeTest method runTestEigenFactorize.

private void runTestEigenFactorize(int rows, RUNTIME_PLATFORM rt) {
    RUNTIME_PLATFORM rtold = rtplatform;
    rtplatform = rt;
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    try {
        getAndLoadTestConfiguration(TEST_NAME1);
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME1 + ".dml";
        programArgs = new String[] { "-args", input("A"), Integer.toString(numEigenValuesToEvaluate), output("D") };
        double[][] A = getRandomMatrix(rows, rows, 0, 1, sparsity, 10);
        MatrixCharacteristics mc = new MatrixCharacteristics(rows, rows, -1, -1, -1);
        writeInputMatrixWithMTD("A", A, false, mc);
        // Expected matrix = 1x1 zero matrix
        double[][] D = new double[numEigenValuesToEvaluate][1];
        for (int i = 0; i < numEigenValuesToEvaluate; i++) {
            D[i][0] = 0.0;
        }
        writeExpectedMatrix("D", D);
        boolean exceptionExpected = false;
        runTest(true, exceptionExpected, null, -1);
        compareResults(1e-8);
    } finally {
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        rtplatform = rtold;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) MatrixCharacteristics(org.apache.sysml.runtime.matrix.MatrixCharacteristics)

Example 78 with RUNTIME_PLATFORM

use of org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM in project incubator-systemml by apache.

the class FullCumminTest method runColAggregateOperationTest.

/**
 * @param sparseM1
 * @param sparseM2
 * @param instType
 */
private void runColAggregateOperationTest(InputType type, boolean sparse, ExecType instType, boolean rewrites) {
    RUNTIME_PLATFORM platformOld = rtplatform;
    switch(instType) {
        case MR:
            rtplatform = RUNTIME_PLATFORM.HADOOP;
            break;
        case SPARK:
            rtplatform = RUNTIME_PLATFORM.SPARK;
            break;
        default:
            rtplatform = RUNTIME_PLATFORM.HYBRID;
            break;
    }
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    // rewrites
    boolean oldFlagRewrites = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
    OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
    try {
        int cols = (type == InputType.COL_VECTOR) ? 1 : colsMatrix;
        int rows = (type == InputType.ROW_VECTOR) ? 1 : rowsMatrix;
        double sparsity = (sparse) ? spSparse : spDense;
        String TEST_CACHE_DIR = "";
        if (TEST_CACHE_ENABLED) {
            TEST_CACHE_DIR = type.ordinal() + "_" + sparsity + "/";
        }
        TestConfiguration config = getTestConfiguration(TEST_NAME);
        loadTestConfiguration(config, TEST_CACHE_DIR);
        // This is for running the junit test the new way, i.e., construct the arguments directly
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME + ".dml";
        programArgs = new String[] { "-explain", "-args", input("A"), output("B") };
        fullRScriptName = HOME + TEST_NAME + ".R";
        rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir() + " " + expectedDir();
        // generate actual dataset
        double[][] A = getRandomMatrix(rows, cols, -0.05, 1, sparsity, 7);
        writeInputMatrixWithMTD("A", A, true);
        runTest(true, false, null, -1);
        if (// in CP no MR jobs should be executed
        instType == ExecType.CP || instType == ExecType.SPARK)
            Assert.assertEquals("Unexpected number of executed MR jobs.", 0, Statistics.getNoOfExecutedMRJobs());
        runRScript(true);
        // compare matrices
        HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("B");
        HashMap<CellIndex, Double> rfile = readRMatrixFromFS("B");
        TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
    } finally {
        rtplatform = platformOld;
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlagRewrites;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 79 with RUNTIME_PLATFORM

use of org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM in project incubator-systemml by apache.

the class FullCumprodTest method runColAggregateOperationTest.

/**
 * @param sparseM1
 * @param sparseM2
 * @param instType
 */
private void runColAggregateOperationTest(InputType type, boolean sparse, ExecType instType, boolean rewrites) {
    RUNTIME_PLATFORM platformOld = rtplatform;
    switch(instType) {
        case MR:
            rtplatform = RUNTIME_PLATFORM.HADOOP;
            break;
        case SPARK:
            rtplatform = RUNTIME_PLATFORM.SPARK;
            break;
        default:
            rtplatform = RUNTIME_PLATFORM.HYBRID;
            break;
    }
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    // rewrites
    boolean oldFlagRewrites = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
    OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
    try {
        int cols = (type == InputType.COL_VECTOR) ? 1 : colsMatrix;
        int rows = (type == InputType.ROW_VECTOR) ? 1 : rowsMatrix;
        double sparsity = (sparse) ? spSparse : spDense;
        String TEST_CACHE_DIR = "";
        if (TEST_CACHE_ENABLED) {
            TEST_CACHE_DIR = type.ordinal() + "_" + sparsity + "/";
        }
        TestConfiguration config = getTestConfiguration(TEST_NAME);
        loadTestConfiguration(config, TEST_CACHE_DIR);
        // This is for running the junit test the new way, i.e., construct the arguments directly
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME + ".dml";
        programArgs = new String[] { "-explain", "-args", input("A"), output("B") };
        fullRScriptName = HOME + TEST_NAME + ".R";
        rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir() + " " + expectedDir();
        // generate actual dataset
        double[][] A = getRandomMatrix(rows, cols, 0.99, 1, sparsity, 7);
        writeInputMatrixWithMTD("A", A, true);
        runTest(true, false, null, -1);
        if (// in CP no MR jobs should be executed
        instType == ExecType.CP || instType == ExecType.SPARK)
            Assert.assertEquals("Unexpected number of executed MR jobs.", 0, Statistics.getNoOfExecutedMRJobs());
        runRScript(true);
        // compare matrices
        HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("B");
        HashMap<CellIndex, Double> rfile = readRMatrixFromFS("B");
        TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
    } finally {
        rtplatform = platformOld;
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlagRewrites;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Example 80 with RUNTIME_PLATFORM

use of org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM in project incubator-systemml by apache.

the class FullCumsumTest method runColAggregateOperationTest.

/**
 * @param sparseM1
 * @param sparseM2
 * @param instType
 */
private void runColAggregateOperationTest(InputType type, boolean sparse, ExecType instType, boolean rewrites) {
    RUNTIME_PLATFORM platformOld = rtplatform;
    switch(instType) {
        case MR:
            rtplatform = RUNTIME_PLATFORM.HADOOP;
            break;
        case SPARK:
            rtplatform = RUNTIME_PLATFORM.SPARK;
            break;
        default:
            rtplatform = RUNTIME_PLATFORM.HYBRID;
            break;
    }
    boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
    if (rtplatform == RUNTIME_PLATFORM.SPARK)
        DMLScript.USE_LOCAL_SPARK_CONFIG = true;
    // rewrites
    boolean oldFlagRewrites = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION;
    OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites;
    try {
        int cols = (type == InputType.COL_VECTOR) ? 1 : colsMatrix;
        int rows = (type == InputType.ROW_VECTOR) ? 1 : rowsMatrix;
        double sparsity = (sparse) ? spSparse : spDense;
        String TEST_CACHE_DIR = "";
        if (TEST_CACHE_ENABLED) {
            TEST_CACHE_DIR = type.ordinal() + "_" + sparsity + "/";
        }
        TestConfiguration config = getTestConfiguration(TEST_NAME);
        loadTestConfiguration(config, TEST_CACHE_DIR);
        // This is for running the junit test the new way, i.e., construct the arguments directly
        String HOME = SCRIPT_DIR + TEST_DIR;
        fullDMLScriptName = HOME + TEST_NAME + ".dml";
        programArgs = new String[] { "-explain", "-args", input("A"), output("B") };
        fullRScriptName = HOME + TEST_NAME + ".R";
        rCmd = "Rscript" + " " + fullRScriptName + " " + inputDir() + " " + expectedDir();
        // generate actual dataset
        double[][] A = getRandomMatrix(rows, cols, -0.05, 1, sparsity, 7);
        writeInputMatrixWithMTD("A", A, true);
        runTest(true, false, null, -1);
        if (// in CP no MR jobs should be executed
        instType == ExecType.CP || instType == ExecType.SPARK)
            Assert.assertEquals("Unexpected number of executed MR jobs.", 0, Statistics.getNoOfExecutedMRJobs());
        runRScript(true);
        // compare matrices
        HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("B");
        HashMap<CellIndex, Double> rfile = readRMatrixFromFS("B");
        TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
    } finally {
        rtplatform = platformOld;
        DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
        OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlagRewrites;
    }
}
Also used : RUNTIME_PLATFORM(org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM) CellIndex(org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration)

Aggregations

RUNTIME_PLATFORM (org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM)248 CellIndex (org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex)173 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)171 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)42 Test (org.junit.Test)17 FrameBlock (org.apache.sysml.runtime.matrix.data.FrameBlock)16 IOException (java.io.IOException)14 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)13 CSVFileFormatProperties (org.apache.sysml.runtime.matrix.data.CSVFileFormatProperties)9 FrameReader (org.apache.sysml.runtime.io.FrameReader)8 Random (java.util.Random)7 Row (org.apache.spark.sql.Row)5 ValueType (org.apache.sysml.parser.Expression.ValueType)5 HashMap (java.util.HashMap)4 DMLScript (org.apache.sysml.api.DMLScript)4 Script (org.apache.sysml.api.mlcontext.Script)4 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)4 Matrix (org.apache.sysml.api.mlcontext.Matrix)3 InputInfo (org.apache.sysml.runtime.matrix.data.InputInfo)3 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3