public void Run() { var config = Application.ReadConfig("config.json"); var client = Application.CreateClient(config); var usingProxyClient = (client is ProxyCertClient); string plgLogin = usingProxyClient ? "" : (String.IsNullOrEmpty(config.plgrid_login) ? Application.ReadString("Enter PL-Grid login:"******"" : Application.ReadPassword("Enter PL-Grid UI password:"******"" : Application.ReadPassword("Enter PL-Grid Certificate password:"******"New simulation {0}", randomNum); var baseScenarioPath = "example_scenario"; Func <string, string> scenarioPath = p => string.Format("{0}{1}{2}", baseScenarioPath, Path.DirectorySeparatorChar, p); var simulationBinariesPath = scenarioPath("bin.zip"); var executorPath = scenarioPath("executor.py"); var scenarioParams = new Dictionary <string, object>() { }; var experimentParams = new Dictionary <string, object>() { { "experiment_name", String.Format("New experiment {0}", randomNum) }, { "experiment_description", "This is a dummy experiment" }, // {"doe", experimentDoe}, { "execution_time_constraint", 3600 } }; try { // TODO: below method with executor id instead of path overload // define input parameters specification var simulationParameters = new List <ExperimentInput.Parameter>() { new Parameter("parameter1", "Param 1") { ParametrizationType = ExperimentInput.ParametrizationType.RANGE, Type = ExperimentInput.Type.FLOAT, Min = 0, Max = 1000 }, new Parameter("parameter2", "Param 2") { ParametrizationType = ExperimentInput.ParametrizationType.RANGE, Type = ExperimentInput.Type.FLOAT, Min = -100, Max = 100 } }; // create new scenario based on parameters specification SimulationScenario scenario = client.RegisterSimulationScenario( simulationName, simulationBinariesPath, simulationParameters, executorPath, scenarioParams); Console.WriteLine("Got scenario with name: {0}, created at: {1}", scenario.Name, scenario.CreatedAt); List <ValuesMap> points; // define few point of parameter space points = new List <ValuesMap>() { new ValuesMap() { { "parameter1", 1.5 }, { "parameter2", 3 } }, new ValuesMap() { { "parameter1", 5.0 }, { "parameter2", 7.0 } }, new ValuesMap() { { "parameter1", 2.0 }, { "parameter2", 9.0 } }, new ValuesMap() { { "parameter1", 12.0 }, { "parameter2", 2.0 } } }; // define more point of parameter space for (int i = 0; i < 10; ++i) { points.Add(new ValuesMap() { { "parameter1", (float)Application.GetRandomNumber(1000) }, { "parameter2", (float)Application.GetRandomNumber(1000) } }); } // create new experiment based on scenario Experiment experiment = scenario.CreateExperimentWithPoints(points, experimentParams); Console.WriteLine("Got experiment with ID: {0}", experiment.Id); // will contain list of worker objects List <SimulationManager> jobs = new List <SimulationManager>(); // -- workers scheduling on PL-Grid -- // TODO: parametrize! // schedule directly on Zeus PBS (preferred for Zeus) if (usingProxyClient) { jobs.AddRange(experiment.ScheduleZeusJobs(1)); } else { jobs.AddRange(experiment.ScheduleZeusJobs(1, plgridLogin: plgLogin, plgridPassword: plgPass)); } // schedule on several PL-Grid Computing Engines using QosCosGrid: Nova and Reef clusters var ces = new List <string> { PLGridCE.NOVA, PLGridCE.REEF }; foreach (string ce in ces) { if (usingProxyClient) { jobs.AddRange(experiment.SchedulePlGridJobs(ce, 1)); } else { jobs.AddRange(experiment.SchedulePlGridJobs(ce, 1, plgridLogin: plgLogin, plgridPassword: plgPass, keyPassphrase: plgKeyPass)); } } foreach (var j in jobs) { Console.WriteLine("Scheduled: {0} {1}", j.Id, j.State); } // Let's stop last started SimulationManager SimulationManager lastSim = jobs.Last(); Console.WriteLine("Stopping Simulation Manager with ID: {0}", lastSim.Id); lastSim.Stop(); // and check current simulation managers state IList <SimulationManager> currentJobs = experiment.GetSimulationManagers(); Console.WriteLine("Current Simulation Managers:"); foreach (var j in jobs) { Console.WriteLine("{0} -> {1}", j.Id, j.State); } // -- workers scheduling on servers -- TODO // Blocking method // experiment.WaitForDone(); // using event to wait for experiment completion experiment.ExperimentCompleted += Application.ShowResults; experiment.NoResources += Application.HandleNoResources; experiment.WatchingIntervalSecs = 4; experiment.StartWatching(); // idle loop... remove if using WaitForDone! while (Application.ShouldWait) { Console.WriteLine("DEBUG: waiting..."); currentJobs = experiment.GetSimulationManagers(); Console.WriteLine("State of Simulation Managers: {0}", string.Join(", ", jobs.Select(i => i.State))); Thread.Sleep(1000); } } catch (RegisterSimulationScenarioException e) { Console.WriteLine("Registering simulation scenario failed: " + e); } catch (CreateScenarioException e) { Console.WriteLine("Creating experiment failed: " + e); } catch (InvalidResponseException e) { Console.WriteLine("Invalid response: {0};\n\n{1};\n\n{2}", e.Response.Content, e.Response.ErrorMessage, e.Response.ErrorException); } catch (ScalarmResourceException <SimulationScenario> e) { Console.WriteLine("Error getting Scalarm SimulationScenario resource: {0}", e.Resource.ErrorCode); } }
public static void Run() { var config = Application.ReadConfig("config.json"); var client = Application.CreateClient(config); if (!(client is ProxyCertClient)) { throw new ApplicationException("This test supports only proxy cert client"); } var randomNum = Application.GetRandomNumber(1000); var simulationName = "TestGetSimError_" + randomNum; var experimentName = "TestGetSimError_exp_" + randomNum; var simDir = "test_scenario_error_executor"; var executorPath = string.Format("{0}{1}{2}", simDir, Path.DirectorySeparatorChar, "executor.sh"); var binPath = string.Format("{0}{1}{2}", simDir, Path.DirectorySeparatorChar, "hello.zip"); var simulationParameters = new List <Scalarm.ExperimentInput.Parameter>() { new Scalarm.ExperimentInput.Parameter("a", "A") { ParametrizationType = Scalarm.ExperimentInput.ParametrizationType.RANGE, Type = Scalarm.ExperimentInput.Type.FLOAT, Min = 0.1f, Max = 10 }, }; SimulationScenario simScenario = client.RegisterSimulationScenario( simulationName, binPath, simulationParameters, executorPath); List <Scalarm.ValuesMap> points = new List <ValuesMap>(); Random rnd = new Random(); for (int i = 0; i < 1000; ++i) { points.Add(new ValuesMap { { "a", rnd.NextDouble() } }); } Dictionary <string, object> experimentParams = new Dictionary <string, object>() { { "experiment_name", experimentName }, { "execution_time_constraint", 5 } }; var experiment = simScenario.CreateExperimentWithPoints(points, experimentParams); experiment.ScheduleZeusJobs(1); try { experiment.WaitForDone(5 * 60 * 1000, 10); } catch (NoActiveSimulationManagersException) { IList <SimulationManager> workers = experiment.GetSimulationManagers(); if (workers.Count != 1) { throw new ApplicationException("Invalid workers count: " + workers.Count); } var sim = workers.First(); Console.WriteLine("Simulation Manager failed with error/log:"); Console.WriteLine(sim.Error); Console.WriteLine(sim.ErrorDetails); } }