public void ParseArgumentsPrintsInformationAboutUnknownOptions() { string[] args = new string[] { "--seedHostName=testHost", "--port=42", "--foo", "--bar", }; // Parse with unknwon options. ArgumentParserUtils.ParseArguments(this._parser, args); var writtenOutput = this._consoleOutput.ToString(); var reader = new StringReader(writtenOutput); Assert.Equal( "One or more arguments could not be interpreted:", reader.ReadLine()); Assert.Equal( "Could not resolve '--foo'.", reader.ReadLine()); Assert.Equal( "Could not resolve '--bar'.", reader.ReadLine()); Assert.Equal( "Try adding '--help' for more information.", reader.ReadLine()); }
/// <summary> /// Executes the worker. /// </summary> /// <param name="args"> /// Arguments like the master's hostname. /// See <see cref="WorkerArgumentParser" /> for more information. /// </param> public static void Run(string[] args) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); LoggingHelper.Configure($"consoleOutput_Worker_{ProcessUtils.GetCurrentProcessId()}.log"); Randomizer.Configure(); // Parse arguments. var argsParser = new WorkerArgumentParser(); if (!ArgumentParserUtils.ParseArguments(argsParser, args)) { return; } LoggingHelper.ChangeConsoleLoggingLevel(argsParser.VerbosityLevel); // Create an actor system for remote nodes to deploy onto. var akkaConfig = CustomizeAkkaConfiguration( argsParser.OwnHostName, argsParser.SeedHostName, argsParser.Port, argsParser.VerbosityLevel >= VerbosityLevel.Trace); var actorSystem = ActorSystem.Create(AkkaNames.ActorSystemName, akkaConfig); // Create an actor checking whether the cluster seed is still up. actorSystem.ActorOf(Props.Create(() => new SeedObserver())); // Do not stop execution before the actor system has been terminated. var cluster = Cluster.Get(actorSystem); actorSystem.WhenTerminated.Wait(); cluster.Leave(cluster.SelfAddress); }
public void ParseArgumentsReturnsTrueForValidOptionsWithoutHelpOption() { string[] args = new string[] { "--seedHostName=testHost", "--port=42", }; Assert.True(ArgumentParserUtils.ParseArguments(this._parser, args)); }
/// <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); } }
/// <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); }
public void ParseArgumentsReturnsFalseForUnknownOptions() { string[] args = new string[] { "--seedHostName=testHost", "--port=42", "--foo", "--bar", }; Assert.False(ArgumentParserUtils.ParseArguments(this._parser, args)); }
/// <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."); }
/// <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); }
/// <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 }
public void ParseArgumentsReturnsFalseIfHelpIsRequested() { var args = new string[] { "--help" }; Assert.False(ArgumentParserUtils.ParseArguments(this._parser, args)); }
public void ParseArgumentsReturnsFalseForMissingOptions() { Assert.False( ArgumentParserUtils.ParseArguments(this._parser, args: new string[0])); }
/// <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()); } }