Search in sources :

Example 6 with DMLException

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

the class FrameIndexingAppendTest method execDMLScriptviaJMLC.

/**
	 * 
	 * @param X
	 * @return
	 * @throws DMLException
	 * @throws IOException
	 */
private ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, String[][] M, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<String[][]> ret = new ArrayList<String[][]>();
    //establish connection to SystemML
    Connection conn = new Connection();
    try {
        //prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC1", "{ \"ids\": true ,\"recode\": [ 1, 2] }");
        args.put("$TRANSFORM_SPEC2", "{ \"ids\": true ,\"recode\": [ 1] }");
        //read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
        if (modelReuse)
            pstmt.setFrame("M", M, true);
        //execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            //bind input parameters
            if (!modelReuse)
                pstmt.setFrame("M", M);
            pstmt.setFrame("F1", F1);
            //execute script
            ResultVariables rs = pstmt.executeScript();
            //get output parameter
            String[][] Y = rs.getFrame("F2");
            //keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) DMLException(org.apache.sysml.api.DMLException) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 7 with DMLException

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

the class FrameCastingTest method execDMLScriptviaJMLC.

/**
	 * 
	 * @param X
	 * @return
	 * @throws DMLException
	 * @throws IOException
	 */
private ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<String[][]> ret = new ArrayList<String[][]>();
    //establish connection to SystemML
    Connection conn = new Connection();
    try {
        //prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC", "{ \"ids\": true ,\"recode\": [ 1, 2, 3] }");
        //read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
        if (modelReuse)
            pstmt.setFrame("F1", F1, true);
        //execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            //bind input parameters
            if (!modelReuse)
                pstmt.setFrame("F1", F1);
            //execute script
            ResultVariables rs = pstmt.executeScript();
            //get output parameter
            String[][] Y = rs.getFrame("F2");
            //keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) DMLException(org.apache.sysml.api.DMLException) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 8 with DMLException

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

the class FrameDecodeTest method execDMLScriptviaJMLC.

/**
	 * 
	 * @param X
	 * @return
	 * @throws DMLException
	 * @throws IOException
	 */
private ArrayList<String[][]> execDMLScriptviaJMLC(String testname, String[][] F1, String[][] M, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<String[][]> ret = new ArrayList<String[][]>();
    //establish connection to SystemML
    Connection conn = new Connection();
    try {
        //prepare input arguments
        HashMap<String, String> args = new HashMap<String, String>();
        args.put("$TRANSFORM_SPEC", "{ \"ids\": true ,\"recode\": [ 1, 2, 3] }");
        //read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, args, new String[] { "F1", "M" }, new String[] { "F2" }, false);
        if (modelReuse)
            pstmt.setFrame("M", M, true);
        //execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            //bind input parameters
            if (!modelReuse)
                pstmt.setFrame("M", M);
            pstmt.setFrame("F1", F1);
            //execute script
            ResultVariables rs = pstmt.executeScript();
            //get output parameter
            String[][] Y = rs.getFrame("F2");
            //keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) HashMap(java.util.HashMap) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) IOException(java.io.IOException) IOException(java.io.IOException) DMLException(org.apache.sysml.api.DMLException) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)

Example 9 with DMLException

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

the class ResultVariables method getMatrix.

/**
	 * Obtain the matrix represented by the given output variable.
	 * 
	 * @param varname output variable name
	 * @return matrix as a two-dimensional double array
	 * @throws DMLException if DMLException occurs
	 */
public double[][] getMatrix(String varname) throws DMLException {
    if (!_out.containsKey(varname))
        throw new DMLException("Non-existent output variable: " + varname);
    double[][] ret = null;
    Data dat = _out.get(varname);
    //basic checks for data type	
    if (!(dat instanceof MatrixObject))
        throw new DMLException("Expected matrix result '" + varname + "' not a matrix.");
    //convert output matrix to double array	
    MatrixObject mo = (MatrixObject) dat;
    MatrixBlock mb = mo.acquireRead();
    ret = DataConverter.convertToDoubleMatrix(mb);
    mo.release();
    return ret;
}
Also used : MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) MatrixObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject) DMLException(org.apache.sysml.api.DMLException) Data(org.apache.sysml.runtime.instructions.cp.Data)

Example 10 with DMLException

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

the class ReuseModelVariablesTest method execDMLScriptviaJMLC.

/**
	 * 
	 * @param X
	 * @return
	 * @throws DMLException
	 * @throws IOException
	 */
private ArrayList<double[][]> execDMLScriptviaJMLC(String testname, ArrayList<double[][]> X, boolean modelReuse) throws IOException {
    Timing time = new Timing(true);
    ArrayList<double[][]> ret = new ArrayList<double[][]>();
    //establish connection to SystemML
    Connection conn = new Connection();
    try {
        // For now, JMLC pipeline only allows dml
        boolean parsePyDML = false;
        //read and precompile script
        String script = conn.readScript(SCRIPT_DIR + TEST_DIR + testname + ".dml");
        PreparedScript pstmt = conn.prepareScript(script, new String[] { "X", "W" }, new String[] { "predicted_y" }, parsePyDML);
        //read model
        String modelData = conn.readScript(SCRIPT_DIR + TEST_DIR + MODEL_FILE);
        double[][] W = conn.convertToDoubleMatrix(modelData, rows, cols);
        if (modelReuse)
            pstmt.setMatrix("W", W, true);
        //execute script multiple times
        for (int i = 0; i < nRuns; i++) {
            //bind input parameters
            if (!modelReuse)
                pstmt.setMatrix("W", W);
            pstmt.setMatrix("X", X.get(i));
            //execute script
            ResultVariables rs = pstmt.executeScript();
            //get output parameter
            double[][] Y = rs.getMatrix("predicted_y");
            //keep result for comparison
            ret.add(Y);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new IOException(ex);
    } finally {
        IOUtilFunctions.closeSilently(conn);
    }
    System.out.println("JMLC scoring w/ " + nRuns + " runs in " + time.stop() + "ms.");
    return ret;
}
Also used : PreparedScript(org.apache.sysml.api.jmlc.PreparedScript) ResultVariables(org.apache.sysml.api.jmlc.ResultVariables) ArrayList(java.util.ArrayList) Connection(org.apache.sysml.api.jmlc.Connection) Timing(org.apache.sysml.runtime.controlprogram.parfor.stat.Timing) IOException(java.io.IOException) IOException(java.io.IOException) DMLException(org.apache.sysml.api.DMLException)

Aggregations

DMLException (org.apache.sysml.api.DMLException)13 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 Connection (org.apache.sysml.api.jmlc.Connection)8 PreparedScript (org.apache.sysml.api.jmlc.PreparedScript)8 ResultVariables (org.apache.sysml.api.jmlc.ResultVariables)8 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)8 HashMap (java.util.HashMap)6 FrameObject (org.apache.sysml.runtime.controlprogram.caching.FrameObject)2 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)2 Data (org.apache.sysml.runtime.instructions.cp.Data)2 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)2 MatrixFormatMetaData (org.apache.sysml.runtime.matrix.MatrixFormatMetaData)2 ProgramRewriter (org.apache.sysml.hops.rewrite.ProgramRewriter)1 RewriteRemovePersistentReadWrite (org.apache.sysml.hops.rewrite.RewriteRemovePersistentReadWrite)1 DMLProgram (org.apache.sysml.parser.DMLProgram)1 DMLTranslator (org.apache.sysml.parser.DMLTranslator)1 ParseException (org.apache.sysml.parser.ParseException)1 ParserWrapper (org.apache.sysml.parser.ParserWrapper)1 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1