Ejemplo n.º 1
0
TEST_F(AnalysisDriverFixture,RuntimeBehavior_StopAndRestartDakotaAnalysis) {

  // RETRIEVE PROBLEM
  Problem problem = retrieveProblem("SimpleHistogramBinUQ",true,false);

  // DEFINE SEED
  Model model = model::exampleModel();
  openstudio::path p = toPath("./example.osm");
  model.save(p,true);
  FileReference seedModel(p);

  // CREATE ANALYSIS
  SamplingAlgorithmOptions algOptions;
  algOptions.setSamples(10);
  Analysis analysis("Stop and Restart Dakota Analysis",
                    problem,
                    SamplingAlgorithm(algOptions),
                    seedModel);

  // RUN ANALYSIS
  if (!dakotaExePath().empty()) {
    ProjectDatabase database = getCleanDatabase("StopAndRestartDakotaAnalysis");
    AnalysisDriver analysisDriver(database);
    AnalysisRunOptions runOptions = standardRunOptions(analysisDriver.database().path().parent_path());
    StopWatcher watcher(analysisDriver);
    watcher.watch(analysis.uuid());
    CurrentAnalysis currentAnalysis = analysisDriver.run(analysis,runOptions);
    analysisDriver.waitForFinished();
    EXPECT_FALSE(analysisDriver.isRunning());

    // check conditions afterward
    boost::optional<runmanager::JobErrors> jobErrors = currentAnalysis.dakotaJobErrors();
    ASSERT_TRUE(jobErrors);
    EXPECT_FALSE(jobErrors->errors().empty());
    EXPECT_FALSE(currentAnalysis.analysis().dataPoints().empty());
    EXPECT_FALSE(currentAnalysis.analysis().dataPointsToQueue().empty());
    EXPECT_FALSE(currentAnalysis.analysis().completeDataPoints().empty());
    EXPECT_FALSE(currentAnalysis.analysis().successfulDataPoints().empty());
    EXPECT_TRUE(currentAnalysis.analysis().failedDataPoints().empty());
    EXPECT_FALSE(currentAnalysis.analysis().algorithm()->isComplete());
    EXPECT_FALSE(currentAnalysis.analysis().algorithm()->failed());
    EXPECT_EQ(0u,analysisDriver.currentAnalyses().size());
    LOG(Debug,"After initial stop, there are " << currentAnalysis.analysis().dataPoints().size()
        << " data points, of which " << currentAnalysis.analysis().completeDataPoints().size()
        << " are complete.");

    // try to restart from database contents
    Analysis analysis = AnalysisRecord::getAnalysisRecords(database)[0].analysis();
    ASSERT_TRUE(analysis.algorithm());
    EXPECT_FALSE(analysis.algorithm()->isComplete());
    EXPECT_FALSE(analysis.algorithm()->failed());
    currentAnalysis = analysisDriver.run(analysis,runOptions);
    analysisDriver.waitForFinished();
    EXPECT_EQ(10u,analysis.dataPoints().size());
    EXPECT_EQ(0u,analysis.dataPointsToQueue().size());
    EXPECT_EQ(10u,analysis.completeDataPoints().size());
    EXPECT_EQ(10u,analysis.successfulDataPoints().size());
    EXPECT_EQ(0u,analysis.failedDataPoints().size());
  }
}
  std::string SamplingAlgorithm_Impl::dakotaInFileDescription() const {

    SamplingAlgorithmOptions options = samplingAlgorithmOptions();
    
    std::stringstream ss;
    ss << "method," << std::endl;
    ss << "        sampling" << std::endl;
    if (boost::optional<SamplingAlgorithmSampleType> sampleType = options.sampleType()) {
      ss << "          sample_type = " << (*sampleType).valueName() << std::endl;
    }
    if (options.allVariables()) {
      ss << "          all_variables" << std::endl;
    }
    if (OptionalInt seed = options.seed()) {
      ss << "          seed = " << *seed << std::endl;
    }
    if (options.fixedSeed()) {
      ss << "          fixed_seed" << std::endl;
    }
    if (boost::optional<SamplingAlgorithmRNGType> rngType = options.rngType()) {
      ss << "          rng = " << (*rngType).valueName() << std::endl;
    }
    if (options.varianceBasedDecomp()) {
      ss << "          variance_based_decomp" << std::endl;
    }
    if (options.dropTolerance()) {
      ss << "          drop_tolerance" << std::endl;
    }
    ss << "          samples = " << options.samples() << std::endl;
    ss << std::endl;

    return ss.str();
  }
TEST_F(AnalysisFixture, SamplingAlgorithmOptions) {

    //Testing SamplingAlgorithmOptions:
    SamplingAlgorithmOptions test1;

    SamplingAlgorithmRNGType obj0(SamplingAlgorithmRNGType::rnum2);
    SamplingAlgorithmSampleType obj1(SamplingAlgorithmSampleType::random);
    test1.setRNGType(obj0);
    test1.setSampleType(obj1);
    EXPECT_EQ(test1.rngType(),obj0);
    EXPECT_EQ(test1.sampleType(),obj1);
    test1.clearRNGType();
    test1.clearSampleType();
    EXPECT_FALSE(test1.rngType());
    EXPECT_FALSE(test1.sampleType());

    test1.setSamples(20);
    test1.setAllVariables(true);
    test1.setVarianceBasedDecomp(true);
    test1.setDropTolerance(true);
    test1.setSeed(5);
    test1.setFixedSeed(true);
    EXPECT_EQ(test1.samples(),20);
    EXPECT_TRUE(test1.varianceBasedDecomp());
    EXPECT_TRUE(test1.allVariables());
    EXPECT_TRUE(test1.dropTolerance());
    EXPECT_EQ(test1.seed(),5);
    EXPECT_TRUE(test1.fixedSeed());
    test1.clearSeed();
    EXPECT_FALSE(test1.seed());

    //Testing SamplingAlgorithm:

    SamplingAlgorithmOptions testOptions;


    testOptions.setAllVariables(true);
    testOptions.setSamples(4);
    testOptions.setSeed(3);
    testOptions.setFixedSeed(true);
    testOptions.setRNGType(SamplingAlgorithmRNGType::mt19937);
    testOptions.setSampleType(SamplingAlgorithmSampleType::lhs);
    testOptions.setVarianceBasedDecomp(true);
    testOptions.setDropTolerance(true);

    SamplingAlgorithm testSamplingOptions(testOptions);

    std::string testSamplingOptionsStrDakotaInDescription = testSamplingOptions.dakotaInFileDescription();
    LOG(Debug,"Printing the DakotaInFileDescription for the Sampling Options Test" << std::endl <<
        testSamplingOptionsStrDakotaInDescription );
}
Ejemplo n.º 4
0
TEST_F(AnalysisDriverFixture,RuntimeBehavior_StopDakotaAnalysis) {
  // Tests for stopping time < 20s.

  // RETRIEVE PROBLEM
  Problem problem = retrieveProblem("SimpleHistogramBinUQ",true,false);

  // DEFINE SEED
  Model model = model::exampleModel();
  openstudio::path p = toPath("./example.osm");
  model.save(p,true);
  FileReference seedModel(p);

  // CREATE ANALYSIS
  SamplingAlgorithmOptions algOptions;
  algOptions.setSamples(100);
  Analysis analysis("Stop Dakota Analysis",
                    problem,
                    SamplingAlgorithm(algOptions),
                    seedModel);

  // RUN ANALYSIS
  if (!dakotaExePath().empty()) {
    ProjectDatabase database = getCleanDatabase("StopDakotaAnalysis");
    AnalysisDriver analysisDriver(database);
    AnalysisRunOptions runOptions = standardRunOptions(analysisDriver.database().path().parent_path());
    StopWatcher watcher(analysisDriver);
    watcher.watch(analysis.uuid());
    CurrentAnalysis currentAnalysis = analysisDriver.run(analysis,runOptions);
    analysisDriver.waitForFinished();
    EXPECT_FALSE(analysisDriver.isRunning());
    EXPECT_GE(watcher.nComplete(),watcher.stopNum());
    EXPECT_LE(watcher.stoppingTime(),openstudio::Time(0,0,0,20));

    // check conditions afterward
    boost::optional<runmanager::JobErrors> jobErrors = currentAnalysis.dakotaJobErrors();
    ASSERT_TRUE(jobErrors);
    EXPECT_FALSE(jobErrors->errors().empty());
    EXPECT_FALSE(currentAnalysis.analysis().dataPoints().empty());
    EXPECT_FALSE(currentAnalysis.analysis().algorithm()->isComplete());
    EXPECT_FALSE(currentAnalysis.analysis().algorithm()->failed());
    EXPECT_EQ(0u,analysisDriver.currentAnalyses().size());
  }
}