Research:Salsa Python
From Astronomy Facility Wiki
Here is documentation for the python methods available in Salsa.
The purpose of these methods is to provide building blocks for any analysis you might want to do. Examples of how to build the tipsy 'boxstat' and 'profile' commands out of these methods are in the 'tipsy.py' file in the ResolutionServer directory.
Charm module
Methods of the "charm" module include:
loadSimulation(file) -- Load simulation data from file.
findAttributeMin(group, attribute) -- return position with a group of the minimum value of an attribute
getFamilies() -- return list of families
getAttributes(family) -- return list of attributes of a family
getGroups() -- return list of groups
getNumParticles(group, family) -- return number of particles of a family in a group.
getAttributeRange() -- return tuple of range of attributes.
getAttributeRangeGroup -- return range of attribute with a group
getAttributeSum(group, attribute) -- return sum within a group of an attribute
getDimensions(family, attribute) -- return dimension (1 or 3) of an attribute.
saveSimulation --
getDataType(family, attribute) -- return data type of attribute as an integer code.
getCenterOfMass(group) -- return center of mass of the group.
createScalarAttribute(family, attribute) -- create a new scalar attribute in a family
createVectorAttribute(family, attribute) -- create a new vector attribute in a family
createGroup_Family(group, parentgroup, family) -- create group using just one family of parent group.
createGroup_AttributeRange(group, parentgroup, attribute, min, max) -- create group out of parentgroup using only particles whose attribute is between min and max.
createGroupAttributeSphere(group, parentgroup, attribute, centerx, centery, centerz, size) -- create group out of parentgroup using only particles whose attribute is within "size" of "center".
createGroupAttributeBox(group, parentgroup, attribute, cornerx, cornery, cornerz, edge1dx, edge1dy, edge1dz, edge2dx, edge2dy, edge2dz, edge3dx, edge3dy, edge3dz) -- create group out of parent group using only particles whose attribute falls in the box defined by the corner and three edges.
runLocalParticleCode(code) -- Run python in string "code" over all particles.
runLocalParticleCodeGroup(group, code, object) -- Run python in string code over all particles in group. Extra parameters can be passed in the object argument.
reduceParticle(group, mapcode, reducecode, object) -- Perform a "map reduce" over all particles in group. Mapcode contains python code to "map" a particle to a tuple, the first item of which is a key. Reducecode is python code to take a list of tuples with the same key, and "reduce" them to a single tuple.
importData(family, attribute, list) -- import data from a python list and assign it to the attribute of a family.
Ck module
The ck module has methods for more basic charm routines:
printstr(str) -- print a string on the server
printclient(str) -- print a string on the client
mype() -- return an integer for MyPe()
numpes() -- return an integer for NumPes()
myindex() -- return a tuple containing the array index (valid only for arrays)
read(where) -- read a value on the chare (uses the "read" method of the chare)
write(where, what) -- write a value back on the chare (uses the "write" method of the chare)
Creating new charm methods
See the python section of the CHARM++ manual for a complete description of how the python scripting works.
The procedure for adding a new method to the ResolutionServer is
- Add an entry to the mainchare structure in ResolutionServer.ci of the form
entry [python "short documentation"] void newMethod(int handle);
- Add a similar declaration to the Main class in ResolutionServer.h
- Define the method in HighLevelPython.cpp. Use
PyArg_ParseTuple()to parse
the arguments, and pythonReturn() to pass back any results. See the
Python/C API documentation for details.
For non-parallel work, you can get at the Worker class on processor 0 with
the declaration
Worker* w = this->workers[0].ckLocal();
For parallel work, separate "entry methods" will have to be declared in the Worker array in ResolutionServer.ci, declared in the Worker class and defined in Worker.cpp. Browse through the CHARM++ manual before doing too much here.
