public static DMLOptions parseCLArguments()

in src/main/java/org/apache/sysds/api/DMLOptions.java [130:354]


	public static DMLOptions parseCLArguments(String[] args)
		throws org.apache.commons.cli.ParseException
	{
		Options options = createCLIOptions();
		CommandLineParser clParser = new PosixParser();
		CommandLine line = clParser.parse(options, args);

		DMLOptions dmlOptions = new DMLOptions(options);
		dmlOptions.help = line.hasOption("help");
		if (line.hasOption("lineage")){
			dmlOptions.lineage = true;
			String lineageTypes[] = line.getOptionValues("lineage");
			if (lineageTypes != null) {
				for (String lineageType : lineageTypes) {
					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);
				}
			}
		}
		dmlOptions.debug = line.hasOption("debug");
		dmlOptions.gpu = line.hasOption("gpu");
		if (dmlOptions.gpu) {
			String force = line.getOptionValue("gpu");
			if (force != null) {
				if (force.equalsIgnoreCase("force")) {
					dmlOptions.forceGPU = true;
				} else {
					throw new org.apache.commons.cli.ParseException("Invalid argument specified for -gpu option");
				}
			}
		}
		if (line.hasOption("exec")){
			String execMode = line.getOptionValue("exec");
			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");
			if (explainType != null){
				if (explainType.equalsIgnoreCase("hops")) dmlOptions.explainType = ExplainType.HOPS;
				else if (explainType.equalsIgnoreCase("runtime")) dmlOptions.explainType = ExplainType.RUNTIME;
				else if (explainType.equalsIgnoreCase("recompile_hops")) dmlOptions.explainType = ExplainType.RECOMPILE_HOPS;
				else if (explainType.equalsIgnoreCase("recompile_runtime")) dmlOptions.explainType = ExplainType.RECOMPILE_RUNTIME;
				else if (explainType.equalsIgnoreCase("codegen")) dmlOptions.explainType = ExplainType.CODEGEN;
				else if (explainType.equalsIgnoreCase("codegen_recompile")) dmlOptions.explainType = ExplainType.CODEGEN_RECOMPILE;
				else throw new org.apache.commons.cli.ParseException("Invalid argument specified for -hops option, must be one of [hops, runtime, recompile_hops, recompile_runtime, codegen, codegen_recompile]");
			}
		}

		dmlOptions.stats = line.hasOption("stats");
		if (dmlOptions.stats){
			String statsCount = line.getOptionValue("stats");
			if (statsCount != null) {
				try {
					dmlOptions.statsCount = Integer.parseInt(statsCount);
				} catch (NumberFormatException e) {
					throw new org.apache.commons.cli.ParseException("Invalid argument specified for -stats option, must be a valid integer");
				}
			}
		}

		dmlOptions.statsNGrams = line.hasOption("ngrams");
		if (dmlOptions.statsNGrams){
			String[] nGramArgs = line.getOptionValues("ngrams");
			if (nGramArgs != null && nGramArgs.length >= 2) {
				try {
					String[] nGramSizeSplit = nGramArgs[0].split(",");
					dmlOptions.statsNGramSizes = new int[nGramSizeSplit.length];

					for (int i = 0; i < nGramSizeSplit.length; i++) {
						dmlOptions.statsNGramSizes[i] = Integer.parseInt(nGramSizeSplit[i]);
					}

					dmlOptions.statsTopKNGrams = Integer.parseInt(nGramArgs[1]);

					if (nGramArgs.length == 3) {
						dmlOptions.statsNGramsUseLineage = Boolean.parseBoolean(nGramArgs[2]);
					}
				} catch (NumberFormatException e) {
					throw new org.apache.commons.cli.ParseException("Invalid argument specified for -ngrams option, must be a valid integer");
				}
			}

			if (dmlOptions.statsNGramsUseLineage) {
				dmlOptions.lineage = true;
			}
		}

		dmlOptions.fedStats = line.hasOption("fedStats");
		if (dmlOptions.fedStats) {
			String fedStatsCount = line.getOptionValue("fedStats");
			if(fedStatsCount != null) {
				try {
					dmlOptions.fedStatsCount = Integer.parseInt(fedStatsCount);
				} catch (NumberFormatException e) {
					throw new org.apache.commons.cli.ParseException("Invalid argument specified for -fedStats option, must be a valid integer");
				}
			}
		}

		dmlOptions.memStats = line.hasOption("mem");

		dmlOptions.clean = line.hasOption("clean");
		
		if (line.hasOption("config")){
			dmlOptions.configFile = line.getOptionValue("config");
		}
		
		if (line.hasOption("w")){
			dmlOptions.fedWorker = true;
			dmlOptions.fedWorkerPort = Integer.parseInt(line.getOptionValue("w"));
		}

		if (line.hasOption("fedMonitoring")) {
			dmlOptions.fedMonitoring= true;
			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")){
			dmlOptions.filePath = line.getOptionValue("f");
		}

		if (line.hasOption("s")){
			dmlOptions.script = line.getOptionValue("s");
		}

		// Positional arguments map is created as ("$1", "a"), ("$2", 123), etc
		if (line.hasOption("args")){
			String[] argValues = line.getOptionValues("args");
			for (int k=0; k<argValues.length; k++){
				String str = argValues[k];
				if (!str.isEmpty()) {
					dmlOptions.argVals.put("$" + (k+1), str);
				}
			}
		}

		if (line.hasOption("python"))
			dmlOptions.pythonPort = Integer.parseInt(line.getOptionValue("python"));

		// Named arguments map is created as ("$K, 123), ("$X", "X.csv"), etc
		if (line.hasOption("nvargs")){
			String varNameRegex = "^[a-zA-Z]([a-zA-Z0-9_])*$";
			String[] nvargValues = line.getOptionValues("nvargs");
			for (String str : nvargValues){
				if (!str.isEmpty()){
					String[] kv = str.split("=");
					if (kv.length != 2){
						throw new org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs option, must be a list of space separated K=V pairs, where K is a valid name of a variable in the DML/PyDML program");
					}
					if (!kv[0].matches(varNameRegex)) {
						throw new org.apache.commons.cli.ParseException("Invalid argument specified for -nvargs option, " + kv[0] + " does not seem like a valid variable name in DML. Valid variable names in DML start with upper-case or lower-case letter, and contain only letters, digits, or underscores");
					}
					dmlOptions.argVals.put("$" + kv[0], kv[1]);
				}
			}
		}

		dmlOptions.checkPrivacy = line.hasOption("checkPrivacy");

		if (line.hasOption("federatedCompilation")){
			OptimizerUtils.FEDERATED_COMPILATION = true;
			dmlOptions.federatedCompilation = true;
			String[] fedCompSpecs = line.getOptionValues("federatedCompilation");
			if (fedCompSpecs != null){
				for ( String spec : fedCompSpecs ){
					String[] specPair = spec.split("=");
					if (specPair.length != 2){
						throw new org.apache.commons.cli.ParseException("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");
					}
					int dmlLineNum = Integer.parseInt(specPair[0]);
					FEDInstruction.FederatedOutput fedOutSpec = FEDInstruction.FederatedOutput.valueOf(specPair[1]);
					OptimizerUtils.FEDERATED_SPECS.put(dmlLineNum,fedOutSpec);
				}
			}
		}

		if ( line.hasOption("noFedRuntimeConversion") ){
			FEDInstructionUtils.noFedRuntimeConversion = true;
			dmlOptions.noFedRuntimeConversion = true;
		}

		if(line.hasOption("seed")){
			dmlOptions.seed = Integer.parseInt(line.getOptionValue("seed"));
		}

		return dmlOptions;
	}