/// <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); }
/// <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 TestChangeConsoleLoggingLevelToWarn() { TestUtils.CheckOutput( action: () => { LoggingHelper.ChangeConsoleLoggingLevel(VerbosityLevel.Warn); LoggingHelperTest.WriteLinesForAllLogLevels(); }, check: consoleOutput => { using (var reader = new StringReader(consoleOutput.ToString())) { var output = reader.ReadToEnd(); this.CheckLinesForAllLogLevels(output, new List <LogLevel> { LogLevel.Warn }); } }); }
public void TestChangeConsoleLoggingLevelToTrace() { TestUtils.CheckOutput( action: () => { LoggingHelper.ChangeConsoleLoggingLevel(VerbosityLevel.Trace); LoggingHelperTest.WriteLinesForAllLogLevels(); }, check: consoleOutput => { using (var reader = new StringReader(consoleOutput.ToString())) { this.CheckLinesForAllLogLevels( reader.ReadToEnd(), new List <LogLevel> { LogLevel.Warn, LogLevel.Info, LogLevel.Debug, LogLevel.Trace }); } }); }
/// <summary> /// Initializes a new instance of the <see cref="GrayBoxSimulation{TTargetAlgorithm, TInstance, TResult}" /> class. /// </summary> /// <param name="configuration">The <see cref="AlgorithmTunerConfiguration"/>.</param> /// <param name="targetAlgorithmFactory">The <see cref="ITargetAlgorithmFactory{TTargetAlgorithm, TInstance, TResult}"/>.</param> /// <param name="customGrayBoxMethods">The <see cref="ICustomGrayBoxMethods{TResult}"/>.</param> /// <param name="runEvaluator">The <see cref="IRunEvaluator{TInstance, TResult}"/>.</param> /// <param name="parameterTree">The <see cref="ParameterTree"/>.</param> public GrayBoxSimulation( AlgorithmTunerConfiguration configuration, ITargetAlgorithmFactory <TTargetAlgorithm, TInstance, TResult> targetAlgorithmFactory, ICustomGrayBoxMethods <TResult> customGrayBoxMethods, IRunEvaluator <TInstance, TResult> runEvaluator, ParameterTree parameterTree) { ProcessUtils.SetDefaultCultureInfo(CultureInfo.InvariantCulture); this._configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); this._customGrayBoxMethods = customGrayBoxMethods ?? throw new ArgumentNullException(nameof(customGrayBoxMethods)); this._runEvaluator = runEvaluator ?? throw new ArgumentNullException(nameof(runEvaluator)); this._targetAlgorithmFactory = targetAlgorithmFactory ?? throw new ArgumentNullException(nameof(targetAlgorithmFactory)); this._parameterTree = parameterTree ?? throw new ArgumentNullException(nameof(parameterTree)); this._logFileDirectory = new DirectoryInfo(Path.Combine(this._configuration.DataRecordDirectoryPath, "GrayBoxSimulationLogFiles")); Directory.CreateDirectory(this._logFileDirectory.FullName); LoggingHelper.Configure( Path.Combine(this._logFileDirectory.FullName, $"consoleOutput_GrayBoxSimulation_{ProcessUtils.GetCurrentProcessId()}.log")); LoggingHelper.ChangeConsoleLoggingLevel(configuration.Verbosity); LoggingHelper.WriteLine(VerbosityLevel.Info, "Reading in and preprocessing data for gray box simulation."); if (!GrayBoxUtils.TryToReadDataRecordsFromDirectory( targetAlgorithmFactory, configuration.DataRecordDirectoryPath, 0, configuration.Generations - 1, out this._allDataRecords)) { throw new ArgumentException($"Cannot read data records from {configuration.DataRecordDirectoryPath}!"); } this.ReadGenerationCompositionFiles(); this.CreatePredictionDictionaryAndDataDictionary(); }
/// <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()); } }