Skip to content

Commit

Permalink
Merge commit '9d7b56399ac235e1d53725c22f09c9556de0a788'
Browse files Browse the repository at this point in the history
  • Loading branch information
moosetest committed Oct 29, 2018
2 parents 3c62067 + 9d7b563 commit d3b2d86
Show file tree
Hide file tree
Showing 47 changed files with 788 additions and 106 deletions.
14 changes: 8 additions & 6 deletions doc/workshop/ExternalModels/projectile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
# (x,y) - vector positions of projectile in time
# t - corresponding time steps
#
from __future__ import division, print_function, unicode_literals, absolute_import
import numpy as np


def prange(v,th,y0=0,g=9.8):
"""
Calculates the analytic range.
Expand Down Expand Up @@ -106,9 +108,9 @@ def run(self,Input):
#can be used as a code as well
if __name__=="__main__":
import sys
print 'Welcome to RAVEN\'s Simple Projectile Motion Simulator!'
print('Welcome to RAVEN\'s Simple Projectile Motion Simulator!')
inFile = sys.argv[sys.argv.index('-i')+1]
print 'Reading input from',inFile,'...'
print('Reading input from',inFile,'...')
outFile = sys.argv[sys.argv.index('-o')+1]
#construct the input
Input = {}
Expand All @@ -125,10 +127,10 @@ class IO:
pass
io = IO()
#run the code
print 'Simulating ...'
print('Simulating ...')
run(io,Input)
#write output
print 'Writing output to',outFile+'.txt','...'
print('Writing output to',outFile+'.txt','...')
outFile = open(outFile+'.txt','w')
header = ' '.join("{:8s}".format(i) for i in ('x0','y0','v0','ang','r','x','y','t'))+ '\n'
outFile.writelines(header.strip()+'\n')
Expand All @@ -138,5 +140,5 @@ class IO:
outFile.writelines('-'*(8*8+4)+'\n')
outFile.writelines('SUCCESS'+'\n')
outFile.close()
print 'Done!'
print ''
print('Done!')
print('')
2 changes: 1 addition & 1 deletion framework/CodeInterfaces/MooseBasedApp/MOOSEparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self, inputFile):
if not line.startswith(b'#'):
ind = line.find(b'=')
if ind != -1:
listLine = line.split(b'=')
listLine = line.split(b'=', 1)
attribName = listLine[0].strip()
if b'#' not in listLine[1]:
attribValue = listLine[1].strip()
Expand Down
6 changes: 3 additions & 3 deletions framework/CodeInterfaces/PHISICS/DecayParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def matrixPrinter(self, line, outfile, atomicNumber):
"""
line = line.upper().split()
line[0] = re.sub(r'(.*?)(\w+)(-)(\d+M?)', r'\1\2\4', line[0]) # remove isotope dashes
for isotopeID in self.listedDict.iterkeys():
for isotopeID in self.listedDict.keys():
if line[0] == isotopeID:
typeOfDecayPerturbed = []
typeOfDecayPerturbed = self.listedDict.get(isotopeID, {}).keys()
typeOfDecayPerturbed = list(self.listedDict.get(isotopeID, {}).keys())
for i in range(len(typeOfDecayPerturbed)):
try:
if self.isotopeClassifier.get(isotopeID) == self.isotopeParsed[0]: # it means the isotope is an actinide
Expand Down Expand Up @@ -189,7 +189,7 @@ def fileReconstruction(self):
@ Out, None
"""
perturbedIsotopes = []
for key in self.pertDict.iterkeys():
for key in self.pertDict.keys():
splittedDecayKeywords = key.split('|')
perturbedIsotopes.append(splittedDecayKeywords[2])
for i in range(len(perturbedIsotopes)):
Expand Down
4 changes: 2 additions & 2 deletions framework/CodeInterfaces/PHISICS/MassParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def matrixPrinter(self, line, outfile):
"""
line = line.upper().split()
line[0] = re.sub(r'(.*?)(\w+)(-)(\d+M?)', r'\1\2\4', line[0])
for isotopeID in self.listedDict['MASS'].iterkeys():
for isotopeID in self.listedDict['MASS'].keys():
if line[0] == isotopeID:
try:
line[2] = str(
Expand Down Expand Up @@ -89,7 +89,7 @@ def fileReconstruction(self, deconstructedDict):
perturbedIsotopes = []
perturbedMaterials = []
perturbedPhysicalParameters = []
for key in deconstructedDict.iterkeys():
for key in deconstructedDict.keys():
perturbedIsotopes.append(key.split('|')[1])
perturbedPhysicalParameters.append(key.split('|')[0])
for i in range(len(perturbedPhysicalParameters)):
Expand Down
4 changes: 2 additions & 2 deletions framework/CodeInterfaces/PHISICS/PhisicsInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def distributeVariablesToParsers(self, perturbedVars):
"""
distributedPerturbedVars = {}
pertType = []
for i in perturbedVars.iterkeys(
for i in perturbedVars.keys(
): # teach what are the type of perturbation (decay FY etc...)
splittedKeywords = i.split('|')
pertType.append(splittedKeywords[0])
Expand Down Expand Up @@ -485,7 +485,7 @@ def createNewInput(self, currentInputFiles, oriInputFiles, samplerType,
self.numberOfMPI = 1
else:
self.numberOfMPI = self.getNumberOfMpi(Kwargs['precommand'])
for perturbedParam in self.distributedPerturbedVars.iterkeys():
for perturbedParam in self.distributedPerturbedVars.keys():
if perturbedParam == 'DECAY':
DecayParser.DecayParser(
currentInputFiles[self.typeDict['decay']].getAbsFile(),
Expand Down
14 changes: 7 additions & 7 deletions framework/CodeInterfaces/PHISICS/phisicsdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def getMrtauIsotopeList(self, atomsInp):
line = re.sub(r'TIME\s+\(days\)', r'', line)
line = re.sub(r' ', r'', line)
line = re.sub(r'\n', r'', line)
self.isotopeListMrtau = filter(None, line.split(','))
self.isotopeListMrtau = list(filter(None, line.split(',')))
break

def getInstantTimeSteps(self, input):
Expand Down Expand Up @@ -826,7 +826,7 @@ def locateMaterialInFile(self, numberOfMPI):
for line in outfile:
if re.search(r'Density spatial moment', line):
count = count + 1
matLine = filter(None, line.split(' '))
matLine = list(filter(None, line.split(' ')))
materialsDict['MPI-' + str(mpi)][count] = matLine[
matLine.index('Material') + 1]
if count == mediaUsed:
Expand Down Expand Up @@ -870,7 +870,7 @@ def getDecayHeat(self, timeStepIndex, matchedTimeSteps, decayHeatFlag):
breakFlag = 1
if decayFlag == 1 and breakFlag == 0:
line = line.rstrip()
decayLine = filter(None, line.split(' '))
decayLine = list(filter(None, line.split(' ')))
if decayLine != []:
stringIsFloatNumber = self.isFloatNumber(decayLine)
if stringIsFloatNumber and decayLine != []:
Expand Down Expand Up @@ -910,7 +910,7 @@ def getDecayHeatMrtau(self, timeStepIndex, matchedTimeSteps,
breakFlag = 1
if decayFlag == 1 and breakFlag == 0:
line = line.rstrip()
decayLine = filter(None, line.split(' '))
decayLine = list(filter(None, line.split(' ')))
if decayLine != []:
stringIsFloatNumber = self.isFloatNumber(decayLine)
if stringIsFloatNumber and decayLine != []:
Expand Down Expand Up @@ -952,7 +952,7 @@ def getBurnUp(self, timeStepIndex, matchedTimeSteps):
breakFlag = 1
if buFlag == 1 and breakFlag == 0:
line = line.rstrip()
buLine = filter(None, line.split(' '))
buLine = list(filter(None, line.split(' ')))
if buLine != []:
stringIsFloatNumber = self.isFloatNumber(buLine)
if stringIsFloatNumber and buLine != []:
Expand Down Expand Up @@ -1062,8 +1062,8 @@ def writeMrtauCSV(self, mrtauDict):
with open(csvOutput, 'a+') as f:
mrtauWriter = csv.writer(
f,
delimiter=str(u',').encode('utf-8'),
quotechar=str(u',').encode('utf-8'),
delimiter=str(','),
quotechar=str(','),
quoting=csv.QUOTE_MINIMAL)
if mrtauDict.get('timeStepIndex') == 0:
mrtauWriter.writerow(['timeMrTau'] + self.numDensityLabelListMrtau +
Expand Down
6 changes: 3 additions & 3 deletions framework/CodeInterfaces/RELAP5/relapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,13 @@ def writeCSV(self,filen):
if len(self.ravenData) > 0:
IOcsvfile.write(',')
for j in range(len(self.ravenData.keys())):
IOcsvfile.write('%s' %(self.ravenData.keys()[j]))
IOcsvfile.write('%s' %(list(self.ravenData.keys())[j]))
if j+1<len(self.ravenData.keys()): IOcsvfile.write(',')
IOcsvfile.write('\n')
for i in range(len(self.minordata.get(list(self.minordata.keys())[0]))):
IOcsvfile.write(','.join(self.minordata.get(self.minordata.keys()[j])[i] for j in range(len(self.minordata.keys()))))
IOcsvfile.write(','.join(self.minordata.get(list(self.minordata.keys())[j])[i] for j in range(len(self.minordata.keys()))))
if len(self.ravenData)>0:
IOcsvfile.write(',')
IOcsvfile.write(','.join(self.ravenData[self.ravenData.keys()[k]] for k in range(len(self.ravenData.keys()))))
IOcsvfile.write(','.join(self.ravenData[list(self.ravenData.keys())[k]] for k in range(len(self.ravenData.keys()))))
IOcsvfile.write('\n')
IOcsvfile.close()
5 changes: 4 additions & 1 deletion framework/CrossValidations/SklCrossValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def __init__(self, messageHandler, **kwargs):

self.__class__.returnType = self.__class__.availImpl[self.SKLType][1]

for key, value in self.initOptionDict.items():
#Need to keep a copy of the keys since the dict is changing
keys = list(self.initOptionDict.keys())
for key in keys:
value = self.initOptionDict[key]
try:
newValue = ast.literal_eval(value)
if type(newValue) == list:
Expand Down
2 changes: 2 additions & 0 deletions framework/GridEntities.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ def initialize(self,initDictionary=None):
self.gridContainer['transformationMethods'] = initDict["transformationMethods"]
self.nVar = len(self.gridInitDict["dimensionNames"]) if "dimensionNames" in self.gridInitDict.keys() else len(initDict["dimensionNames"])
self.gridContainer['dimensionNames'] = self.gridInitDict["dimensionNames"] if "dimensionNames" in self.gridInitDict.keys() else initDict["dimensionNames"]
#expand iterator with list()
self.gridContainer['dimensionNames'] = list(self.gridContainer['dimensionNames'])
upperkeys = list(self.gridInitDict["upperBounds"].keys() if "upperBounds" in self.gridInitDict.keys() else initDict["upperBounds" ].keys())
lowerkeys = list(self.gridInitDict["lowerBounds"].keys() if "lowerBounds" in self.gridInitDict.keys() else initDict["lowerBounds" ].keys())
self.gridContainer['dimensionNames'].sort()
Expand Down
2 changes: 1 addition & 1 deletion framework/Metrics/MetricUtilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _getPDFandCDFfromWeightedData(data, weights, numBins, uniformBins, interpola
@ Out, (dataStats, cdfFunc, pdfFunc), tuple, dataStats is dictionary with things like "mean" and "stdev", cdfFunction is a function that returns the CDF value and pdfFunc is a function that returns the PDF value.
"""
# Sort the data
sortedData = zip(data, weights)
sortedData = list(zip(data, weights))
sortedData.sort() #Sort the data.
weightSum = sum(weights)
value = 0 #Read only
Expand Down
5 changes: 3 additions & 2 deletions framework/Models/HybridModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import numpy as np
from numpy import linalg
import time
import itertools
from collections import OrderedDict
#External Modules End--------------------------------------------------------------------------------

Expand Down Expand Up @@ -609,7 +610,7 @@ def evaluateSample(self, myInput, samplerType, kwargs):
@ Out, rlz, dict, This holds the output information of the evaluated sample.
"""
self.raiseADebug("Evaluate Sample")
kwargsKeys = kwargs.keys()
kwargsKeys = list(kwargs.keys())
kwargsKeys.pop(kwargsKeys.index("jobHandler"))
kwargsToKeep = {keepKey: kwargs[keepKey] for keepKey in kwargsKeys}
jobHandler = kwargs['jobHandler']
Expand All @@ -619,7 +620,7 @@ def evaluateSample(self, myInput, samplerType, kwargs):
# assure rlz has all metadata
rlz = dict((var,np.atleast_1d(kwargsToKeep[var])) for var in kwargsToKeep.keys())
# update rlz with input space from inRun and output space from result
rlz.update(dict((var,np.atleast_1d(kwargsToKeep['SampledVars'][var] if var in kwargs['SampledVars'] else result[var])) for var in set(result.keys()+kwargsToKeep['SampledVars'].keys())))
rlz.update(dict((var,np.atleast_1d(kwargsToKeep['SampledVars'][var] if var in kwargs['SampledVars'] else result[var])) for var in set(itertools.chain(result.keys(),kwargsToKeep['SampledVars'].keys()))))

return rlz

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def readMoreXML(self,xmlNode):
self.name = xmlNode.attrib['name']
for child in xmlNode:
if child.tag == 'subseqLen':
self.subseqLen = map(int, child.text.split(','))
self.subseqLen = list(map(int, child.text.split(',')))
elif child.tag == 'pivotParameter':
self.pivotParameter = child.text
elif child.tag == 'outputLen':
Expand Down
2 changes: 1 addition & 1 deletion framework/PostProcessors/CrossValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def initialize(self, runInfo, inputs, initDict=None) :
if metricIn[2] in self.metricsDict.keys():
self.metricsDict[metricIn[2]] = metricIn[3]

if self.metricsDict.values().count(None) != 0:
if list(self.metricsDict.values()).count(None) != 0:
metricName = self.metricsDict.keys()[list(self.metricsDict.values()).index(None)]
self.raiseAnError(IOError, "Missing definition for Metric: ", metricName)

Expand Down
4 changes: 2 additions & 2 deletions framework/PostProcessors/DataClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#Internal Modules---------------------------------------------------------------
from BaseClasses import BaseType
from utils import InputData
from utils import InputData, utils
from .PostProcessor import PostProcessor
import MessageHandler
import Files
Expand Down Expand Up @@ -232,7 +232,7 @@ def run(self, inputIn):
if outputType == 'HistorySet':
outputDict['historySizes'] = copy.copy(targetDict['historySizes'])

numRlz = targetDict['input'].values()[0].size
numRlz = utils.first(targetDict['input'].values()).size
outputDict[self.label] = np.empty(numRlz)
for i in range(numRlz):
tempTargDict = {}
Expand Down
6 changes: 3 additions & 3 deletions framework/PostProcessors/DataMining.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def __runSciKitLearn(self, Input):
##FIXME: You may also want to output the covariances of each pair of
## dimensions as well, this is currently only accessible from the solution export metadata
## We should list the variables name the solution export in order to access this data
for joffset,col in enumerate(self.unSupervisedEngine.features.keys()[i:]):
for joffset,col in enumerate(list(self.unSupervisedEngine.features.keys())[i:]):
j = i+joffset
covValues = mixtureCovars[:,i,j]
covName = 'cov_'+str(key)+'_'+str(col)
Expand Down Expand Up @@ -820,7 +820,7 @@ def __runTemporalSciKitLearn(self, Input):
rlzDims = {}
rlzs = {}
## First store the label as the input for this cluster
mixLabels = range(int(np.max(componentMeanIndices.values()))+1)
mixLabels = range(int(np.max(list(componentMeanIndices.values())))+1)
rlzs[self.labelFeature] = np.atleast_1d(mixLabels)
rlzs[self.pivotParameter] = self.pivotVariable
for rlzIndex in mixLabels:
Expand Down Expand Up @@ -851,7 +851,7 @@ def __runTemporalSciKitLearn(self, Input):
## dimensions as well
if mixtureCovars is not None:
for i,row in enumerate(self.unSupervisedEngine.features.keys()):
for joffset,col in enumerate(self.unSupervisedEngine.features.keys()[i:]):
for joffset,col in enumerate(list(self.unSupervisedEngine.features.keys())[i:]):
j = i+joffset
timeSeries = np.zeros(numberOfHistoryStep)
for timeIdx in range(numberOfHistoryStep):
Expand Down
20 changes: 10 additions & 10 deletions framework/PostProcessors/FTGate.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,25 +122,25 @@ def evaluateGate(self,argumentValues):
@ Out, outcome, float, calculated outcome of the gate
"""
if self.gate == 'and':
outcome = andGate(argumentValues.values())
outcome = andGate(list(argumentValues.values()))
elif self.gate == 'or':
outcome = orGate(argumentValues.values())
outcome = orGate(list(argumentValues.values()))
elif self.gate == 'nor':
outcome = norGate(argumentValues.values())
outcome = norGate(list(argumentValues.values()))
elif self.gate == 'nand':
outcome = nandGate(argumentValues.values())
outcome = nandGate(list(argumentValues.values()))
elif self.gate == 'xor':
outcome = xorGate(argumentValues.values())
outcome = xorGate(list(argumentValues.values()))
elif self.gate == 'iff':
outcome = iffGate(argumentValues.values())
outcome = iffGate(list(argumentValues.values()))
elif self.gate == 'atleast':
outcome = atLeastGate(argumentValues.values(),float(self.params['min']))
outcome = atLeastGate(list(argumentValues.values()),float(self.params['min']))
elif self.gate == 'cardinality':
outcome = cardinalityGate(argumentValues.values(),float(self.params['min']),float(self.params['max']))
outcome = cardinalityGate(list(argumentValues.values()),float(self.params['min']),float(self.params['max']))
elif self.gate == 'imply':
outcome = implyGate(argumentValues)
elif self.gate == 'not':
outcome = notGate(argumentValues.values())
outcome = notGate(list(argumentValues.values()))
return outcome

def notGate(value):
Expand Down Expand Up @@ -242,7 +242,7 @@ def implyGate(argumentValues):
@ In, argumentValues, list, list of values
@ Out, outcome, float, calculated outcome of the gate
"""
keys = argumentValues.keys()
keys = list(argumentValues.keys())
if argumentValues[keys[0]]==1 and argumentValues[keys[1]]==0:
outcome = 0
else:
Expand Down
4 changes: 2 additions & 2 deletions framework/PostProcessors/FTStructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def FTsolver(self):
"""
self.gateSequence = []
availBasicEvents = copy.deepcopy(self.basicEvents)
availBasicEvents = availBasicEvents + self.houseEvents.keys()
availBasicEvents = availBasicEvents + list(self.houseEvents.keys())
counter = 0
while True:
complete=False
for gate in self.gateList.keys():
if set(self.gateList[gate].returnArguments()) <= set(availBasicEvents):
self.gateSequence.append(gate)
availBasicEvents.append(gate)
if set(availBasicEvents) == set(self.basicEvents+self.gateID+self.houseEvents.keys()):
if set(availBasicEvents) == set(itertools.chain(self.basicEvents,self.gateID,self.houseEvents.keys())):
complete=True
break
if counter > len(self.gateList.keys()):
Expand Down
4 changes: 2 additions & 2 deletions framework/PostProcessors/RavenOutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class RavenOutput(PostProcessor):
# outputDict={'realizations':[]}
# if self.dynamic:
# #outputs are basically a point set with pivot as input and requested XML path entries as output
# fileName = self.files.values()[0]['fileObject'].getAbsFile()
# fileName = utils.first(self.files.values())['fileObject'].getAbsFile()
# root,_ = xmlUtils.loadToTree(fileName)
# #determine the pivot parameter
# pivot = root[0].tag
Expand All @@ -202,7 +202,7 @@ class RavenOutput(PostProcessor):
# for p,pivotStep in enumerate(root):
# realization = {'inputs':{},'outputs':{},'metadata':{'loadedFromRavenFile':fileName}}
# realization['inputs'][pivot] = float(pivotStep.attrib['value'])
# for name,path in self.files.values()[0]['paths'].items():
# for name,path in utils.first(self.files.values())['paths'].items():
# desiredNode = self._readPath(pivotStep,path,fileName)
# realization['outputs'][name] = float(desiredNode.text)
# outputDict['realizations'].append(realization)
Expand Down
2 changes: 1 addition & 1 deletion framework/Runners/Runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __del__(self):
"""
if self.__printTimings:
# print timing history
pairs = self.timings.items()
pairs = list(self.timings.items())
pairs.sort(key=lambda x:x[1])
prof = ""
prof += 'TIMINGS for job "{}":'.format(self.identifier)
Expand Down
Loading

0 comments on commit d3b2d86

Please sign in to comment.