Commit 1580c9de authored by John Tourtellott's avatar John Tourtellott

Merge branch 'ace3p-debug' into 'master'

Ace3p debug

See merge request !65
parents 208298da f70cb757
......@@ -39,12 +39,16 @@ class Export(smtk.operation.Operation):
def name(self):
return "export ACE3P"
# NOTE: Here is where we could/should do semantic validation
def ableToOperate(self):
return smtk.operation.Operation.ableToOperate(self)
def operateInternal(self):
success = ExportCMB(self.parameters(), self.log)
success = ExportCMB(self)
smtk.ErrorMessage(self.log(), sys.exc_info()[0])
return self.createResult(smtk.operation.Operation.Outcome.FAILED)
print('Error', self.log().convertToString())
# Return with success
result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
......@@ -84,7 +88,7 @@ class Export(smtk.operation.Operation):
ExportScope = type('ExportScope', (object,), dict())
# ---------------------------------------------------------------------
def ExportCMB(operator_spec, log):
def ExportCMB(export_op):
'''Entry function, called by operator to write export files
Returns boolean indicating success
......@@ -92,34 +96,39 @@ def ExportCMB(operator_spec, log):
spec: Attribute Resource specifying the export operation
print 'Enter ExportCMB()', operator_spec, log
print 'Enter ExportCMB()', export_op
# Initialize scope instance to store spec values and other info
scope = ExportScope()
scope.logger = log
scope.export_att = operator_spec
scope.sim_atts = smtk.attribute.Resource.CastTo(operator_spec.find('attributes').value())
scope.logger = export_op.log()
scope.export_att = export_op.parameters()
scope.sim_atts = smtk.attribute.Resource.CastTo(scope.export_att.find('attributes').value())
if scope.sim_atts is None:
msg = 'ERROR - No simlation attributes'
print msg
raise Exception(msg)
model_resource = smtk.model.Resource.CastTo(operator_spec.find('model').value())
if model_resource is None:
# Get model resource
model_entity = smtk.model.Entity.CastTo(scope.export_att.find('model').objectValue(0))
scope.model_resource = smtk.model.Resource.CastTo(model_entity.resource())
if scope.model_resource is None:
msg = 'ERROR - No model'
print msg
raise Exception(msg)
scope.model_manager = model_resource
scope.model_path = model_resource.location()
scope.model_file = os.path.basename(scope.model_path)
raise RuntimeError(msg)
# Get model
model_item = scope.export_att.findFile('MeshFile')
if model_item is None:
msg = 'MeshFile item not found -- cannot export'
raise RuntimeError(msg)
scope.model_path = model_item.value(0)
print 'scope.model_path %s' % scope.model_path
export_spec_att = operator_spec
scope.model_file = os.path.basename(scope.model_path)
# Initialize solver list
solver_item = export_spec_att.findString('Analysis')
solver_item = scope.export_att.findString('Analysis')
if solver_item is None:
msg = 'Missing \"Analysis\" item -- cannot export'
......@@ -129,6 +138,9 @@ def ExportCMB(operator_spec, log):
raise Exception(msg)
solver_string = solver_item.value(0)
print 'solver_string:', solver_string
scope.solver_list = solver_string.split('.')
......@@ -148,14 +160,19 @@ def ExportCMB(operator_spec, log):
# # And save for later
# scope.domain_source = source_item.value(0)
folder_item = export_spec_att.findDirectory('OutputFolder')
# Get output folder
folder_item = scope.export_att.findDirectory('OutputFolder')
if folder_item is None or not folder_item.isSet(0):
msg = 'Output folder not set -- cannot export'
raise Exception(msg)
scope.output_folder = folder_item.value(0)
# Create output folder if needed
if not os.path.exists(scope.output_folder):
file_prefix_item = export_spec_att.findString('OutputFilePrefix')
# Get output file prefix
file_prefix_item = scope.export_att.findString('OutputFilePrefix')
if file_prefix_item is None or not file_prefix_item.isSet(0):
msg = 'Output file prefix not set -- cannot export'
......@@ -264,7 +281,7 @@ def ExportCMB(operator_spec, log):
# (else)
# Check for NERSCSimulation item
sim_item = export_spec_att.find('NERSCSimulation')
sim_item = scope.export_att.find('NERSCSimulation')
if sim_item is not None and sim_item.isEnabled():
# Import nersc module (only when needed)
from internal.writers import nersc
<?xml version="1.0"?>
<SMTK_AttributeResource Version="3">
<AttDef Type="ace3p-export" BaseType="operation" Label="Export to ACE3P">
<AttDef Type="ace3p-export" BaseType="operation" Label="Export to ACE3P" Version="1">
Write ACE3P input file for selected program.
<Resource Name="model" Label="Model">
<Component Name="model" Label="Model" LockType="DoNotLock">
<Resource Name="smtk::model::Resource"/>
<Resource Name="smtk::model::Resource" Filter="model" />
<Resource Name="attributes" Label="Attributes">
<Resource Name="smtk::attribute::Resource"/>
<File Name="MeshFile" Label="Mesh File" ShouldExist="True"
FileFilters="Exodus files (*.exo *.ex2 *.gen);;NetCDf files (*.ncdf);; All files (*.*)" Version="0"/>
<String Name="Analysis" Label="ACE3P Analysis" Version="0">
<Directory Name="OutputFolder" Label="Export Folder" Version="0">
Log into nersc machine and get newt session id
import argparse
import getpass
import requests
nersc_url = ''
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Login to obtain newt session id')
parser.add_argument('--machine', '-m', default='cori', help='cori or edison')
parser.add_argument('--user', '-u', default='johnt', help='user name')
args = parser.parse_args()
# print(args)
print('Username: {}'.format(args.user))
print('Machine: {}'.format(args.machine))
password = getpass.getpass(prompt='Password: ')
# One time password for MFA
otp = input('Enter one time password (for MFA)')
# print('ready')
credentials = {
'username': args.user,
'password': password + str(otp)
url = '{}/login/'.format(nersc_url)
r =, data=credentials)
js = r.json()
if js.get('auth'):
session_id = js.get('newt_sessionid')
print('newt_sessionid: {}'.format(session_id))
print('NOT authenticated, response:')
Continually logs user's queue on nersc machine
import argparse
import datetime
import time
import requests
nersc_url = ''
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Login to obtain newt session id')
parser.add_argument('--machine', '-m', default='cori', help='cori or edison')
parser.add_argument('--outfile', '-o', help='output logfile')
parser.add_argument('--user', '-u', default='johnt', help='user name')
parser.add_argument('--wait_sec', '-w', default=5, help='delay between each queue request')
# Add session id either as string or file to read
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--sessionid', '-s', help='newt session id')
group.add_argument('--id_filename', '-i', help='filename containing newt session id')
args = parser.parse_args()
# print(args)
print('Username: {}'.format(args.user))
print('Machine: {}'.format(args.machine))
url = '{}/queue/{}?user={}'.format(nersc_url, args.machine, args.user)
newt_sessionid = None
if args.sessionid:
elif args.id_filename:
with open(args.id_filename) as f:
newt_sessionid =
if not newt_sessionid:
raise RuntimeError('Not able to read session id file {}'.format(args.if_filename))
cookies = dict(newt_sessionid=newt_sessionid)
# Rest logfile
if args.outfile:
with open(args.outfile, 'w') as f:
start_time =
td = None # time delta
print('Begin logging loop: use Control-C to break')
while True:
if td is None:
td = datetime.timedelta()
td = - start_time
r = requests.get(url, cookies=cookies)
js = r.json()
data = '{}: {}'.format(td, js)
# Log to file
if args.outfile:
complete = False
with open(args.outfile, 'a') as f:
complete = True
if not complete:
print('Unabled to write to output file {}'.format(args.outfile))
# Delay
except KeyboardInterrupt:
r =, data=credentials)
js = r.json()
if js.get('auth'):
session_id = js.get('newt_sessionid')
print('newt_sessionid: {}'.format(session_id))
print('NOT authenticated, response:')
......@@ -260,7 +260,7 @@ class Track3PWriter(basewriter.BaseWriter):
ent_ref = model_ent_item.value(i)
ent = ent_ref.entity()
prop_idlist = self.scope.model_manager.integerProperty(ent, 'pedigree id')
prop_idlist = self.scope.model_resource.integerProperty(ent, 'pedigree id')
#print 'idlist', idlist
if prop_idlist:
#scope.output.write(' %d' % idlist[0])
......@@ -11,14 +11,14 @@ import smtk.model
def get_model_info(scope):
'''DEPRECATED Finds/updates model-related info on input scope object:
* scope.model_manager
* scope.model_resource
* scope.model_ent
* scope.model_file
* scope.model_path
scope.model_manager = scope.sim_atts.refModelResource()
scope.model_resource = scope.sim_atts.refModelResource()
mask = int(smtk.model.MODEL_ENTITY)
model_ents = scope.model_manager.entitiesMatchingFlags(mask, True)
model_ents = scope.model_resource.entitiesMatchingFlags(mask, True)
#print 'model_ents', model_ents
if not model_ents:
msg = 'No model - cannot export'
......@@ -33,7 +33,7 @@ def get_model_info(scope):
# Get path to native model from string properties
# that *should* be on the model
urls = scope.model_manager.stringProperty(scope.model_ent, 'url')
urls = scope.model_resource.stringProperty(scope.model_ent, 'url')
if not urls:
msg = 'Model has to string property \"url\"'
print 'ERROR: %s' % msg
......@@ -51,7 +51,7 @@ def get_model_info(scope):
scope.model_path = url
# Path to native model is relative to .smtk model file
smtk_urls = scope.model_manager.stringProperty(
smtk_urls = scope.model_resource.stringProperty(
scope.model_ent, 'smtk_url')
if not smtk_urls:
msg = 'Model has no string property \"smtk_url\". Cannot get path to native model'
......@@ -105,7 +105,7 @@ def get_entity_ids(scope, model_entity_item):
ent = model_entity_item.objectValue(i)
prop_idlist = scope.model_manager.integerProperty(, 'pedigree id')
prop_idlist = scope.model_resource.integerProperty(, 'pedigree id')
if prop_idlist:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment