Commit 0a39087a authored by John Tourtellott's avatar John Tourtellott

Update export template and operator to current cmb:master

* Rename ace3p-simulator.sbt to ACE3P.sbt
* Move resource definitions into sbt file (now version 3)
* No more ExportSpec object, but keeping ExportScope for now
* Drop/hide advance-level item (tailfile) - not showing in view,
  but kept operator disabled because it was not set)
* Minor change to girder_client
parent 1ab1cef8
...@@ -19,11 +19,10 @@ import sys ...@@ -19,11 +19,10 @@ import sys
sys.dont_write_bytecode = True sys.dont_write_bytecode = True
import smtk import smtk
if 'pybind11' == smtk.wrappingProtocol(): import smtk.attribute
#print 'Using pybind11 bindings' import smtk.io
import smtk.attribute import smtk.model
import smtk.model #import smtk.simulation
import smtk.simulation
# Add the directory containing this file to the python module search list # Add the directory containing this file to the python module search list
import inspect import inspect
...@@ -41,19 +40,8 @@ class Export(smtk.operation.Operation): ...@@ -41,19 +40,8 @@ class Export(smtk.operation.Operation):
return "export ACE3P" return "export ACE3P"
def operateInternal(self): def operateInternal(self):
sim_attrs = smtk.attribute.Resource.CastTo(self.parameters().find('simulation').value())
exp_attrs = smtk.attribute.Resource.CastTo(self.parameters().find('export').value())
model_resource = smtk.model.Resource.CastTo(self.parameters().find('model resource').value())
sim_attrs.setRefModelResource(model_resource)
# create export spec object
spec = smtk.simulation.ExportSpec()
spec.setSimulationAttributes(sim_attrs)
spec.setExportAttributes(exp_attrs)
try: try:
success = ExportCMB(spec) success = ExportCMB(self.parameters(), self.log)
except: except:
smtk.ErrorMessage(self.log(), sys.exc_info()[0]) smtk.ErrorMessage(self.log(), sys.exc_info()[0])
return self.createResult(smtk.operation.Operation.Outcome.FAILED) return self.createResult(smtk.operation.Operation.Outcome.FAILED)
...@@ -65,18 +53,25 @@ class Export(smtk.operation.Operation): ...@@ -65,18 +53,25 @@ class Export(smtk.operation.Operation):
def createSpecification(self): def createSpecification(self):
spec = self.createBaseSpecification() spec = self.createBaseSpecification()
print 'spec:', spec
opDef = spec.createDefinition('test op', 'operation') # Load export atts
source_dir = os.path.abspath(os.path.dirname(__file__))
print 'source_dir:', source_dir
sbt_path = os.path.join(source_dir, 'internal', 'ace3p-export.sbt')
print 'sbt_path:', sbt_path
reader = smtk.io.AttributeReader()
result = reader.read(spec, sbt_path, self.log())
print 'reader result:', result
simulationDef = smtk.attribute.ResourceItemDefinition.New('simulation') # opDef = spec.createDefinition('test op', 'operation')
opDef = spec.findDefinition('ace3p-export')
simulationDef = smtk.attribute.ResourceItemDefinition.New('attributes')
simulationDef.setAcceptsEntries('smtk::attribute::Resource', '', True) simulationDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
opDef.addItemDefinition(simulationDef) opDef.addItemDefinition(simulationDef)
exportDef = smtk.attribute.ResourceItemDefinition.New('export') modelDef = smtk.attribute.ResourceItemDefinition.New('model')
exportDef.setAcceptsEntries('smtk::attribute::Resource', '', True)
opDef.addItemDefinition(exportDef)
modelDef = smtk.attribute.ResourceItemDefinition.New('model resource')
modelDef.setAcceptsEntries('smtk::model::Resource', '', True) modelDef.setAcceptsEntries('smtk::model::Resource', '', True)
opDef.addItemDefinition(modelDef) opDef.addItemDefinition(modelDef)
...@@ -89,40 +84,39 @@ class Export(smtk.operation.Operation): ...@@ -89,40 +84,39 @@ class Export(smtk.operation.Operation):
ExportScope = type('ExportScope', (object,), dict()) ExportScope = type('ExportScope', (object,), dict())
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
def ExportCMB(spec): def ExportCMB(operator_spec, log):
'''Entry function, called by CMB to write export files '''Entry function, called by operator to write export files
Returns boolean indicating success Returns boolean indicating success
Parameters Parameters
---------- ----------
spec: Top-level object passed in from CMB spec: Attribute Resource specifying the export operation
''' '''
# print 'Enter ExportCMB()' print 'Enter ExportCMB()', operator_spec, log
reload(utils)
# Initialize scope instance to store spec values and other info # Initialize scope instance to store spec values and other info
scope = ExportScope() scope = ExportScope()
scope.logger = spec.getLogger()
scope.sim_atts = spec.getSimulationAttributes() scope.logger = log
scope.export_atts = operator_spec
scope.sim_atts = smtk.attribute.Resource.CastTo(operator_spec.find('attributes').value())
if scope.sim_atts is None: if scope.sim_atts is None:
msg = 'ERROR - No simlation attributes' msg = 'ERROR - No simlation attributes'
print msg print msg
raise Exception(msg) raise Exception(msg)
reload(utils) model_resource = smtk.model.Resource.CastTo(operator_spec.find('model').value())
utils.get_model_info(scope) if 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)
print 'scope.model_path %s' % scope.model_path print 'scope.model_path %s' % scope.model_path
scope.export_atts = spec.getExportAttributes() export_spec_att = operator_spec
if scope.export_atts is not None:
att_list = scope.export_atts.findAttributes('ExportSpec')
if len(att_list) > 1:
msg = 'More than one ExportSpec instance -- ignoring all'
print 'WARNING:', msg
scope.logger.addWarning(msg)
return False
# (else)
export_spec_att = att_list[0]
# Initialize solver list # Initialize solver list
solver_item = export_spec_att.findString('Analysis') solver_item = export_spec_att.findString('Analysis')
......
<?xml version="1.0"?> <?xml version="1.0"?>
<SMTK_AttributeSystem Version="2"> <SMTK_AttributeResource Version="3">
<Definitions> <Definitions>
<AttDef Type="ExportSpec" Label="Settings" BaseType="" Version="0"> <AttDef Type="ace3p-export" BaseType="operation" Label="Export to ACE3P">
<BriefDescription>
Write ACE3P input file for selected program.
</BriefDescription>
<DetailedDescription>
Todo
</DetailedDescription>
<ItemDefinitions> <ItemDefinitions>
<Resource Name="model" Label="Model">
<Accepts>
<Resource Name="smtk::model::Resource"/>
</Accepts>
</Resource>
<Resource Name="attributes" Label="Attributes">
<Accepts>
<Resource Name="smtk::attribute::Resource"/>
</Accepts>
</Resource>
<String Name="Analysis" Label="ACE3P Analysis" Version="0"> <String Name="Analysis" Label="ACE3P Analysis" Version="0">
<ChildrenDefinitions> <ChildrenDefinitions>
<Directory Name="OutputFolder" Label="Export Folder" Version="0"> <Directory Name="OutputFolder" Label="Export Folder" Version="0">
...@@ -126,9 +142,6 @@ ...@@ -126,9 +142,6 @@
</Structure> </Structure>
</DiscreteInfo> </DiscreteInfo>
</String> </String>
<File Name="PythonScript" Label="Python script" Version="0" AdvanceLevel="1" NumberOfRequiredValues="1" ShouldExist="true" FileFilters="Python files (*.py);;All files (*.*)">
<DefaultValue>ACE3P.py</DefaultValue>
</File>
<Group Name="NERSCSimulation" Label="Submit job to NERSC" <Group Name="NERSCSimulation" Label="Submit job to NERSC"
Optional="true" IsEnabledByDefault="false" Optional="true" IsEnabledByDefault="false"
...@@ -212,18 +225,18 @@ ...@@ -212,18 +225,18 @@
<DefaultValue>5</DefaultValue> <DefaultValue>5</DefaultValue>
<RangeInfo><Min Inclusive="true">1</Min></RangeInfo> <RangeInfo><Min Inclusive="true">1</Min></RangeInfo>
</Int> </Int>
<String Name="TailFile" Label="Tail Filename" Version="0" AdvanceLevel="1"> <!-- <String Name="TailFile" Label="Tail Filename" Version="0" AdvanceLevel="1">
</String> </String>
</ItemDefinitions> --> </ItemDefinitions>
</Group> </Group>
</ItemDefinitions> </ItemDefinitions>
</AttDef> </AttDef>
</Definitions> </Definitions>
<Views> <Views>
<View Type="Instanced" Title="Export Settings" TopLevel="true" FilterByCategory="false"> <View Type="Instanced" Title="Export Settings" TopLevel="true" FilterByCategory="false" FilterByAdvanceLevel="true">
<InstancedAttributes> <InstancedAttributes>
<Att Name="Options" Type="ExportSpec" /> <Att Name="Options" Type="ExportSpec" />
</InstancedAttributes> </InstancedAttributes>
</View> </View>
</Views> </Views>
</SMTK_AttributeSystem> </SMTK_AttributeResource>
...@@ -13,8 +13,6 @@ side set 2 ------> Magnetic ...@@ -13,8 +13,6 @@ side set 2 ------> Magnetic
side set 6 ------> Exterior side set 6 ------> Exterior
Conductivity --> 5.78e+07 Conductivity --> 5.78e+07
Magnetic --> side set 1, side set 2
## Materials ## Materials
Material --> New, element block 1 Material --> New, element block 1
......
...@@ -67,7 +67,8 @@ class CumulusClient(): ...@@ -67,7 +67,8 @@ class CumulusClient():
#print 'user', user #print 'user', user
user_id = user['_id'] user_id = user['_id']
r = self._client.listFolder(user_id, 'user', name='Private') r = self._client.listFolder(user_id, 'user', name='Private')
self._private_folder_id = r.next()['_id'] #self._private_folder_id = r.next()['_id']
self._private_folder_id = r[0]['_id']
print 'private_folder_id', self._private_folder_id print 'private_folder_id', self._private_folder_id
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
...@@ -152,7 +153,6 @@ class CumulusClient(): ...@@ -152,7 +153,6 @@ class CumulusClient():
print 'Created job folder', folder_name print 'Created job folder', folder_name
self._input_folder_id = self.get_folder(self._job_folder_id, 'input_files') self._input_folder_id = self.get_folder(self._job_folder_id, 'input_files')
self._output_folder_id = self.get_folder(self._job_folder_id, 'output_files') self._output_folder_id = self.get_folder(self._job_folder_id, 'output_files')
# Make sure job_name isn't null # Make sure job_name isn't null
if not job_name: if not job_name:
job_name = 'CumulusJob' job_name = 'CumulusJob'
......
...@@ -222,9 +222,10 @@ def create_job(scope, solver, sim_item): ...@@ -222,9 +222,10 @@ def create_job(scope, solver, sim_item):
job_name = get_string(sim_item, 'JobName') job_name = get_string(sim_item, 'JobName')
if not job_name: if not job_name:
raise Exception('No Job Name specified -- cannot submit to NERSC') raise Exception('No Job Name specified -- cannot submit to NERSC')
# Next line crashes modelbuilder, because there is no TailFile item any more
tail = get_string(sim_item, 'TailFile') # tail = get_string(sim_item, 'TailFile')
scope.cumulus.create_job(job_name, tail=tail) # scope.cumulus.create_job(job_name, tail=tail)
scope.cumulus.create_job(job_name)
# Add cmb-specific metadata # Add cmb-specific metadata
cmb_data = dict() cmb_data = dict()
......
...@@ -9,7 +9,7 @@ import smtk.model ...@@ -9,7 +9,7 @@ import smtk.model
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
def get_model_info(scope): def get_model_info(scope):
'''Finds/updates model-related info on input scope object: '''DEPRECATED Finds/updates model-related info on input scope object:
* scope.model_manager * scope.model_manager
* scope.model_ent * scope.model_ent
......
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