Commit 95d8f4c6 authored by John Tourtellott's avatar John Tourtellott

Update workflow scripts to work with both pybind11 and shiboken wrappers

Add Developer.md file to list known updates for pybind11-compatible
python scripts.
parent 9a1fe83f
......@@ -17,6 +17,11 @@ import sys
sys.dont_write_bytecode = True
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import smtk.model
import smtk.simulation
ExportScope = type('ExportScope', (object,), dict())
# ---------------------------------------------------------------------
......@@ -36,7 +41,8 @@ def ExportCMB(spec):
scope.sim_atts = spec.getSimulationAttributes()
if scope.sim_atts is not None:
scope.model_manager = scope.sim_atts.refModelManager()
model_ents = scope.model_manager.entitiesMatchingFlags(smtk.model.MODEL_ENTITY, True)
mask = int(smtk.model.MODEL_ENTITY)
model_ents = scope.model_manager.entitiesMatchingFlags(mask, True)
#print 'model_ents', model_ents
if not model_ents:
msg = 'No model - cannot export'
......
......@@ -24,6 +24,9 @@ from girder_client import HttpError
import requests
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import cumulusclient
reload(cumulusclient) # for dev
......
......@@ -32,6 +32,9 @@ import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
import smtk.attribute
import smtk.simulation
# Explicitly load adhcommon and AdHSurfaceWater modules
......
......@@ -15,7 +15,14 @@ Export script for Shallow Water 2D applications
import imp
import os
import sys
sys.path.append('/media/ssd/sim/projects/erdc/build/pybind-superbuild/install/lib')
for path in sys.path:
print path
import smtk
if 'pybind11' == smtk.wrappingProtocol():
import smtk.io
import smtk.simulation
# so devs don't complain about pyc files in source
sys.dont_write_bytecode = True
......@@ -25,8 +32,10 @@ module_name = 'adhcommon'
abs_path = os.path.abspath(__file__)
abs_dir = os.path.dirname(abs_path)
module_args = imp.find_module(module_name, [abs_dir])
print 'module_args', module_args
imp.load_module(module_name, *module_args)
adh = sys.modules.get(module_name)
print 'adh', adh
# Define placeholder/passthrough functions for custom writer functions
# Actual implementations, prefixed by "_", are further below
......@@ -135,7 +144,7 @@ def ExportCMB(spec):
----------
spec: Top-level object passed in from CMB
'''
#print 'Enter ExportCMB()'
print 'Enter ExportCMB()'
# Initialize scope instance to store spec values and other info
scope = adh.init_scope(spec)
......
......@@ -18,7 +18,12 @@ Common functions for all ADH exporters
"""
import os
import smtk
reload(smtk)
if 'pybind11' == smtk.wrappingProtocol():
import smtk.common
import smtk.attribute
import smtk.model
import smtk.mesh
import smtk.io
# Mapping from VTK's tet face ordering to ADH's tet face
......@@ -926,7 +931,8 @@ def assign_model_entity_ids(model, dimension, property_name='id', first=1):
print 'Unrecognized dimension', dimension
return first
entity_list = model.entitiesMatchingFlags(celltype, True)
mask = int(celltype)
entity_list = model.entitiesMatchingFlags(mask, True)
entity_id = first
for entity in entity_list:
model.setIntegerProperty(entity, property_name, entity_id)
......
......@@ -9,12 +9,18 @@
# PURPOSE. See the above copyright notice for more information.
#
#=============================================================================
print 'ENTER dakotaExporter.py'
import bisect
import math
import random
import string
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import smtk.model
import smtk.simulation
def writeMethodItem(writer, i, indent):
if i.isEnabled():
......@@ -203,6 +209,7 @@ def ExportCMB(spec):
writeResponces(writer,responces)
writer.close()
print 'Wrote', output_file_name
#
# Below are utility functions that are used by ExportCMB()
......
# Notes for developers
## Python scripts
For compatibility with pybind11 bindings
* Import smtk submodules where needed
* Note that smtk.simulation is needed in files where
ExportCMB() function is called.
* Must explicitly pass integer to smtk.modelManager.entitiesMatchingFlags()
* Pybind doesn't need or have smtk.to_concrete()
* Pybind doesn't need or have smtk.attribute.System.CastTo()
* Pybind doesn't need or have smtk.attribute.AttributePtr
* Pybind uses unicode instead of str, so use isinstance(object, basestring)
......@@ -16,6 +16,9 @@ import imp
import os
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.simulation
# Import formatters module explicitly, so that it always reloads
module_name = 'formatters'
......@@ -123,9 +126,12 @@ def ExportCMB(spec):
project_path = None
item = export_spec_att.find('ProjectPath')
if item is not None:
dir_item = smtk.to_concrete(item)
project_path = dir_item.value(0)
#print 'project_path', project_path
if 'shiboken' == smtk.wrappingProtocol():
dir_item = smtk.to_concrete(item)
else:
dir_item = item
project_path = dir_item.value(0)
#print 'project_path', project_path
if not project_path:
msg = 'No project_path specified -- cannot export'
......
......@@ -103,8 +103,9 @@ class ProjectCardFormat:
att = None
# Check input type (don't forget shared pointer type!)
if isinstance(att_or_system, smtk.attribute.Attribute) or \
isinstance(att_or_system, smtk.AttributePtr):
if isinstance(att_or_system, smtk.attribute.Attribute):
att = att_or_system
elif hasattr(smtk, 'AttributePtr') and isinstance(att_or_system, smtk.AttributePtr):
att = att_or_system
# If attribute system passed in, look for 1 attribute instance
......
......@@ -3,6 +3,12 @@ import os
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.common
import smtk.attribute
import smtk.model
import smtk.io
# Hard-code inputs for now
INPUT_SIMULATION_ATTS = 'test1.crf'
......@@ -97,11 +103,17 @@ if __name__ == '__main__':
# Extract attribute systems and construct MockExportSpec
simbuilder_resource = resource_set.get('simbuilder')
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
if 'shiboken' == smtk.wrappingProtocol():
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
else:
sim_atts = simbuilder_resource
print 'sim_atts', sim_atts
export_resource = resource_set.get('export')
export_atts = smtk.attribute.System.CastTo(export_resource)
if 'shiboken' == smtk.wrappingProtocol():
export_atts = smtk.attribute.System.CastTo(export_resource)
else:
export_atts = export_resource
print 'export_atts', export_atts
# Initialize Attribute in export_atts
......
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import smtk.simulation
# Common data structures & functions
ConfigData = type('ConfigData', (object,), dict())
......
......@@ -18,6 +18,9 @@ sys.dont_write_bytecode = True
print 'loading', os.path.basename(__file__)
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.simulation
import internal
reload(internal) # for development
......
......@@ -3,6 +3,12 @@ import os
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.common
import smtk.attribute
import smtk.io
# Add path to IBAMR-2d.py script
abs_path = os.path.abspath(__file__)
......@@ -96,11 +102,17 @@ if __name__ == '__main__':
# Initialize simuation attributes
simbuilder_resource = resource_set.get('simbuilder')
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
if 'shiboken' == smtk.wrappingProtocol():
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
else:
sim_atts = simbuilder_resource
print 'sim_atts', sim_atts
export_resource = resource_set.get('export')
export_atts = smtk.attribute.System.CastTo(export_resource)
if 'shiboken' == smtk.wrappingProtocol():
export_atts = smtk.attribute.System.CastTo(export_resource)
else:
export_atts = export_resource
print 'export_atts', export_atts
# Initialize export attributes
......
......@@ -14,6 +14,9 @@ print 'loading', os.path.basename(__file__)
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
from conditionset import ConditionSet
......@@ -159,8 +162,12 @@ class CardFormat:
else:
value = concrete_item.value(0)
# RefItem a special case
if isinstance(value, smtk.AttributePtr):
value = value.name()
if 'shiboken' == smtk.wrappingProtocol():
if isinstance(value, smtk.AttributePtr):
value = value.name()
else:
if isinstance(value, smtk.attribute.Attribute):
value = value.name()
self.write_value(out, value, keyword=keyword, tab=tab)
return self.finish_write(item)
......@@ -171,6 +178,7 @@ class CardFormat:
'''Writes value to output stream
'''
if keyword is None:
keyword = self.keyword
if tab is None:
......@@ -181,11 +189,12 @@ class CardFormat:
text_formatter = ' {:<%s} = {:}\n' % tab
if as_boolean:
value = 'TRUE' if value else 'FALSE'
elif quote_string and isinstance(value, str):
elif quote_string and isinstance(value, basestring):
value = '\"%s\"' % value
line = text_formatter.format(keyword, value)
out.write(line)
# ---------------------------------------------------------------------
def finish_write(self, item=None):
'''Internal method for common code after value written. Returns True
......
......@@ -14,7 +14,6 @@ import os
print 'loading', os.path.basename(__file__)
import sys
import smtk
# ---------------------------------------------------------------------
class OutputComponent:
......
......@@ -13,6 +13,9 @@ import os
print 'loading', os.path.basename(__file__)
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
from cardformat import CardFormat
from conditionset import ConditionSet
......
......@@ -14,6 +14,11 @@
import os
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import smtk.model
import smtk.simulation
# so devs don't complain about pyc files in source
sys.dont_write_bytecode = True
......@@ -581,7 +586,7 @@ def write_bcs(scope, att_type, function_name, variable_name=None, comment=None):
scope.logger.addWarning(msg)
print 'WARNING:', msg
continue
else:
else:
body_item = smtk.attribute.to_concrete(item)
if not body_item.isSet(0):
......
......@@ -17,6 +17,9 @@ print 'loading', os.path.basename(__file__)
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.simulation
import internal
from internal import writer
......@@ -367,7 +370,10 @@ def ExportCMB(spec):
project_path = None
item = export_spec_att.find('ProjectDir')
if item is not None:
dir_item = smtk.to_concrete(item)
if 'shiboken' == smtk.wrappingProtocol():
dir_item = smtk.to_concrete(item)
else:
dir_item = item
project_path = dir_item.value(0)
print 'project_path', project_path
......
......@@ -3,6 +3,12 @@ import os
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
import smtk.attribute
import smtk.model
import smtk.io
import smtk.bridge.exodus
print 'exodus', smtk.bridge.exodus
# Add path to Truchas.py script
abs_path = os.path.abspath(__file__)
......@@ -21,13 +27,15 @@ def load_smtk_model(model_manager, session_type, smtk_file):
Application should check validity
'''
print 'importing model file'
mgr = smtk.model.Manager.create()
sess = model_manager.createSession(session_type)
sess.assignDefaultName()
op = sess.op("import smtk model")
#print 'op', op
op.findFile("filename", smtk.attribute.ALL_CHILDREN).setValue(0, smtk_file)
if 'shiboken' == smtk.wrappingProtocol():
op.findFile("filename", smtk.attribute.ALL_CHILDREN).setValue(0, smtk_file)
else:
op.findFile('filename').setValue(smtk_file)
#print 'able to operate?', op.ableToOperate()
result = op.operate()
......@@ -129,14 +137,18 @@ if __name__ == '__main__':
# Initialize simuation attributes
simbuilder_resource = resource_set.get('simbuilder')
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
export_resource = resource_set.get('export')
if 'shiboken' == smtk.wrappingProtocol():
sim_atts = smtk.attribute.System.CastTo(simbuilder_resource)
export_atts = smtk.attribute.System.CastTo(export_resource)
else:
sim_atts = simbuilder_resource
export_atts = export_resource
#print 'sim_atts', sim_atts
#print 'export_atts', export_atts
sim_atts.setRefModelManager(model_manager)
export_resource = resource_set.get('export')
export_atts = smtk.attribute.System.CastTo(export_resource)
print 'export_atts', export_atts
# Initialize export attributes
export_spec_att = None
att_list = export_atts.findAttributes('ExportSpec')
......
......@@ -14,6 +14,9 @@ print 'loading', os.path.basename(__file__)
import sys
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
# ---------------------------------------------------------------------
class CardFormat:
......@@ -194,7 +197,7 @@ class CardFormat:
else:
value = concrete_item.value(0)
# RefItem a special case
if isinstance(value, smtk.AttributePtr):
if hasattr(smtk, 'AttributePtr') and isinstance(value, smtk.AttributePtr):
value = value.name()
if self.as_property:
......@@ -227,7 +230,7 @@ class CardFormat:
name_string = 'property_name(%d) = \"%s\",' % (index, self.keyword)
value_prefix = 'property_function' if is_expression else 'property_constant'
if isinstance(value, str):
if isinstance(value, basestring):
value = '\"%s\"' % value
predicate_string = ' %s(%d) = %s' % (value_prefix, index, value)
......@@ -271,7 +274,7 @@ class CardFormat:
return True
# Check single string, which is typical case
if isinstance(test_condition, str):
if isinstance(test_condition, basestring):
return test_condition in klass.Conditions
# Check if test_conditions are a subset of current conditions
......@@ -347,7 +350,7 @@ class CardFormat:
text_formatter = ' {:<%s} = {:}\n' % tab
if as_boolean:
value = '.true.' if value else '.false.'
elif quote_string and isinstance(value, str):
elif quote_string and isinstance(value, basestring):
value = '\"%s\"' % value
line = text_formatter.format(keyword, value)
out.write(line)
......@@ -13,7 +13,6 @@ import os
print 'loading', os.path.basename(__file__)
import sys
import smtk
from cardformat import CardFormat
......
......@@ -13,6 +13,10 @@ import os
print 'loading', os.path.basename(__file__)
import smtk
if 'pybind11' == smtk.wrappingProtocol():
#print 'Using pybind11 bindings'
import smtk.attribute
import smtk.model
from cardformat import CardFormat
# ---------------------------------------------------------------------
......@@ -345,7 +349,7 @@ class Writer:
subitem = active_item.item(0, i)
value_item = smtk.attribute.to_concrete(subitem)
value_list.append(value_item.value(0))
string_list = [str(x) for x in value_list]
string_value = ', '.join(string_list)
CardFormat.write_value(
......@@ -731,8 +735,8 @@ class Writer:
CardFormat.ModelManager = self.model_manager
# Get mesh file from model manager
model_ents = self.model_manager.entitiesMatchingFlags(
smtk.model.MODEL_ENTITY, True)
mask = int(smtk.model.MODEL_ENTITY)
model_ents = self.model_manager.entitiesMatchingFlags(mask, True)
#print 'model_ents', model_ents
if not model_ents:
msg = 'No model - export will be incomplete'
......
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