Repository: systemml Updated Branches: refs/heads/master e6ee26a0e -> 56205d025
[SYSTEMML-2100] Extended JMLC API (configuration handling) This patch extends the JMLC API by set/reset functionality for dml configuration properties. In detail, we introduce an interface for configurable APIs in order to ensure API consistency across, for example, MLContext and JMLC. Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/4b5b14b8 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/4b5b14b8 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/4b5b14b8 Branch: refs/heads/master Commit: 4b5b14b8b2765b2f5e2d66da94623f71e71a5d9a Parents: e6ee26a Author: Matthias Boehm <[email protected]> Authored: Tue Jan 30 21:14:01 2018 -0800 Committer: Matthias Boehm <[email protected]> Committed: Tue Jan 30 21:14:01 2018 -0800 ---------------------------------------------------------------------- .../org/apache/sysml/api/ConfigurableAPI.java | 43 ++++++++++++++++++++ .../apache/sysml/api/jmlc/PreparedScript.java | 19 ++++++++- .../apache/sysml/api/mlcontext/MLContext.java | 20 +++------ .../java/org/apache/sysml/conf/DMLConfig.java | 20 ++++++--- 4 files changed, 80 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/4b5b14b8/src/main/java/org/apache/sysml/api/ConfigurableAPI.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/ConfigurableAPI.java b/src/main/java/org/apache/sysml/api/ConfigurableAPI.java new file mode 100644 index 0000000..427e33d --- /dev/null +++ b/src/main/java/org/apache/sysml/api/ConfigurableAPI.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.sysml.api; + +/** + * This interface defines the programmatic access to dml configuration properties + * (as defined in SystemML-config.xml) to ensure API consistency across all APIs. + */ +public interface ConfigurableAPI +{ + /** + * Reset configuration settings to default settings. + */ + public void resetConfig(); + + /** + * Set configuration property, such as + * {@code setConfigProperty("sysml.localtmpdir", "/tmp/systemml")}. + * + * @param propertyName + * property name + * @param propertyValue + * property value + */ + public void setConfigProperty(String propertyName, String propertyValue); +} http://git-wip-us.apache.org/repos/asf/systemml/blob/4b5b14b8/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java b/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java index dac211e..d52875a 100644 --- a/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java +++ b/src/main/java/org/apache/sysml/api/jmlc/PreparedScript.java @@ -28,6 +28,7 @@ import java.util.Map.Entry; import org.apache.commons.lang.NotImplementedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.sysml.api.ConfigurableAPI; import org.apache.sysml.api.DMLException; import org.apache.sysml.conf.CompilerConfig; import org.apache.sysml.conf.ConfigurationManager; @@ -37,6 +38,7 @@ import org.apache.sysml.hops.OptimizerUtils; import org.apache.sysml.hops.ipa.FunctionCallGraph; import org.apache.sysml.parser.DMLProgram; import org.apache.sysml.parser.Expression.ValueType; +import org.apache.sysml.runtime.DMLRuntimeException; import org.apache.sysml.runtime.controlprogram.FunctionProgramBlock; import org.apache.sysml.runtime.controlprogram.LocalVariableMap; import org.apache.sysml.runtime.controlprogram.Program; @@ -62,7 +64,7 @@ import org.apache.sysml.utils.Explain; /** * Representation of a prepared (precompiled) DML/PyDML script. */ -public class PreparedScript +public class PreparedScript implements ConfigurableAPI { private static final Log LOG = LogFactory.getLog(PreparedScript.class.getName()); @@ -122,6 +124,21 @@ public class PreparedScript _cconf = cconf; } + @Override + public void resetConfig() { + _dmlconf.set(new DMLConfig()); + } + + @Override + public void setConfigProperty(String propertyName, String propertyValue) { + try { + _dmlconf.setTextValue(propertyName, propertyValue); + } + catch( DMLRuntimeException e ) { + throw new RuntimeException(e); + } + } + /** * Binds a scalar boolean to a registered input variable. * http://git-wip-us.apache.org/repos/asf/systemml/blob/4b5b14b8/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java index 37bd309..acc69a0 100644 --- a/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java +++ b/src/main/java/org/apache/sysml/api/mlcontext/MLContext.java @@ -26,6 +26,7 @@ import org.apache.log4j.Logger; import org.apache.spark.SparkContext; import org.apache.spark.api.java.JavaSparkContext; import org.apache.spark.sql.SparkSession; +import org.apache.sysml.api.ConfigurableAPI; import org.apache.sysml.api.DMLScript; import org.apache.sysml.conf.ConfigurationManager; import org.apache.sysml.conf.DMLConfig; @@ -48,7 +49,8 @@ import org.apache.sysml.utils.MLContextProxy; * languages such as Scala, Java, and Python. * */ -public class MLContext { +public class MLContext implements ConfigurableAPI +{ /** * Logger for MLContext */ @@ -277,24 +279,12 @@ public class MLContext { MLContextUtil.setCompilerConfig(); } - /** - * Reset configuration settings to default settings. - */ + @Override public void resetConfig() { MLContextUtil.setDefaultConfig(); } - - - /** - * Set configuration property, such as - * {@code setConfigProperty("sysml.localtmpdir", "/tmp/systemml")}. - * - * @param propertyName - * property name - * @param propertyValue - * property value - */ + @Override public void setConfigProperty(String propertyName, String propertyValue) { DMLConfig config = ConfigurationManager.getDMLConfig(); try { http://git-wip-us.apache.org/repos/asf/systemml/blob/4b5b14b8/src/main/java/org/apache/sysml/conf/DMLConfig.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/conf/DMLConfig.java b/src/main/java/org/apache/sysml/conf/DMLConfig.java index b5db1c1..3e70e36 100644 --- a/src/main/java/org/apache/sysml/conf/DMLConfig.java +++ b/src/main/java/org/apache/sysml/conf/DMLConfig.java @@ -55,7 +55,6 @@ import org.xml.sax.SAXException; public class DMLConfig { - public static final String DEFAULT_SYSTEMML_CONFIG_FILEPATH = "./SystemML-config.xml"; private static final Log LOG = LogFactory.getLog(DMLConfig.class.getName()); @@ -104,7 +103,7 @@ public class DMLConfig //configuration default values private static HashMap<String, String> _defaultVals = null; - private String _fileName = null; + private String _fileName = null; private Element _xmlRoot = null; private DocumentBuilder _documentBuilder = null; private Document _document = null; @@ -141,8 +140,7 @@ public class DMLConfig _defaultVals.put(FLOATING_POINT_PRECISION, "double" ); } - public DMLConfig() - { + public DMLConfig() { } @@ -171,10 +169,20 @@ public class DMLConfig LOCAL_MR_MODE_STAGING_DIR = getTextValue(LOCAL_TMP_DIR) + "/hadoop/mapred/staging"; } - public DMLConfig( Element root ) - { + public DMLConfig( Element root ) { _xmlRoot = root; } + + public DMLConfig( DMLConfig dmlconf ) { + set(dmlconf); + } + + public void set(DMLConfig dmlconf) { + _fileName = dmlconf._fileName; + _xmlRoot = dmlconf._xmlRoot; + _documentBuilder = dmlconf._documentBuilder; + _document = dmlconf._document; + } /** * Method to parse configuration
