Package org.apache.sysds.api.mlcontext
Class MLContext
- java.lang.Object
- 
- org.apache.sysds.api.mlcontext.MLContext
 
- 
- All Implemented Interfaces:
- ConfigurableAPI
 
 public class MLContext extends Object implements ConfigurableAPI The MLContext API offers programmatic access to SystemDS on Spark from languages such as Scala, Java, and Python.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classMLContext.ExecutionTypeThe different types of execution environments supported by SystemDS.static classMLContext.ExplainLevelThe different explain levels supported by SystemDS.classMLContext.InternalProxyUsed internally by MLContextProxy.
 - 
Constructor SummaryConstructors Constructor Description MLContext(org.apache.spark.api.java.JavaSparkContext javaSparkContext)Create an MLContext based on a JavaSparkContext for interaction with SystemDS on Spark.MLContext(org.apache.spark.SparkContext sparkContext)Create an MLContext based on a SparkContext for interaction with SystemDS on Spark.MLContext(org.apache.spark.sql.SparkSession spark)Create an MLContext based on a SparkSession for interaction with SystemDS on Spark.
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringbuildTime()Obtain the SystemDS jar file build time.voidclose()Closes the mlcontext, which includes the cleanup of static and local state as well as scratch space and buffer pool cleanup.MLResultsexecute(Script script)Execute a DML or PYDML Script.MLResultsexecute(Script script, ScriptExecutor scriptExecutor)Execute a DML or PYDML Script object using a ScriptExecutor.static MLContextgetActiveMLContext()Retrieve the currently active MLContext.MLContext.ExecutionTypegetExecutionType()Obtain the current execution environment.MLContext.InternalProxygetInternalProxy()Used internally by MLContextProxy.org.apache.spark.sql.SparkSessiongetSparkSession()Obtain the SparkSession associated with this MLContext.intgetStatisticsMaxHeavyHitters()Obtain the maximum number of heavy hitters that are printed out as part of the statistics.ProjectInfoinfo()Obtain information about the project such as version and build time from the manifest in the SystemDS jar file.booleanisExplain()Whether or not an explanation of the DML/PYDML program should be output to standard output.booleanisForceGPU()Whether or not the "force" GPU mode is enabled.booleanisGPU()Whether or not the GPU mode is enabled.booleanisInitBeforeExecution()Whether or not the default ScriptExecutor should be initialized before execution.booleanisMaintainSymbolTable()Obtain whether or not all values should be maintained in the symbol table after execution.booleanisStatistics()Whether or not statistics of the DML/PYDML program execution should be output to standard output.voidresetConfig()Reset configuration settings to default settings.voidsetConfig(String configFilePath)Set SystemDS configuration based on a configuration file.voidsetConfigProperty(String propertyName, String propertyValue)Set configuration property, such assetConfigProperty("sysds.localtmpdir", "/tmp/systemds").voidsetExecutionScript(Script executionScript)Sets the script that is being executedvoidsetExecutionType(MLContext.ExecutionType executionType)Set the execution environment.voidsetExplain(boolean explain)Whether or not an explanation of the DML/PYDML program should be output to standard output.voidsetExplainLevel(String explainLevel)Set the level of program explanation that should be displayed if explain is set to true.voidsetExplainLevel(MLContext.ExplainLevel explainLevel)Set the level of program explanation that should be displayed if explain is set to true.voidsetForceGPU(boolean enable)Whether or not to explicitly "force" the usage of GPU.voidsetGPU(boolean enable)Whether or not to use (an available) GPU on the driver node.voidsetInitBeforeExecution(boolean initBeforeExecution)Whether or not the default ScriptExecutor should be initialized before execution.voidsetLineage(boolean lineage)Set whether or not lineage should be tracedvoidsetLineage(LineageCacheConfig.ReuseCacheType reuse)Set type of lineage-based reuse caching and enable lineage tracingvoidsetMaintainSymbolTable(boolean maintainSymbolTable)Set whether or not all values should be maintained in the symbol table after execution.voidsetStatistics(boolean statistics)Whether or not statistics of the DML/PYDML program execution should be output to standard output.voidsetStatisticsMaxHeavyHitters(int maxHeavyHitters)Sets the maximum number of heavy hitters that are printed out as part of the statistics.Stringversion()Obtain the SystemDS version number.
 
- 
- 
- 
Constructor Detail- 
MLContextpublic MLContext(org.apache.spark.sql.SparkSession spark) Create an MLContext based on a SparkSession for interaction with SystemDS on Spark.- Parameters:
- spark- SparkSession
 
 - 
MLContextpublic MLContext(org.apache.spark.SparkContext sparkContext) Create an MLContext based on a SparkContext for interaction with SystemDS on Spark.- Parameters:
- sparkContext- SparkContext
 
 - 
MLContextpublic MLContext(org.apache.spark.api.java.JavaSparkContext javaSparkContext) Create an MLContext based on a JavaSparkContext for interaction with SystemDS on Spark.- Parameters:
- javaSparkContext- JavaSparkContext
 
 
- 
 - 
Method Detail- 
getActiveMLContextpublic static MLContext getActiveMLContext() Retrieve the currently active MLContext. This is used internally by SystemDS via MLContextProxy.- Returns:
- the active MLContext
 
 - 
resetConfigpublic void resetConfig() Description copied from interface:ConfigurableAPIReset configuration settings to default settings.- Specified by:
- resetConfigin interface- ConfigurableAPI
 
 - 
setConfigPropertypublic void setConfigProperty(String propertyName, String propertyValue) Description copied from interface:ConfigurableAPISet configuration property, such assetConfigProperty("sysds.localtmpdir", "/tmp/systemds").- Specified by:
- setConfigPropertyin interface- ConfigurableAPI
- Parameters:
- propertyName- property name
- propertyValue- property value
 
 - 
executepublic MLResults execute(Script script) Execute a DML or PYDML Script.- Parameters:
- script- The DML or PYDML Script object to execute.
- Returns:
- the results as a MLResults object
 
 - 
executepublic MLResults execute(Script script, ScriptExecutor scriptExecutor) Execute a DML or PYDML Script object using a ScriptExecutor. The ScriptExecutor class can be extended to allow the modification of the default execution pathway.- Parameters:
- script- the DML or PYDML Script object
- scriptExecutor- the ScriptExecutor that defines the script execution pathway
- Returns:
- the results as a MLResults object
 
 - 
setExecutionScriptpublic void setExecutionScript(Script executionScript) Sets the script that is being executed- Parameters:
- executionScript- script that is being executed
 
 - 
setConfigpublic void setConfig(String configFilePath) Set SystemDS configuration based on a configuration file.- Parameters:
- configFilePath- path to the configuration file
 
 - 
getSparkSessionpublic org.apache.spark.sql.SparkSession getSparkSession() Obtain the SparkSession associated with this MLContext.- Returns:
- the SparkSession associated with this MLContext.
 
 - 
isExplainpublic boolean isExplain() Whether or not an explanation of the DML/PYDML program should be output to standard output.- Returns:
- trueif explanation should be output,- falseotherwise
 
 - 
setExplainpublic void setExplain(boolean explain) Whether or not an explanation of the DML/PYDML program should be output to standard output.- Parameters:
- explain-- trueif explanation should be output,- falseotherwise
 
 - 
setLineagepublic void setLineage(boolean lineage) Set whether or not lineage should be traced- Parameters:
- lineage-- trueif lineage should be traced,- falseotherwise
 
 - 
setLineagepublic void setLineage(LineageCacheConfig.ReuseCacheType reuse) Set type of lineage-based reuse caching and enable lineage tracing- Parameters:
- reuse- reuse cache type to use
 
 - 
isMaintainSymbolTablepublic boolean isMaintainSymbolTable() Obtain whether or not all values should be maintained in the symbol table after execution.- Returns:
- trueif all values should be maintained in the symbol table,- falseotherwise
 
 - 
setMaintainSymbolTablepublic void setMaintainSymbolTable(boolean maintainSymbolTable) Set whether or not all values should be maintained in the symbol table after execution.- Parameters:
- maintainSymbolTable-- trueif all values should be maintained in the symbol table,- falseotherwise
 
 - 
setExplainLevelpublic void setExplainLevel(MLContext.ExplainLevel explainLevel) Set the level of program explanation that should be displayed if explain is set to true.- Parameters:
- explainLevel- the level of program explanation
 
 - 
setExplainLevelpublic void setExplainLevel(String explainLevel) Set the level of program explanation that should be displayed if explain is set to true.- Parameters:
- explainLevel- string denoting program explanation
 
 - 
setGPUpublic void setGPU(boolean enable) Whether or not to use (an available) GPU on the driver node. If a GPU is not available, and the GPU mode is set, SystemDS will crash when the program is run.- Parameters:
- enable- true if needs to be enabled, false otherwise
 
 - 
setForceGPUpublic void setForceGPU(boolean enable) Whether or not to explicitly "force" the usage of GPU. If a GPU is not available, and the GPU mode is set or if available memory on GPU is less, SystemDS will crash when the program is run.- Parameters:
- enable- true if needs to be enabled, false otherwise
 
 - 
isGPUpublic boolean isGPU() Whether or not the GPU mode is enabled.- Returns:
- true if enabled, false otherwise
 
 - 
isForceGPUpublic boolean isForceGPU() Whether or not the "force" GPU mode is enabled.- Returns:
- true if enabled, false otherwise
 
 - 
getInternalProxypublic MLContext.InternalProxy getInternalProxy() Used internally by MLContextProxy.- Returns:
- InternalProxy object used by MLContextProxy
 
 - 
isStatisticspublic boolean isStatistics() Whether or not statistics of the DML/PYDML program execution should be output to standard output.- Returns:
- trueif statistics should be output,- falseotherwise
 
 - 
setStatisticspublic void setStatistics(boolean statistics) Whether or not statistics of the DML/PYDML program execution should be output to standard output.- Parameters:
- statistics-- trueif statistics should be output,- falseotherwise
 
 - 
setStatisticsMaxHeavyHitterspublic void setStatisticsMaxHeavyHitters(int maxHeavyHitters) Sets the maximum number of heavy hitters that are printed out as part of the statistics.- Parameters:
- maxHeavyHitters- maximum number of heavy hitters to print
 
 - 
closepublic void close() Closes the mlcontext, which includes the cleanup of static and local state as well as scratch space and buffer pool cleanup. Note that the spark context is not explicitly closed to allow external reuse.
 - 
infopublic ProjectInfo info() Obtain information about the project such as version and build time from the manifest in the SystemDS jar file.- Returns:
- information about the project
 
 - 
versionpublic String version() Obtain the SystemDS version number.- Returns:
- the SystemDS version number
 
 - 
buildTimepublic String buildTime() Obtain the SystemDS jar file build time.- Returns:
- the SystemDS jar file build time
 
 - 
getStatisticsMaxHeavyHitterspublic int getStatisticsMaxHeavyHitters() Obtain the maximum number of heavy hitters that are printed out as part of the statistics.- Returns:
- maximum number of heavy hitters to print
 
 - 
isInitBeforeExecutionpublic boolean isInitBeforeExecution() Whether or not the default ScriptExecutor should be initialized before execution.- Returns:
- trueif ScriptExecutor should be initialized before execution,- falseotherwise
 
 - 
setInitBeforeExecutionpublic void setInitBeforeExecution(boolean initBeforeExecution) Whether or not the default ScriptExecutor should be initialized before execution.- Parameters:
- initBeforeExecution-- trueif ScriptExecutor should be initialized before execution,- falseotherwise
 
 - 
getExecutionTypepublic MLContext.ExecutionType getExecutionType() Obtain the current execution environment.- Returns:
- the execution environment
 
 - 
setExecutionTypepublic void setExecutionType(MLContext.ExecutionType executionType) Set the execution environment.- Parameters:
- executionType- the execution environment
 
 
- 
 
-