Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYSTEMDS-3842] Improve test coverage of API components #2241

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions src/main/java/org/apache/sysds/api/DMLOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,34 +141,32 @@ public static DMLOptions parseCLArguments(String[] args)
String lineageTypes[] = line.getOptionValues("lineage");
if (lineageTypes != null) {
for (String lineageType : lineageTypes) {
if (lineageType != null){
if (lineageType.equalsIgnoreCase("dedup"))
dmlOptions.lineage_dedup = lineageType.equalsIgnoreCase("dedup");
else if (lineageType.equalsIgnoreCase("reuse_full")
|| lineageType.equalsIgnoreCase("reuse"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_FULL;
else if (lineageType.equalsIgnoreCase("reuse_partial"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_PARTIAL;
else if (lineageType.equalsIgnoreCase("reuse_multilevel"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_MULTILEVEL;
else if (lineageType.equalsIgnoreCase("reuse_hybrid"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_HYBRID;
else if (lineageType.equalsIgnoreCase("none"))
dmlOptions.linReuseType = ReuseCacheType.NONE;
else if (lineageType.equalsIgnoreCase("policy_lru"))
dmlOptions.linCachePolicy = LineageCachePolicy.LRU;
else if (lineageType.equalsIgnoreCase("policy_costnsize"))
dmlOptions.linCachePolicy = LineageCachePolicy.COSTNSIZE;
else if (lineageType.equalsIgnoreCase("policy_dagheight"))
dmlOptions.linCachePolicy = LineageCachePolicy.DAGHEIGHT;
else if (lineageType.equalsIgnoreCase("estimate"))
dmlOptions.lineage_estimate = lineageType.equalsIgnoreCase("estimate");
else if (lineageType.equalsIgnoreCase("debugger"))
dmlOptions.lineage_debugger = lineageType.equalsIgnoreCase("debugger");
else
throw new org.apache.commons.cli.ParseException(
"Invalid argument specified for -lineage option: " + lineageType);
}
if (lineageType.equalsIgnoreCase("dedup"))
dmlOptions.lineage_dedup = lineageType.equalsIgnoreCase("dedup");
else if (lineageType.equalsIgnoreCase("reuse_full")
|| lineageType.equalsIgnoreCase("reuse"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_FULL;
else if (lineageType.equalsIgnoreCase("reuse_partial"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_PARTIAL;
else if (lineageType.equalsIgnoreCase("reuse_multilevel"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_MULTILEVEL;
else if (lineageType.equalsIgnoreCase("reuse_hybrid"))
dmlOptions.linReuseType = ReuseCacheType.REUSE_HYBRID;
else if (lineageType.equalsIgnoreCase("none"))
dmlOptions.linReuseType = ReuseCacheType.NONE;
else if (lineageType.equalsIgnoreCase("policy_lru"))
dmlOptions.linCachePolicy = LineageCachePolicy.LRU;
else if (lineageType.equalsIgnoreCase("policy_costnsize"))
dmlOptions.linCachePolicy = LineageCachePolicy.COSTNSIZE;
else if (lineageType.equalsIgnoreCase("policy_dagheight"))
dmlOptions.linCachePolicy = LineageCachePolicy.DAGHEIGHT;
else if (lineageType.equalsIgnoreCase("estimate"))
dmlOptions.lineage_estimate = true;
else if (lineageType.equalsIgnoreCase("debugger"))
dmlOptions.lineage_debugger = true;
else
throw new org.apache.commons.cli.ParseException(
"Invalid argument specified for -lineage option: " + lineageType);
}
}
}
Expand All @@ -186,13 +184,11 @@ else if (lineageType.equalsIgnoreCase("debugger"))
}
if (line.hasOption("exec")){
String execMode = line.getOptionValue("exec");
if (execMode != null){
if (execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = ExecMode.SINGLE_NODE;
else if (execMode.equalsIgnoreCase("hybrid")) dmlOptions.execMode = ExecMode.HYBRID;
else if (execMode.equalsIgnoreCase("spark")) dmlOptions.execMode = ExecMode.SPARK;
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -exec option, must be one of [hadoop, singlenode, hybrid, HYBRID, spark]");
}
}
if (execMode.equalsIgnoreCase("singlenode")) dmlOptions.execMode = ExecMode.SINGLE_NODE;
else if (execMode.equalsIgnoreCase("hybrid")) dmlOptions.execMode = ExecMode.HYBRID;
else if (execMode.equalsIgnoreCase("spark")) dmlOptions.execMode = ExecMode.SPARK;
else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -exec option, must be one of [hadoop, singlenode, hybrid, HYBRID, spark]");
}
if (line.hasOption("explain")) {
dmlOptions.explainType = ExplainType.RUNTIME;
String explainType = line.getOptionValue("explain");
Expand Down Expand Up @@ -222,7 +218,7 @@ else if (lineageType.equalsIgnoreCase("debugger"))
dmlOptions.statsNGrams = line.hasOption("ngrams");
if (dmlOptions.statsNGrams){
String[] nGramArgs = line.getOptionValues("ngrams");
if (nGramArgs.length >= 2) {
if (nGramArgs != null && nGramArgs.length >= 2) {
try {
String[] nGramSizeSplit = nGramArgs[0].split(",");
dmlOptions.statsNGramSizes = new int[nGramSizeSplit.length];
Expand Down Expand Up @@ -273,11 +269,17 @@ else if (lineageType.equalsIgnoreCase("debugger"))

if (line.hasOption("fedMonitoring")) {
dmlOptions.fedMonitoring= true;
dmlOptions.fedMonitoringPort = Integer.parseInt(line.getOptionValue("fedMonitoring"));
String port = line.getOptionValue("fedMonitoring");
if(port != null)
dmlOptions.fedMonitoringPort = Integer.parseInt(port);
else
throw new org.apache.commons.cli.ParseException("No port [integer] specified for -fedMonitoring option");
}

if (line.hasOption("fedMonitoringAddress")) {
dmlOptions.fedMonitoringAddress = line.getOptionValue("fedMonitoringAddress");
if(dmlOptions.fedMonitoringAddress == null)
throw new org.apache.commons.cli.ParseException("No address [String] specified for -fedMonitoringAddress option");
}

if (line.hasOption("f")){
Expand Down Expand Up @@ -326,7 +328,7 @@ else if (lineageType.equalsIgnoreCase("debugger"))
OptimizerUtils.FEDERATED_COMPILATION = true;
dmlOptions.federatedCompilation = true;
String[] fedCompSpecs = line.getOptionValues("federatedCompilation");
if ( fedCompSpecs != null && fedCompSpecs.length > 0 ){
if (fedCompSpecs != null){
for ( String spec : fedCompSpecs ){
String[] specPair = spec.split("=");
if (specPair.length != 2){
Expand Down Expand Up @@ -370,8 +372,8 @@ private static Options createCLIOptions() {
.withDescription("monitors and reports summary execution statistics; heavy hitter <count> is 10 unless overridden; default off")
.hasOptionalArg().create("stats");
Option ngramsOpt = OptionBuilder//.withArgName("ngrams")
.withDescription("monitors and reports the most occurring n-grams; -ngrams <comma separated n's> <topK>")
.hasOptionalArgs(2).create("ngrams");
.withDescription("monitors and reports the most occurring n-grams; -ngrams <comma separated n's> <topK> <boolean lineage>")
.hasOptionalArgs(3).create("ngrams");
Option fedStatsOpt = OptionBuilder.withArgName("count")
.withDescription("monitors and reports summary execution statistics of federated workers; heavy hitter <count> is 10 unless overridden; default off")
.hasOptionalArg().create("fedStats");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static void loadNativeCodeGenerator(GeneratorAPI generator) {
else {
local_tmp = System.getProperty("user.dir") + "/src/main".replace("/", File.separator);
}

// TODO: Code is unreachable here
if(generator == GeneratorAPI.CUDA) {
// init GPUs with jCuda to avoid double initialization problems
GPUContextPool.initializeGPU();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
import org.apache.commons.cli.AlreadySelectedException;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.cli.ParseException;
import org.apache.sysds.hops.OptimizerUtils;
import org.apache.sysds.runtime.instructions.fed.FEDInstruction;
import org.apache.sysds.runtime.lineage.LineageCacheConfig;
import org.junit.Assert;
import org.junit.Test;
import org.apache.sysds.api.DMLOptions;
import org.apache.sysds.common.Types.ExecMode;
import org.apache.sysds.runtime.lineage.LineageCacheConfig.ReuseCacheType;
import org.apache.sysds.utils.Explain;

import static org.apache.sysds.api.DMLOptions.parseCLArguments;

@net.jcip.annotations.NotThreadSafe
public class CLIOptionsParserTest {

Expand Down Expand Up @@ -162,6 +167,7 @@ public void testLineageReuseP() throws Exception {
Assert.assertEquals(ReuseCacheType.REUSE_PARTIAL, o.linReuseType);
Assert.assertEquals(false, o.lineage_dedup);
}

@Test
public void testLineageReuseH() throws Exception {
String cl = "systemds -f test.dml -lineage reuse_hybrid";
Expand Down Expand Up @@ -450,4 +456,193 @@ public void testNVArgs4() throws Exception {
Map<String, String> m = o.argVals;
Assert.assertEquals("'def'", m.get("$abc"));
}

@Test
public void parseCLArgumentsLineageDAGHEIGHTTest() throws ParseException {
String[] args = new String[]{"-f", "test", "-lineage", "policy_dagheight"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.lineage && opts.linCachePolicy == LineageCacheConfig.LineageCachePolicy.DAGHEIGHT);
}

@Test
public void parseCLIArgumentsLineageEstimateTest() throws ParseException {
String[] args = new String[]{"-f", "test", "-lineage", "estimate"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.lineage && opts.lineage_estimate);
}

@Test
public void parseCLArgumentsGPUTest() throws ParseException {
String[] args = new String[]{"-f", "test", "-gpu",};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.gpu);
}

@Test
public void parseCLArgumentsInvalidExplainTest() throws ParseException {
String[] args = new String[]{"-f", "test","-explain","XYZ"};
try {
parseCLArguments(args);
} catch (ParseException e) {
assert e.getMessage().equals("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime, codegen, codegen_recompile]");
}
}

@Test
public void parseCLArgumentsExplainCodegenRecompileTest() throws ParseException {
String[] args = new String[]{"-f", "test","-explain","codegen_recompile"};
DMLOptions opts = parseCLArguments(args);
Assert.assertEquals(opts.explainType, Explain.ExplainType.CODEGEN_RECOMPILE);
}

@Test
public void parseCLArgumentsNGramsTest1() throws ParseException {
String[] args = new String[]{"-f", "test", "-ngrams",};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.statsNGrams);
}

@Test
public void parseCLArgumentsNGramsTest2() throws ParseException {
String[] args = new String[]{"-f", "test", "-ngrams","1"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.statsNGrams);
}

@Test
public void parseCLArgumentsNGramsTest3() throws ParseException {
String[] args = new String[]{"-f", "test", "-ngrams","1","1","FALSE"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.statsNGrams);
Assert.assertEquals(opts.statsNGramSizes[0], 1);
Assert.assertEquals(opts.statsTopKNGrams, 1);
Assert.assertFalse(opts.statsNGramsUseLineage);
}

@Test
public void parseCLArgumentsNGramsTest4() throws ParseException {
String[] args = new String[]{"-f", "test", "-ngrams","1,3","1"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.statsNGrams);
Assert.assertEquals(opts.statsNGramSizes[0], 1);
Assert.assertEquals(opts.statsNGramSizes[1], 3);
Assert.assertEquals(opts.statsTopKNGrams, 1);
Assert.assertTrue(opts.statsNGramsUseLineage);
}

@Test
public void parseCLArgumentsNGramsTest5() throws ParseException {
String[] args = new String[]{"-f", "test","-ngrams","1,2","b"};
try {
parseCLArguments(args);
} catch (ParseException e) {
assert e.getMessage().equals("Invalid argument specified for -ngrams option, must be a valid integer");
}
}

@Test
public void parseCLArgumentsFEDStatsTest1() throws ParseException {
String[] args = new String[]{"-f", "test", "-fedStats",};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.fedStats);
}

@Test
public void parseCLArgumentsFEDStatsTest2() throws ParseException {
String[] args = new String[]{"-f", "test", "-fedStats", "21"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.fedStats);
Assert.assertEquals(21, opts.fedStatsCount);
}

@Test
public void parseCLArgumentsFEDStatsTest3() {
String[] args = new String[]{"-f", "test", "-fedStats", "xyz"};
try {
parseCLArguments(args);
} catch (ParseException e) {
assert e.getMessage().equals("Invalid argument specified for -fedStats option, must be a valid integer");
}
}

@Test
public void parseCLArgumentsFEDMonitoringTest1() {
String[] args = new String[]{"-fedMonitoring"};
try {
parseCLArguments(args);
} catch (ParseException e) {
assert e.getMessage().equals("No port [integer] specified for -fedMonitoring option");
}
}

@Test
public void parseCLArgumentsFEDMonitoringTest2() {
String[] args = new String[]{"-fedMonitoring","21", "-fedMonitoringAddress"};
try {
parseCLArguments(args);
} catch (ParseException e) {
assert e.getMessage().equals("No address [String] specified for -fedMonitoringAddress option");
}
}

@Test
public void parseCLArgumentsFEDMonitoringTest3() throws ParseException {
String[] args = new String[]{"-fedMonitoring", "21"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.fedMonitoring);
Assert.assertEquals(21, opts.fedMonitoringPort);
}

@Test
public void parseCLArgumentsFEDMonitoringTest4() throws ParseException {
String[] args = new String[]{"-fedMonitoring", "21", "-fedMonitoringAddress", "xyz"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.fedMonitoring);
Assert.assertEquals(21, opts.fedMonitoringPort);
Assert.assertEquals("xyz", opts.fedMonitoringAddress);
}

@Test
public void parseCLArgumentsFEDCompilationTest1() throws ParseException {
String[] args = new String[]{"-f", "test", "-federatedCompilation"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.federatedCompilation);
}

@Test
public void parseCLArgumentsFEDCompilationTest2() throws ParseException {
String[] args = new String[]{"-f", "test", "-federatedCompilation", "1=NONE"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.federatedCompilation);
Assert.assertEquals(OptimizerUtils.FEDERATED_SPECS.get(1), FEDInstruction.FederatedOutput.NONE);
}

@Test
public void parseCLArgumentsFEDCompilationTest3() {
String[] args = new String[]{"-f","test", "-federatedCompilation","1=n=n"};
try {
parseCLArguments(args);
throw new AssertionError("Test should have resulted in Exception");
} catch (ParseException e){
Assert.assertEquals("Invalid argument specified for -federatedCompilation option, must be a list of space separated K=V pairs, where K is a line number of the DML script and V is a federated output value",e.getMessage());
}
}

@Test
public void parseCLArgumentsFEDNoRuntimeConversionTest() throws ParseException {
String[] args = new String[]{"-f", "test", "-noFedRuntimeConversion"};
DMLOptions opts = parseCLArguments(args);
Assert.assertTrue(opts.noFedRuntimeConversion);
}

@Test
public void testDMLOptionToString() throws ParseException {
String cl = "systemds -f test.dml -exec spark";
String[] args = cl.split(" ");
DMLOptions o = DMLOptions.parseCLArguments(args);
String oString = o.toString();
Assert.assertTrue(oString.contains("script='null'"));
Assert.assertTrue(oString.contains("filePath='test.dml'"));
Assert.assertTrue(oString.contains("execMode=SPARK"));
}
}
Loading
Loading