Search in sources :

Example 1 with ExplainType

use of org.apache.sysml.utils.Explain.ExplainType in project incubator-systemml by apache.

the class DMLScript method executeScript.

/**
	 * Single entry point for all public invocation alternatives (e.g.,
	 * main, executeScript, JaqlUdf etc)
	 * 
	 * @param conf Hadoop configuration
	 * @param args arguments
	 * @return true if success, false otherwise
	 * @throws DMLException if DMLException occurs
	 * @throws ParseException if ParseException occurs
	 */
public static boolean executeScript(Configuration conf, String[] args) throws DMLException {
    //parse arguments and set execution properties
    //keep old rtplatform
    RUNTIME_PLATFORM oldrtplatform = rtplatform;
    //keep old explain
    ExplainType oldexplain = EXPLAIN;
    Options options = createCLIOptions();
    try {
        DMLOptions dmlOptions = parseCLArguments(args, options);
        // String[] scriptArgs = null; //optional script arguments
        // boolean namedScriptArgs = false;
        STATISTICS = dmlOptions.stats;
        STATISTICS_COUNT = dmlOptions.statsCount;
        USE_ACCELERATOR = dmlOptions.gpu;
        FORCE_ACCELERATOR = dmlOptions.forceGPU;
        EXPLAIN = dmlOptions.explainType;
        ENABLE_DEBUG_MODE = dmlOptions.debug;
        SCRIPT_TYPE = dmlOptions.scriptType;
        rtplatform = dmlOptions.execMode;
        String fnameOptConfig = dmlOptions.configFile;
        boolean isFile = dmlOptions.filePath != null;
        String fileOrScript = isFile ? dmlOptions.filePath : dmlOptions.script;
        boolean help = dmlOptions.help;
        if (help) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("systemml", options);
            return true;
        }
        if (dmlOptions.clean) {
            cleanSystemMLWorkspace();
            return true;
        }
        //set log level
        if (!ENABLE_DEBUG_MODE)
            setLoggingProperties(conf);
        //Step 2: prepare script invocation
        if (isFile && StringUtils.endsWithIgnoreCase(fileOrScript, ".pydml")) {
            SCRIPT_TYPE = ScriptType.PYDML;
        }
        String dmlScriptStr = readDMLScript(isFile, fileOrScript);
        Map<String, String> argVals = dmlOptions.argVals;
        DML_FILE_PATH_ANTLR_PARSER = dmlOptions.filePath;
        //Step 3: invoke dml script
        printInvocationInfo(fileOrScript, fnameOptConfig, argVals);
        if (ENABLE_DEBUG_MODE) {
            // inner try loop is just to isolate the debug exception, which will allow to manage the bugs from debugger v/s runtime
            launchDebugger(dmlScriptStr, fnameOptConfig, argVals, SCRIPT_TYPE);
        } else {
            execute(dmlScriptStr, fnameOptConfig, argVals, args, SCRIPT_TYPE);
        }
    } catch (AlreadySelectedException e) {
        System.err.println("Mutually exclusive options were selected. " + e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("systemml", options);
        return false;
    } catch (org.apache.commons.cli.ParseException e) {
        System.err.println(e.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("systemml", options);
    } catch (ParseException pe) {
        throw pe;
    } catch (DMLScriptException e) {
        //rethrow DMLScriptException to propagate stop call
        throw e;
    } catch (Exception ex) {
        LOG.error("Failed to execute DML script.", ex);
        throw new DMLException(ex);
    } finally {
        //reset runtime platform and visualize flag
        rtplatform = oldrtplatform;
        EXPLAIN = oldexplain;
    }
    return true;
}
Also used : Options(org.apache.commons.cli.Options) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) HopsException(org.apache.sysml.hops.HopsException) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) LopsException(org.apache.sysml.lops.LopsException) LanguageException(org.apache.sysml.parser.LanguageException) IOException(java.io.IOException) AlreadySelectedException(org.apache.commons.cli.AlreadySelectedException) ParseException(org.apache.sysml.parser.ParseException) DMLDebuggerException(org.apache.sysml.debug.DMLDebuggerException) HelpFormatter(org.apache.commons.cli.HelpFormatter) ExplainType(org.apache.sysml.utils.Explain.ExplainType) DMLScriptException(org.apache.sysml.runtime.DMLScriptException) ParseException(org.apache.sysml.parser.ParseException)

Example 2 with ExplainType

use of org.apache.sysml.utils.Explain.ExplainType in project incubator-systemml by apache.

the class ScriptExecutor method setExplainLevel.

/**
	 * Set the level of program explanation that should be displayed if explain
	 * is set to true.
	 * 
	 * @param explainLevel
	 *            the level of program explanation
	 */
public void setExplainLevel(ExplainLevel explainLevel) {
    this.explainLevel = explainLevel;
    if (explainLevel == null) {
        DMLScript.EXPLAIN = ExplainType.NONE;
    } else {
        ExplainType explainType = explainLevel.getExplainType();
        DMLScript.EXPLAIN = explainType;
    }
}
Also used : ExplainType(org.apache.sysml.utils.Explain.ExplainType)

Example 3 with ExplainType

use of org.apache.sysml.utils.Explain.ExplainType in project incubator-systemml by apache.

the class ScriptExecutor method showExplanation.

/**
	 * Output a description of the program to standard output.
	 */
protected void showExplanation() {
    if (!explain)
        return;
    try {
        ExplainType explainType = (explainLevel != null) ? explainLevel.getExplainType() : ExplainType.RUNTIME;
        System.out.println(Explain.explain(dmlProgram, runtimeProgram, explainType));
    } catch (Exception e) {
        throw new MLContextException("Exception occurred while explaining dml program", e);
    }
}
Also used : ExplainType(org.apache.sysml.utils.Explain.ExplainType) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException) LopsException(org.apache.sysml.lops.LopsException) LanguageException(org.apache.sysml.parser.LanguageException) HopsException(org.apache.sysml.hops.HopsException) IOException(java.io.IOException) ParseException(org.apache.sysml.parser.ParseException)

Aggregations

ExplainType (org.apache.sysml.utils.Explain.ExplainType)3 IOException (java.io.IOException)2 HopsException (org.apache.sysml.hops.HopsException)2 LopsException (org.apache.sysml.lops.LopsException)2 LanguageException (org.apache.sysml.parser.LanguageException)2 ParseException (org.apache.sysml.parser.ParseException)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2 AlreadySelectedException (org.apache.commons.cli.AlreadySelectedException)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1 DMLDebuggerException (org.apache.sysml.debug.DMLDebuggerException)1 DMLScriptException (org.apache.sysml.runtime.DMLScriptException)1