Repository: incubator-systemml Updated Branches: refs/heads/master 5bde577a2 -> a1f1cf5a1
[SYSTEMML-508] Extend "executeScript" In MLContext To Accept PyDML. This adds the ability to run PyDML via `executeScript` from both Python and Scala. NOTE: This is simply a quick addition, as `MLContext` is receiving a major overhaul that will overwrite all of this. Closes #139. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/a1f1cf5a Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/a1f1cf5a Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/a1f1cf5a Branch: refs/heads/master Commit: a1f1cf5a1774ada129a44fc8360581915d133f85 Parents: 5bde577 Author: Mike Dusenberry <[email protected]> Authored: Mon May 9 10:37:21 2016 -0700 Committer: Mike Dusenberry <[email protected]> Committed: Mon May 9 10:37:21 2016 -0700 ---------------------------------------------------------------------- .../java/org/apache/sysml/api/MLContext.java | 41 +++++++++++++++++--- .../org/apache/sysml/api/python/SystemML.py | 4 +- 2 files changed, 38 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/a1f1cf5a/src/main/java/org/apache/sysml/api/MLContext.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/MLContext.java b/src/main/java/org/apache/sysml/api/MLContext.java index 41c5757..2600c35 100644 --- a/src/main/java/org/apache/sysml/api/MLContext.java +++ b/src/main/java/org/apache/sysml/api/MLContext.java @@ -1118,7 +1118,8 @@ public class MLContext { } /** - * Experimental API. Not supported in Python MLContext API. + * Execute a script stored in a string. + * * @param dmlScript * @return * @throws IOException @@ -1127,12 +1128,22 @@ public class MLContext { */ public MLOutput executeScript(String dmlScript) throws IOException, DMLException { - return compileAndExecuteScript(dmlScript, null, false, false, false, null); + return executeScript(dmlScript, false); } - + + public MLOutput executeScript(String dmlScript, boolean isPyDML) + throws IOException, DMLException { + return executeScript(dmlScript, isPyDML, null); + } + public MLOutput executeScript(String dmlScript, String configFilePath) throws IOException, DMLException { - return compileAndExecuteScript(dmlScript, null, false, false, false, configFilePath); + return executeScript(dmlScript, false, configFilePath); + } + + public MLOutput executeScript(String dmlScript, boolean isPyDML, String configFilePath) + throws IOException, DMLException { + return compileAndExecuteScript(dmlScript, null, false, false, isPyDML, configFilePath); } public MLOutput executeScript(String dmlScript, scala.collection.immutable.Map<String, String> namedArgs) @@ -1140,18 +1151,38 @@ public class MLContext { return executeScript(dmlScript, new HashMap<String, String>(scala.collection.JavaConversions.mapAsJavaMap(namedArgs)), null); } + public MLOutput executeScript(String dmlScript, scala.collection.immutable.Map<String, String> namedArgs, boolean isPyDML) + throws IOException, DMLException { + return executeScript(dmlScript, new HashMap<String, String>(scala.collection.JavaConversions.mapAsJavaMap(namedArgs)), isPyDML, null); + } + public MLOutput executeScript(String dmlScript, scala.collection.immutable.Map<String, String> namedArgs, String configFilePath) throws IOException, DMLException { return executeScript(dmlScript, new HashMap<String, String>(scala.collection.JavaConversions.mapAsJavaMap(namedArgs)), configFilePath); } + public MLOutput executeScript(String dmlScript, scala.collection.immutable.Map<String, String> namedArgs, boolean isPyDML, String configFilePath) + throws IOException, DMLException { + return executeScript(dmlScript, new HashMap<String, String>(scala.collection.JavaConversions.mapAsJavaMap(namedArgs)), isPyDML, configFilePath); + } + public MLOutput executeScript(String dmlScript, Map<String, String> namedArgs) throws IOException, DMLException { return executeScript(dmlScript, namedArgs, null); } + public MLOutput executeScript(String dmlScript, Map<String, String> namedArgs, boolean isPyDML) + throws IOException, DMLException { + return executeScript(dmlScript, namedArgs, isPyDML, null); + } + public MLOutput executeScript(String dmlScript, Map<String, String> namedArgs, String configFilePath) throws IOException, DMLException { + return executeScript(dmlScript, namedArgs, false, configFilePath); + } + + public MLOutput executeScript(String dmlScript, Map<String, String> namedArgs, boolean isPyDML, String configFilePath) + throws IOException, DMLException { String [] args = new String[namedArgs.size()]; int i = 0; for(Entry<String, String> entry : namedArgs.entrySet()) { @@ -1161,7 +1192,7 @@ public class MLContext { args[i] = entry.getKey() + "=" + entry.getValue(); i++; } - return compileAndExecuteScript(dmlScript, args, false, true, false, configFilePath); + return compileAndExecuteScript(dmlScript, args, false, true, isPyDML, configFilePath); } private void checkIfRegisteringInputAllowed() throws DMLRuntimeException { http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/a1f1cf5a/src/main/java/org/apache/sysml/api/python/SystemML.py ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/python/SystemML.py b/src/main/java/org/apache/sysml/api/python/SystemML.py index 361d533..7b834c5 100644 --- a/src/main/java/org/apache/sysml/api/python/SystemML.py +++ b/src/main/java/org/apache/sysml/api/python/SystemML.py @@ -100,7 +100,7 @@ class MLContext(object): except Py4JJavaError: traceback.print_exc() - def executeScript(self, dmlScript, nargs=None, outputs=None, configFilePath=None): + def executeScript(self, dmlScript, nargs=None, outputs=None, isPyDML=False, configFilePath=None): """ Executes the script in spark-mode by passing the arguments to the MLContext java class. @@ -125,7 +125,7 @@ class MLContext(object): self.registerOutput(out) # Execute script - jml_out = self.ml.executeScript(dmlScript, nargs, configFilePath) + jml_out = self.ml.executeScript(dmlScript, nargs, isPyDML, configFilePath) ml_out = MLOutput(jml_out, self.sc) return ml_out except Py4JJavaError:
