def testVarGenFuncs(iterGen): valuesIter = msuite.getParamValuesIter(varDict, iterGen) print "Value tuples:\n%s" % list(valuesIter) indicesIter = msuite.getVariantIndicesIter(varDict, iterGen) print "Indices into vars list:\n%s" % list(indicesIter) indicesIter = msuite.getVariantIndicesIter(varDict, iterGen) varNameDicts = msuite.getVariantNameDicts(varDict, indicesIter) print "Dictionary of var names:values :\n%s" % varNameDicts indicesIter = msuite.getVariantIndicesIter(varDict, iterGen) varPathDicts = msuite.getVariantParamPathDicts(varDict, indicesIter) print "Dictionary of var paths:values :\n%s" % varPathDicts indicesIter = msuite.getVariantIndicesIter(varDict, iterGen) subPaths = msuite.getTextParamValsSubdirs(varDict, indicesIter) print "Sub-paths (textual):\n%s" % subPaths indicesIter = msuite.getVariantIndicesIter(varDict, iterGen) cmdLineOvers = msuite.getVariantCmdLineOverrides(varDict, indicesIter) print "Cmd-line strings:\n%s" % cmdLineOvers print "subDirs, strs:" subDirsAndCmdLines = zip(subPaths, cmdLineOvers) for subDir, cmdLineStr in subDirsAndCmdLines: print " %s: '%s'" % (subDir, cmdLineStr) print "Indexes and results of a certain parameter" gravRunIs = msuite.getVarRunIs('gravity', varDict, varNameDicts) print "Run Indices of variant 'gravity':\n%s" % gravRunIs surfValsMap = msuite.getOtherParamValsByVarRunIs(gravRunIs, varNameDicts, 'surfShape') print "Run Indices of variant 'surfShape' sorted by 'gravity':\n%s" \ % (surfValsMap)
def test_getVariantParamPathDicts(self): indicesIt = msuite.getVariantIndicesIter(self.varDict, itertools.izip) varDicts = msuite.getVariantParamPathDicts(self.varDict, indicesIt) self.assertEqual(len(varDicts), min(list(map(len, [self.yRange, self.zRange])))) for ii, varDict in enumerate(varDicts): self.assertEqual(varDict['minY'], self.yRange[ii]) self.assertEqual(varDict['maxZ'], self.zRange[ii]) indicesIt = msuite.getVariantIndicesIter(self.varDict, msuite.product) varDicts = msuite.getVariantParamPathDicts(self.varDict, indicesIt) self.assertEqual(len(varDicts), (len(self.yRange) * len(self.zRange))) # Loop through and check the product has worked. for ii in range(len(self.yRange)): for jj in range(len(self.zRange)): entryI = ii * len(self.zRange) + jj varDict = varDicts[entryI] self.assertEqual(varDict['minY'], self.yRange[ii]) self.assertEqual(varDict['maxZ'], self.zRange[jj])
def test_getVariantParamPathDicts(self): indicesIt = msuite.getVariantIndicesIter(self.varDict, itertools.izip) varDicts = msuite.getVariantParamPathDicts(self.varDict, indicesIt) self.assertEqual(len(varDicts), min( map(len, [self.yRange, self.zRange]))) for ii, varDict in enumerate(varDicts): self.assertEqual(varDict['minY'], self.yRange[ii]) self.assertEqual(varDict['maxZ'], self.zRange[ii]) indicesIt = msuite.getVariantIndicesIter(self.varDict, msuite.product) varDicts = msuite.getVariantParamPathDicts(self.varDict, indicesIt) self.assertEqual(len(varDicts), (len(self.yRange) * len(self.zRange))) # Loop through and check the product has worked. for ii in range(len(self.yRange)): for jj in range(len(self.zRange)): entryI = ii * len(self.zRange) + jj varDict = varDicts[entryI] self.assertEqual(varDict['minY'], self.yRange[ii]) self.assertEqual(varDict['maxZ'], self.zRange[jj])
def modelImagesDisplay(mSuite, rGen, level, imgPerRow=1): imageInfos = mSuite.modelImagesToDisplay elements = [] if mSuite.iterGen is not None: inIter = msuite.getVariantIndicesIter(mSuite.modelVariants, mSuite.iterGen) varNameDicts = msuite.getVariantNameDicts(mSuite.modelVariants, inIter) for runI, imagesPerRun in enumerate(imageInfos): #Allow runs with no images (may not be interesting). if len(imagesPerRun) == 0: continue mRun = mSuite.runs[runI] elements.append( rGen.getHeaderEl("Run %d: %s" % (runI, mSuite.runs[runI].name), level)) # TODO: optional info to provide with each run. #if mSuite.iterGen is not None: # elements.append(rGen.getHeaderEl("%s" % varNameDicts[runI], # style=ParaStyle)) # Put the images in a table nRows = int(math.ceil(len(imagesPerRun) / float(imgPerRow))) data = [[] for rowI in range(nRows)] rowI = 0 for ii, imgInfo in enumerate(imagesPerRun): hdrText = "Timestep %d:" % (imgInfo[0]) if imgInfo[1] != "": hdrText += " (%s)" % imgInfo[1] imgFName = os.path.join(mRun.basePath, mRun.outputPath, 'window.%.5d.png' % imgInfo[0]) # Set possible thumbnail size - can reduce file size if many # images are being used. tScale = 1 / float(imgPerRow) * 100 # Set display size on page img = PIL.Image.open(imgFName) initWidth, initHeight = img.size ratio = initHeight / float(initWidth) newWidth = int( math.floor((rGen.PAGE_WIDTH * .9) / float(imgPerRow))) newHeight = int(math.floor(newWidth * ratio)) data[rowI].append( rGen.getImageEls(imgFName, width=newWidth, height=newHeight, tScale=tScale, hdrText=hdrText)) if (ii + 1) % imgPerRow == 0: rowI += 1 table = rGen.getTableEl(data) elements.append(table) result = elements return result
def modelImagesDisplay(mSuite, rGen, level, imgPerRow=1): imageInfos = mSuite.modelImagesToDisplay elements = [] if mSuite.iterGen is not None: inIter = msuite.getVariantIndicesIter(mSuite.modelVariants, mSuite.iterGen) varNameDicts = msuite.getVariantNameDicts(mSuite.modelVariants, inIter) for runI, imagesPerRun in enumerate(imageInfos): #Allow runs with no images (may not be interesting). if len(imagesPerRun) == 0: continue mRun = mSuite.runs[runI] elements.append(rGen.getHeaderEl("Run %d: %s" % (runI, mSuite.runs[runI].name), level)) # TODO: optional info to provide with each run. #if mSuite.iterGen is not None: # elements.append(rGen.getHeaderEl("%s" % varNameDicts[runI], # style=ParaStyle)) # Put the images in a table nRows = int(math.ceil(len(imagesPerRun)/float(imgPerRow))) data = [[] for rowI in range(nRows)] rowI = 0 for ii, imgInfo in enumerate(imagesPerRun): hdrText = "Timestep %d:" % (imgInfo[0]) if imgInfo[1] != "": hdrText += " (%s)" % imgInfo[1] imgFName = os.path.join(mRun.basePath, mRun.outputPath, 'window.%.5d.png' % imgInfo[0]) # Set possible thumbnail size - can reduce file size if many # images are being used. tScale = 1/float(imgPerRow) * 100 # Set display size on page img = PIL.Image.open(imgFName) initWidth, initHeight = img.size ratio = initHeight / float(initWidth) newWidth = int(math.floor((rGen.PAGE_WIDTH*.9) / float(imgPerRow))) newHeight = int(math.floor(newWidth * ratio)) data[rowI].append(rGen.getImageEls(imgFName, width=newWidth, height=newHeight, tScale=tScale, hdrText=hdrText)) if (ii+1) % imgPerRow == 0: rowI += 1 table = rGen.getTableEl(data) elements.append(table) result = elements return result
def reportResults(mSuite, mResults): indicesIter = msuite.getVariantIndicesIter(mSuite.modelVariants, mSuite.iterGen) varNameDicts = msuite.getVariantNameDicts(mSuite.modelVariants, indicesIter) for resI, mRes in enumerate(mResults): print "Post-process result %d: with" % resI, print ", ".join(["%s=%g" % item for item in varNameDicts[resI].iteritems()]) mRes.readFrequentOutput() mRes.freqOutput.plotOverTime('Vrms', depName='Time', path=mRes.outputPath) maxVal, maxTimeStep = mRes.freqOutput.getMax('Vrms') maxTime = mRes.freqOutput.getValueAtStep('Time', maxTimeStep) print "\tMaximum value of Vrms was %f, at time %.2f" % (maxVal, maxTime) modelplots.plotOverAllRuns(mResults, 'Vrms', depName='Time', path=mSuite.outputPathBase) mSuite.analysisImages = [ 'Vrms-multiRunTimeSeries.png'] mSuite.modelImagesToDisplay = [[] for runI in range(len(mSuite.runs))] for runI, mRun in enumerate(mSuite.runs): mRes = mResults[runI] fStep = mRes.freqOutput.finalStep() fTime = mRes.freqOutput.getValueAtStep('Time', fStep) dEvery = mRun.simParams.dumpevery lastImgStep = fStep / dEvery * dEvery vrmsMax, vrmsPeakStep = mRes.freqOutput.getMax('Vrms') vrmsMaxTime = mRes.freqOutput.getValueAtStep('Time', vrmsPeakStep) vrmsPeakImgStep = mRun.simParams.nearestDumpStep(fStep, vrmsPeakStep) vrmsPeakImgTime = mRes.freqOutput.getValueAtStep('Time', vrmsPeakImgStep) mSuite.modelImagesToDisplay[runI] = [ (0, "initial"), (vrmsPeakImgStep, "t=%f, near VRMS peak %g (at t=%g)" %\ (vrmsPeakImgTime, vrmsMax, vrmsMaxTime)), (mRun.simParams.nearestDumpStep(fStep, fStep*.5), "1/2"), (mRun.simParams.nearestDumpStep(fStep, fStep*.75), "3/4"), (lastImgStep, "final state (t=%f)" % fTime)] for rGen in getGenerators(["RST", "ReportLab"], mSuite.outputPathBase): sReps.makeSuiteReport(mSuite, mResults, rGen, os.path.join(mSuite.outputPathBase, "%s-report.%s" %\ ("RayTaySuite-examples", rGen.stdExt)), imgPerRow=3)
def getStatus(self, resultsSet): """After a suite of runs created by :meth:".genSuite" has been run, when this method is passed the results of the suite (as a list of :class:`credo.modelresult.ModelResult`), it must decide and return the status of the test (as a :class:`.SysTestResult`). It also needs to save this status to :attr:`.testStatus`. By default, this simply gets each :class:`~.TestComponent` registered for the system test do check its status, all must pass for a total pass. .. note:: if using this default method, then sub-classes need to have defined `failMsg` and `passMsg` attributes to use. """ # If using this defaul if not (hasattr(self, 'passMsg') and hasattr(self, 'failMsg')): raise AttributeError("Please define 'passMsg' and 'failMsg'"\ " attributes of your SysTest class to use the defualt"\ " getStatus method.") if len(resultsSet) != len(self.testComps): raise ValueError("Model results passed in to getStatus must"\ " be same length array as number of testComponents specified"\ " (lens are %d and %d, respectively)" %\ (len(resultsSet), len(self.testComps))) self.checkModelResultsValid(resultsSet) runPassed = [None for res in resultsSet] self.tcResults = [{} for res in resultsSet] #TODO: cleanup in future when iterator/generator interface improved if self.mSuite.iterGen is not None: inIter = msuite.getVariantIndicesIter(self.mSuite.modelVariants, self.mSuite.iterGen) varDicts = msuite.getVariantNameDicts(self.mSuite.modelVariants, inIter) for runI, modelResult in enumerate(resultsSet): if len(self.testComps[runI]) > 0: print("Testing single-run T.C.s for model result %d" % (runI)) if self.mSuite.iterGen is not None: print("(var-generated, with variants applied of:\n%s)"\ % varDicts[runI]) for tcName, tComp in list(self.testComps[runI].items()): tcResult = tComp.check(modelResult) self.tcResults[runI][tcName] = tcResult runPassed[runI] = all(self.tcResults[runI].values()) if len(self.testComps[runI]) > 0: if runPassed[runI]: print("All single run test components for"\ " run %d passed." % runI) else: #Do not break - we want to do all checks for sys tests print("at least one single run test component for"\ " run %d failed." % runI) self.allsrPassed = all(runPassed) #Now do the Multi-run test components if len(self.multiRunTestComps) > 0: print("Testing multi-run test components:") self.mrtcResults = {} for tcName, mrtComp in list(self.multiRunTestComps.items()): tcResult = mrtComp.check(resultsSet) self.mrtcResults[tcName] = tcResult self.allmrPassed = all(self.mrtcResults.values()) if len(self.multiRunTestComps) > 0: if self.allmrPassed: print("All multi-run test components passed.") else: print("at least one multi-run test component failed.") if self.allsrPassed and self.allmrPassed: self.testStatus = CREDO_PASS(self.passMsg) else: self.testStatus = CREDO_FAIL(self.failMsg) return self.testStatus
def customReporting(sciBTest, mResults): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt stress = {} recDeviatoricStress = {} recDeviatoricStressTCs = {} recDeviatoricStressRes = {} stressTCs = {} stressRes = {} for fComp in ["XX", "XY", "YY"]: recDeviatoricStressTCs[fComp], recDeviatoricStressRes[fComp] = sciBTest.getTCRes(\ "recoveredDeviatoricStress-%s" % fComp) stressTCs[fComp], stressRes[fComp] = sciBTest.getTCRes(\ "Stress-%s" % fComp) recDeviatoricStress[fComp] = [tc.actualVal for tc in recDeviatoricStressTCs[fComp]] stress[fComp] = [tc.actualVal for tc in stressTCs[fComp]] inIter = msuite.getVariantIndicesIter(sciBTest.mSuite.modelVariants, iterStrategy) varDicts = msuite.getVariantNameDicts(sciBTest.mSuite.modelVariants, inIter) for resI, mRes in enumerate(mResults): print "Post-process result %d" % (resI), print "with variants applied of:" print varDicts[resI] print "Value of recDeviatoricStress(%s) is (%s)\n stress(%s) is (%s)." %\ (", ".join(fCompMap), ", ".join(["%g" % recDeviatoricStress[c][resI] for c in fCompMap]), ", ".join(fCompMap), ", ".join(["%g" % stress[c][resI] for c in fCompMap])) # TO DO: #plotDeviatoricStressVsAnalytic(maxStressXX, maxStressYY, maxStressXY, # minStressXX, minStressYY, minStressXY, # {"DeviatoricStress_XX":recDeviatoricStress['XX']}, {"DeviatoricStress_YY":recDeviatoricStress['YY']}, # {"DeviatoricStress_XY":recDeviatoricStress['XY']}, # {"Stress_XX":stressXX}, {"Stress_YY":stressYY}, {"Stress_XY":stressXY}) #plt.savefig(os.path.join(mSuite.outputPathBase, # "RecoveredDeviatoricStressAndStressValues.png"), # dpi=None, facecolor='w', edgecolor='w', # orientation='portrait', papertype=None, format=None, # transparent=False) # Save to a CSV file. observables = {'recovered DeviatoricStress XX': recDeviatoricStress['XX'], 'recovered DeviatoricStress XX Passed': recDeviatoricStressRes['XX'], 'recovered DeviatoricStress YY': recDeviatoricStress['YY'], 'recovered DeviatoricStress YY Passed': recDeviatoricStressRes['YY'], 'recovered DeviatoricStress XY': recDeviatoricStress['XY'], 'recovered DeviatoricStress XY Passed': recDeviatoricStressRes['XY'], 'stress XX': stress['XX'], 'stress XX Passed': stressRes['XX'], 'stress YY': stress['YY'], 'stress YY Passed': stressRes['YY'], 'stress XY': stress['XY'], 'stress XY Passed': stressRes['XY']} msuite.writeInputsOutputsToCSV(sciBTest.mSuite, observables, "OrthotropicTestStressValues.csv") sciBTest.mSuite.analysisImages = None sciBTest.mSuite.modelImagesToDisplay = None for rGen in getGenerators(["RST", "ReportLab"], sciBTest.outputPathBase): sReps.makeSciBenchReport(sciBTest, mResults, rGen, os.path.join(sciBTest.outputPathBase, "%s-report.%s" %\ (sciBTest.testName, rGen.stdExt)))