/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">If 'master' is included as argument, a /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments. /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param> public static void Main(string[] args) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log"); // Parse arguments. var argsParser = new SapsRunnerConfigurationParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } var config = argsParser.ConfigurationBuilder.Build(); // Start master or worker depending on arguments. if (argsParser.IsMaster) { Dictionary <string, IAllele> bestParameters; switch (config.GenericParameterization) { case GenericParameterization.RandomForestAverageRank: bestParameters = GenericSapsEntryPoint < GenomePredictionRandomForest <AverageRankStrategy>, GenomePredictionForestModel <GenomePredictionTree>, AverageRankStrategy> .Run(argsParser.AdditionalArguments, config); break; case GenericParameterization.RandomForestReuseOldTrees: bestParameters = GenericSapsEntryPoint < GenomePredictionRandomForest <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config); break; case GenericParameterization.StandardRandomForest: case GenericParameterization.Default: default: bestParameters = GenericSapsEntryPoint < StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, config); break; } Program.LogBestParameters(bestParameters, config); } else { Worker.Run(args); } }
public void ParseArgumentsReturnsFalseForUnknownOptions() { string[] args = new string[] { "--seedHostName=testHost", "--port=42", "--foo", "--bar", }; Assert.False(ArgumentParserUtils.ParseArguments(this._parser, args)); }
/// <summary> /// Runs the master. /// </summary> /// <param name="args"> /// Arguments to configure the run, e.g. population size or port to use. /// </param> /// <param name="algorithmTunerBuilder"> /// A function creating a <see cref="AlgorithmTuner{TTargetAlgorithm, TInstance, TResult, TLearnerModel, TPredictorModel, TSamplingStrategy}"/> instance. /// </param> /// <returns> /// The <see cref="Dictionary{String, IAllele}"/>, containing the best configuration. /// </returns> public static Dictionary <string, IAllele> Run( string[] args, Func <AlgorithmTunerConfiguration, string, string, AlgorithmTuner <TTargetAlgorithm, TInstance, TResult, TLearnerModel, TPredictorModel, TSamplingStrategy> > algorithmTunerBuilder) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"consoleOutput_Master_{ProcessUtils.GetCurrentProcessId()}.log"); Randomizer.Configure(); var argsParser = new MasterArgumentParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return(null); } var configuration = CreateAlgorithmTunerConfiguration(argsParser); LoggingHelper.ChangeConsoleLoggingLevel(configuration.Verbosity); LoggingHelper.WriteLine(VerbosityLevel.Info, $"Configuration:{Environment.NewLine}{configuration}"); // Create status file directories. Directory.CreateDirectory(configuration.StatusFileDirectory); if (configuration.ZipOldStatusFiles) { Directory.CreateDirectory(configuration.ZippedStatusFileDirectory); } using var runner = algorithmTunerBuilder.Invoke( configuration, argsParser.PathToTrainingInstanceFolder, argsParser.PathToTestInstanceFolder); if (argsParser.StartFromExistingStatus) { runner.UseStatusDump(Path.Combine(configuration.StatusFileDirectory, AlgorithmTunerConfiguration.FileName)); } if (configuration.EnableDataRecording) { runner.PrepareDataRecordDirectory(argsParser.StartFromExistingStatus); } // Run algorithm tuner. var bestParameters = runner.Run(); LoggingHelper.WriteLine( VerbosityLevel.Info, $"Best Configuration:{Environment.NewLine}{string.Join(Environment.NewLine, bestParameters.Select(keyValuePair => $"{keyValuePair.Key}: {keyValuePair.Value}"))}"); runner.CompleteAndExportGenerationHistory(); return(bestParameters); }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">If 'master' is included as argument, a /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments. /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param> public static void Main(string[] args) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log"); // Parse arguments. var argsParser = new BbobRunnerConfigurationParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } var bbobConfig = argsParser.ConfigurationBuilder.Build(); if (argsParser.IsMaster) { switch (bbobConfig.GenericParameterization) { case GenericParameterization.RandomForestAverageRank: GenericBbobEntryPoint < GenomePredictionRandomForest <AverageRankStrategy>, GenomePredictionForestModel <GenomePredictionTree>, AverageRankStrategy> .Run(argsParser.AdditionalArguments, bbobConfig); break; case GenericParameterization.RandomForestReuseOldTrees: GenericBbobEntryPoint < GenomePredictionRandomForest <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, bbobConfig); break; case GenericParameterization.StandardRandomForest: case GenericParameterization.Default: default: GenericBbobEntryPoint < StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.AdditionalArguments, bbobConfig); break; } } else { Worker.Run(args); return; } }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">If 'master' is included as argument, a /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments. /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param> public static void Main(string[] args) { LoggingHelper.Configure("bbobParserLog.txt"); var configParser = new BbobRunnerConfigurationParser(); if (!ArgumentParserUtils.ParseArguments(configParser, args)) { return; } var bbobConfig = configParser.ConfigurationBuilder.Build(); if (bbobConfig.IsMaster) { switch (bbobConfig.GenericParameterization) { case GenericParameterization.RandomForestAverageRank: GenericBbobEntryPoint < GenomePredictionRandomForest <AverageRankStrategy>, GenomePredictionForestModel <GenomePredictionTree>, AverageRankStrategy> .Run(configParser.AdditionalArguments, bbobConfig); break; case GenericParameterization.RandomForestReuseOldTrees: GenericBbobEntryPoint < GenomePredictionRandomForest <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(configParser.AdditionalArguments, bbobConfig); break; case GenericParameterization.StandardRandomForest: case GenericParameterization.Default: default: GenericBbobEntryPoint < StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(configParser.AdditionalArguments, bbobConfig); break; } } else { Worker.Run(args); return; } }
public void ParseArgumentsPrintsHelpIfHelpIsRequested() { // Parse with help option. var args = new string[] { "--help" }; ArgumentParserUtils.ParseArguments(this._parser, args); // Check that information about options is written to console. var consoleText = this._consoleOutput.ToString(); Assert.True( consoleText.Contains("Information about usage will be printed."), "No information about --help parameter was given on --help."); }
public void TestArgumentParserUtils_TrySetPropertyValue_Single() { IDictionary <string, ArgumentData> data = ArgumentParserUtils.GetArgumentData <TestParams>(); TestParams testParams = new TestParams(); Assert.IsTrue(testParams.TrySetPropertyValue(data["s"].Property, "value")); Assert.AreEqual("value", testParams.String); Assert.IsTrue(testParams.TrySetPropertyValue(data["iv"].Property, "7")); Assert.AreEqual(7, testParams.Count); Assert.IsTrue(testParams.TrySetPropertyValue(data["ev"].Property, "First")); Assert.AreEqual(TestOrdinal.First, testParams.OrdinalVal); Assert.IsTrue(testParams.TrySetPropertyValue(data["f"].Property, "true")); Assert.AreEqual(true, testParams.IsFree); }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">If 'master' is included as argument, a /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the remaining arguments. /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param> public static void Main(string[] args) { LoggingHelper.Configure($"lingelingParserLog.txt"); // Parse arguments. var argsParser = new LingelingRunnerConfigurationParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } var config = argsParser.ConfigurationBuilder.Build(); // Start master or worker depending on arguments. if (config.IsMaster) { var bestParameters = config.GenericParameterization switch { GenericParameterization.RandomForestAverageRank => GenericLingelingEntryPoint < GenomePredictionRandomForest <AverageRankStrategy>, GenomePredictionForestModel <GenomePredictionTree>, AverageRankStrategy> .Run(argsParser.RemainingArguments, config), GenericParameterization.RandomForestReuseOldTrees => GenericLingelingEntryPoint < GenomePredictionRandomForest <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config), GenericParameterization.StandardRandomForest => GenericLingelingEntryPoint < StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config), GenericParameterization.Default => GenericLingelingEntryPoint < StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config), _ => GenericLingelingEntryPoint <StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run(argsParser.RemainingArguments, config) }; Program.LogBestParameters(bestParameters, config); } else { Worker.Run(args); } }
public void ParseArgumentsPrintsInformationAboutMissingOptions() { // Parse with missing options. ArgumentParserUtils.ParseArguments(this._parser, args: new string[0]); // Check that information about it is written to console. var reader = new StringReader(this._consoleOutput.ToString()); var line = reader.ReadLine(); Assert.Equal( "Invalid options: ", line); line = reader.ReadLine(); Assert.Equal( "Seed host name must be provided. Where is the master located?", line); line = reader.ReadLine(); Assert.Equal( "Try adding '--help' for more information.", line); }
public void TestArgumentParserUtils_TrySetPropertyValue_Array() { IDictionary <string, ArgumentData> data = ArgumentParserUtils.GetArgumentData <TestParams>(); TestParams testParams = new TestParams(); // string array Assert.IsTrue(testParams.TrySetPropertyValue(data["a"].Property, new[] { "value1", "value2" })); Assert.AreEqual(2, testParams.Array.Count()); Assert.IsTrue(testParams.Array.Contains("value1")); Assert.IsTrue(testParams.Array.Contains("value2")); // int array Assert.IsTrue(testParams.TrySetPropertyValue(data["ia"].Property, new[] { "2", "3" })); Assert.AreEqual(2, testParams.Array.Count()); Assert.IsTrue(testParams.IntArray.Contains(2)); Assert.IsTrue(testParams.IntArray.Contains(2)); // Enum array Assert.IsTrue(testParams.TrySetPropertyValue(data["ea"].Property, new[] { "First", "Second" })); Assert.AreEqual(2, testParams.Array.Count()); Assert.IsTrue(testParams.EnumArray.Contains(TestOrdinal.First)); Assert.IsTrue(testParams.EnumArray.Contains(TestOrdinal.Second)); }
public void TestArgumentParserUtils_TrySetPropertyValue_Invalid() { IDictionary <string, ArgumentData> data = ArgumentParserUtils.GetArgumentData <TestParams>(); TestParams testParams = new TestParams(); Assert.IsFalse(testParams.TrySetPropertyValue(data["iv"].Property, "NaN")); Assert.IsFalse(testParams.TrySetPropertyValue(data["ev"].Property, "Sec")); Assert.IsFalse(testParams.TrySetPropertyValue(data["df"].Property, "NotTrue")); Assert.IsFalse(testParams.TrySetPropertyValue(data["ia"].Property, new[] { "NaN", "1" })); Assert.IsFalse(testParams.TrySetPropertyValue(data["ea"].Property, new[] { "First", "Sec" })); // Ensure error messages are displayed IList <string> errorLog = Logger.ErrorLog; Assert.AreEqual(5, errorLog.Count); Assert.AreEqual("Error: Given value 'NaN' should be of type 'Int32'", errorLog[0]); Assert.AreEqual("Error: Unknown value 'Sec' given. Valid values - [First, Second, Third]", errorLog[1]); Assert.AreEqual("Error: Given value 'NotTrue' should be of type 'Boolean'", errorLog[2]); Assert.AreEqual("Error: Given values 'NaN, 1' should be a list of type 'Int32'", errorLog[3]); Assert.AreEqual("Error: Given list 'First, Sec' contains an unknown value. Valid values - [First, Second, Third]", errorLog[4]); }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">Program arguments. Call the program with --help for more information.</param> public static void Main(string[] args) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log"); // Parse arguments. var argsParser = new ArgumentParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } // Start master or worker depending on arguments. if (argsParser.IsMaster) { Program.RunMaster(argsParser); } else { Worker.Run(argsParser.AdditionalArguments.ToArray()); } }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">Program arguments. Call the program with --help for more information.</param> public static void Main(string[] args) { // Parse arguments. var argsParser = new ArgumentParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } // Start master or worker depending on arguments. if (argsParser.MasterRequested) { Program.RunMaster(argsParser); } else { Worker.Run(argsParser.AdditionalArguments.ToArray()); } #if DEBUG Console.WriteLine("Press any key to exit..."); Console.ReadLine(); #endif }
/// <summary> /// Entry point to the program. /// </summary> /// <param name="args">If 'master' is included as argument, a /// <see cref="Master{TTargetAlgorithm,TInstance,TResult}"/> is starting using the provided arguments. /// Otherwise, a <see cref="Worker"/> is started with the provided arguments.</param> public static void Main(string[] args) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"parserLog_{ProcessUtils.GetCurrentProcessId()}.log"); // Parse gurobi configuration. var gurobiParser = new GurobiRunnerConfigurationParser(); if (!ArgumentParserUtils.ParseArguments(gurobiParser, args)) { return; } if (gurobiParser.IsPostTuningRunner) { LoggingHelper.Configure($"consoleOutput_PostTuningRun_{ProcessUtils.GetCurrentProcessId()}.log"); // Parse and build tuner configuration. var masterArgumentParser = new MasterArgumentParser(); if (!ArgumentParserUtils.ParseArguments(masterArgumentParser, gurobiParser.AdditionalArguments.ToArray())) { return; } var tunerConfig = masterArgumentParser.ConfigurationBuilder.Build(); LoggingHelper.ChangeConsoleLoggingLevel(tunerConfig.Verbosity); // Build gurobi configuration. var gurobiConfig = Program.BuildGurobiConfigAndCheckThreadCount(gurobiParser.ConfigurationBuilder, tunerConfig); var gurobiRunnerFactory = new GurobiRunnerFactory(gurobiConfig, tunerConfig); var parameterTree = GurobiUtils.CreateParameterTree(); // Start post tuning runner. var parallelPostTuningRunner = new ParallelPostTuningRunner <GurobiRunner, InstanceSeedFile, GurobiResult>( tunerConfig, gurobiParser.PostTuningConfiguration, gurobiRunnerFactory, parameterTree); parallelPostTuningRunner.ExecutePostTuningRunsInParallel(); return; } if (gurobiParser.IsMaster) { Master <GurobiRunner, InstanceSeedFile, GurobiResult, StandardRandomForestLearner <ReuseOldTreesStrategy>, GenomePredictionForestModel <GenomePredictionTree>, ReuseOldTreesStrategy> .Run( args : gurobiParser.AdditionalArguments.ToArray(), algorithmTunerBuilder : (algorithmTunerConfig, pathToInstanceFolder, pathToTestInstanceFolder) => Program.BuildGurobiRunner( algorithmTunerConfig, pathToInstanceFolder, pathToTestInstanceFolder, gurobiParser.ConfigurationBuilder)); } else { Worker.Run(gurobiParser.AdditionalArguments.ToArray()); } }
public void ParseArgumentsReturnsFalseIfHelpIsRequested() { var args = new string[] { "--help" }; Assert.False(ArgumentParserUtils.ParseArguments(this._parser, args)); }
public void TestArgumentParserUtils_ParseParam() { // Non params Tuple <string, string> param = ArgumentParserUtils.ParseParam("a"); Assert.IsNull(param); // Flags param = ArgumentParserUtils.ParseParam("/b"); Assert.IsNotNull(param); Assert.AreEqual("b", param.Item1); Assert.IsTrue(string.IsNullOrWhiteSpace(param.Item2)); param = ArgumentParserUtils.ParseParam("-c"); Assert.IsNotNull(param); Assert.AreEqual("c", param.Item1); Assert.IsTrue(string.IsNullOrWhiteSpace(param.Item2)); // Assignments param = ArgumentParserUtils.ParseParam("-d:dval"); Assert.IsNotNull(param); Assert.AreEqual("d", param.Item1); Assert.AreEqual("dval", param.Item2); param = ArgumentParserUtils.ParseParam("/e=eval"); Assert.IsNotNull(param); Assert.AreEqual("e", param.Item1); Assert.AreEqual("eval", param.Item2); // Long keys param = ArgumentParserUtils.ParseParam("--f-gh"); Assert.IsNotNull(param); Assert.AreEqual("f-gh", param.Item1); Assert.IsTrue(string.IsNullOrWhiteSpace(param.Item2)); param = ArgumentParserUtils.ParseParam("--i-jk=kval"); Assert.IsNotNull(param); Assert.AreEqual("i-jk", param.Item1); Assert.AreEqual("kval", param.Item2); param = ArgumentParserUtils.ParseParam("--l-mn=mval-with-hyphen"); Assert.IsNotNull(param); Assert.AreEqual("l-mn", param.Item1); Assert.AreEqual("mval-with-hyphen", param.Item2); param = ArgumentParserUtils.ParseParam("/o:oval-with-hyphen"); Assert.IsNotNull(param); Assert.AreEqual("o", param.Item1); Assert.AreEqual("oval-with-hyphen", param.Item2); // Paths or spaces param = ArgumentParserUtils.ParseParam(@"/path:Z:\Dir\File.Ext"); Assert.IsNotNull(param); Assert.AreEqual("path", param.Item1); Assert.AreEqual(@"Z:\Dir\File.Ext", param.Item2); param = ArgumentParserUtils.ParseParam("-q=arg with space"); Assert.IsNotNull(param); Assert.AreEqual("q", param.Item1); Assert.AreEqual("arg with space", param.Item2); }
public void ParseArgumentsReturnsFalseForMissingOptions() { Assert.False( ArgumentParserUtils.ParseArguments(this._parser, args: new string[0])); }