Skip to content

Commit

Permalink
Merge pull request #128 from eslickj/master
Browse files Browse the repository at this point in the history
Fixing 'tolist' and time step problems
  • Loading branch information
ou3llnl authored Mar 8, 2018
2 parents 1eea014 + 798b9a4 commit 31a1ff0
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 309 deletions.
Empty file removed exampleGUITest.py
Empty file.
2 changes: 1 addition & 1 deletion foqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def signal_handler(signal, frame):
help="Add an application type to TurbineLite DB")
parser.add_argument("--terminateConsumer",
help = "Terminate the consumer with the given UUID")
parser.add_argument("--runUITestScript",
parser.add_argument("-s", "--runUITestScript",
help="Load and run a user interface test script")
args = parser.parse_args()
# before changing the directory get absolute path for file to load
Expand Down
2 changes: 1 addition & 1 deletion foqus_lib/framework/graph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def run(self):
for vkey in job[nkey]:
if type(job[nkey][vkey]).\
__module__ == numpy.__name__:
job[nkey][vkey] = job[nkey][vkey].tolist()
job[nkey][vkey] = job[nkey][vkey]
if self.turbineSession is None:
self.solveListValTurbine(self.runList)
else:
Expand Down
6 changes: 3 additions & 3 deletions foqus_lib/framework/graph/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def upadteSCDefaults(self, outfile=None):
for name, item in sc["inputs"].iteritems():
if name in self.gr.input[self.name]:
item['default'] = self.gr.input[self.name][name].value
item['default'] = item['default'].tolist()
item['default'] = item['default']
with open(outfile, "wb") as f:
json.dump(sc, f, indent=2)

Expand Down Expand Up @@ -583,9 +583,9 @@ def generateInputJSON(self):
if var.set == "sinter":
try:
if self.altInput is not None:
inputSetL2[vkey] = self.altInput[vkey].tolist()
inputSetL2[vkey] = self.altInput[vkey]
else:
inputSetL2[vkey] = var.value.tolist()
inputSetL2[vkey] = var.value
except:
self.calcError = 23
raise NodeEx(
Expand Down
42 changes: 19 additions & 23 deletions foqus_lib/framework/listen/listen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class foqusListener2(threading.Thread):
'''
This class uses a multiprocessing listener to allow
FOQUS to be controlled over a socket connection.
The main purpose for this is ALAMO adaptive
The main purpose for this is ALAMO adaptive
sampling.
'''
def __init__(self, dat, host = 'localhost', port=56002):
Expand All @@ -20,22 +20,22 @@ def __init__(self, dat, host = 'localhost', port=56002):
# Create a listener
self.address = (host, port)
self.listener = Listener(self.address)

def run(self):
quitListening = False
while True:
#Wait for a connection to be made
conn = self.listener.accept()
while True:
msg = conn.recv()
if not (msg and isinstance(msg, list) and msg[0]):
if not (msg and isinstance(msg, list) and msg[0]):
# ignore improperly formatted messages
continue
if msg[0] == "close":
# close the connection
conn.close()
break
elif msg[0] == "quit":
elif msg[0] == "quit":
# close the connection and don't wait for another
quitListening = True
if self.gt:
Expand All @@ -57,11 +57,11 @@ def run(self):
logging.exception("Error running flowsheet")
conn.send([1])
elif msg[0] == "saveValues":
self.gt.join(10)
self.gt.join(10)
if self.gt.isAlive():
# still waiting but continue so you have a
# chance to shutdown the listener if you want
conn.send([1, "Still Running"])
conn.send([1, "Still Running"])
else:
if self.gt.res:
self.dat.flowsheet.loadValues(self.gt.res)
Expand All @@ -76,7 +76,7 @@ class foqusListener(threading.Thread):
'''
This class uses a multiprocessing listener to allow
FOQUS to be controlled over a socket connection.
The main purpose for this is ALAMO adaptive
The main purpose for this is ALAMO adaptive
sampling.
'''
def __init__(self, dat, host = 'localhost', port=56001):
Expand All @@ -94,34 +94,34 @@ def __init__(self, dat, host = 'localhost', port=56001):
# Create a listener
self.address = (host, port)
self.listener = Listener(self.address)

def setInputs(self, l):
self.inputNames = l

def setOutputs(self, l):
self.outputNames = l

def run(self):
'''
Called by Thread when you run start() method
'''
quitListening = False
# create an input dictionary structure to load values from
inpDict = self.dat.flowsheet.saveValues()['input']
inpDict = self.dat.flowsheet.saveValues()['input']
# Enter loop waiting for requests from client
while True:
#Wait for a connection to be made
conn = self.listener.accept()
while True:
msg = conn.recv()
if not (msg and isinstance(msg, list) and msg[0]):
if not (msg and isinstance(msg, list) and msg[0]):
# ignore improperly formatted messages
continue
if msg[0] == "close":
# close the connection
conn.close()
break
elif msg[0] == "quit":
elif msg[0] == "quit":
# close the connection and don't wait for another
quitListening = True
conn.close()
Expand All @@ -145,14 +145,12 @@ def run(self):
varVals = msg[1] #List of variable values
sampInput = copy.deepcopy(inpDict)
vals = self.dat.flowsheet.input.unflatten(
self.inputNames,
varVals,
self.inputNames,
varVals,
unScale=self.scaled)
for nkey in vals:
for vkey in vals[nkey]:
ts = self.dat.flowsheet.input[nkey][vkey].ts
sampInput[nkey][vkey][ts]=\
vals[nkey][vkey].tolist()
sampInput[nkey][vkey] = vals[nkey][vkey]
self.samples.append(sampInput)
runIndex = len(self.samples) - 1
conn.send(['submitted', runIndex])
Expand All @@ -166,9 +164,9 @@ def run(self):
stat = []
for res in self.gt.res:
self.dat.flowsheet.results.addFromSavedValues(
self.resStoreSet,
self.resStoreSet,
'res_{0}'.format(self.runid),
None,
None,
res)
self.runid += 1
stat.append(res['graphError'])
Expand All @@ -177,9 +175,7 @@ def run(self):
vn = vn.split('.', 1)
nodeName = vn[0]
varName = vn[1]
r += np.array(
res['output'][nodeName][varName]\
).flatten().tolist()
r += res['output'][nodeName][varName]
if res['graphError'] != 0:
for i in range(len(r)):
r[i] = self.failValue
Expand Down
25 changes: 13 additions & 12 deletions foqus_lib/framework/sampleResults/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ def sd_col_list(sd, time=None):
for n, d in sd[s[0]].iteritems():
for v in d:
columns.append("{}.{}.{}".format(s[1], n, v))
dat.append(sd[s[0]][n][v])
el = sd[s[0]][n][v]
if s[1] == "setting":
el = repr(el)
dat.append(el)
#node error and turbine messages columns
for s in [["nodeError", "node_err"], ["turbineMessages", "turb"]]:
for n in sd[s[0]]:
columns.append("{}.{}".format(s[1], n))
dat.append(sd[s[0]][n])
# return the list of of columns and list of accosiated data.
# return the list of of columns and list of associated data.
return (columns, dat)

def incriment_name(name, exnames):
Expand Down Expand Up @@ -217,21 +220,19 @@ def loadDict(self, sd):
except:
logging.getLogger("foqus." + __name__).exception(
"Error loading stored results")
try:
for i in sd["__filters"]:
self.filters[i] = dataFilter().loadDict(sd["__filters"][i])
except:
pass
for i in sd.get("__filters", []):
self.filters[i] = dataFilter().loadDict(sd["__filters"][i])
self.update_filter_indexes()

def data_sets(self):
"""
Return a set of data set labels
"""
"""Return a set of data set labels"""
return set(self.loc[:,"set"])

def addFromSavedValues(self, set_name, result_name, time, sd):
self.add_result(sd, set_name=set_name, result_name=result_name, time=time)
def addFromSavedValues(self, setName, name, time=None, valDict=None):
"""Temoprary function for compatablility
should move to add_result()
"""
self.add_result(valDict, set_name=setName, result_name=name, time=time)

def add_result(self, sd, set_name="default", result_name="res", time=None):
"""
Expand Down
2 changes: 1 addition & 1 deletion foqus_lib/framework/surrogate/surrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def writePluginTop(
lines.append(s12+'vdesc = "{0}",'.format(desc))
lines.append(s12+'tags = [],')
lines.append(s12+'dtype = float)')
inputvals.append(defVal.tolist())
inputvals.append(defVal)
# input vector of default values (needed for ACOSSO, BSS-ANOVA & iREVEAL)
lines.append(s8+"self.inputvals = {0}".format(json.dumps(inputvals)))
# output variables
Expand Down
36 changes: 20 additions & 16 deletions foqus_lib/framework/uq/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
import time
import platform
import logging

try:
from PyQt5 import QtGui, QtCore, QtWidgets
Expand Down Expand Up @@ -37,16 +38,16 @@ def __init__(self, parent=None):
#self.doneButton.setEnabled(False)
#self.doneButton.clicked.connect(self.close)
#self.gridLayout.addWidget(self.doneButton)

def showError(self, error, out = None):
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Critical)
msgBox.setText(error + '\nPlease consult the FOQUS UQ developers for assistance.')
if out is not None:
msgBox.setDetailedText(out)
msgBox.exec_()


@staticmethod
def getPsuadePath(): ### OBSOLETE in this release
# Brenda's version of getPsuadePath(), superceded by LocalExecutionModule.getPsuadePath()
Expand Down Expand Up @@ -111,7 +112,7 @@ def showError(error, out = None, showDeveloperHelpMessage = True):
# Pass a filename as a string to use as input file (e.g. "psuade ps.in")
# Requires a psuade formatted file
# Pass a file handle to use it as a script (e.g. "psuade < script")
def invokePsuade(arg1, arg2 = None, printOutputToScreen = False, textDialog = None,
def invokePsuade(arg1, arg2 = None, printOutputToScreen = False, textDialog = None,
dialogShowSignal = None,
dialogCloseSignal = None,
textInsertSignal = None,
Expand All @@ -120,7 +121,7 @@ def invokePsuade(arg1, arg2 = None, printOutputToScreen = False, textDialog = No
plotOuuValuesSignal = None,
):
from LocalExecutionModule import LocalExecutionModule

psuadePath = LocalExecutionModule.getPsuadePath()
if psuadePath is None:
return (None, None)
Expand Down Expand Up @@ -185,18 +186,18 @@ def runCommandInWindow(command,
stderr=subprocess.PIPE,
executable=executable,
shell=True)


logFile = open(logFile, 'w')


if usePyside and QtWidgets.QApplication.instance() is not None:
if textDialog is None:
Common.dialog = Common.textDialog()
Common.dialog.show()
Common.dialog = Common.textDialog()
Common.dialog.show()
else:
Common.dialog = textDialog
dialogShowSignal.emit()
Common.dialog = textDialog
dialogShowSignal.emit()

out = ''
count = 0
Expand Down Expand Up @@ -295,10 +296,15 @@ def runCommandInWindow(command,
print '\n\n'

logFile.close()

# process error
out2, error = p.communicate()
p.terminate()
try:
p.terminate()
except:
logging.getLogger("foqus." + __name__)\
.exception('Error terminating PSUADE process, this may be okay'
'but not sure so logged it (JCE)')
if error:
if showErrorSignal is None:
Common.showError(error, out)
Expand Down Expand Up @@ -337,5 +343,3 @@ def getUserRegressionOutputName(outName, userRegressionFile, data):
index = outName.index('.')
outName = outName[index + 1:]
return outName


Loading

0 comments on commit 31a1ff0

Please sign in to comment.