Object Oriented Python API

Revision as of 18:47, 31 March 2011 by BradWhitlock (talk | contribs) (Ideas for an Object Oriented Python API)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Ideas for an Object Oriented Python API

There are two possible tracks to follow on the road to providing VisIt with a more object oriented python API:

  • Rewrite the guts of the Python API in an objected oriented manner.
  • Wrap the existing interface with a higher level objected oriented layer.

Backward compatibility with the existing API is an important requirement so the second approach is our current focus.


From a data analysis stand point the current state machine like api can be pretty painful - here are some requests for an OO-api:

If you have a handle to an object you should be able to modify it & call update without any worry of what state VisIt is currently in.

For example: You have create a plot and add an operator. You have a handle to an operator & you want to make a change to some op attribute, and export the resulting dataset over time.

#
# Imaginary Example Use Case:
#

db = Database("wave.visit")
pc = Plot(db,"Pseudocolor","v")
pc["centering"] = "nodal"

isov = pc.add_operator("Isovolume")
isov["variable"] = "v"
isov["min"] = .1

pc.update()

while db.has_next():
  ts = db.next()
  pc.export(file_name="wave.exp.%40d.vtk" % ts,vars=("v","u"),export_type="VTK")

These modifications may translate to a long list of actual visit operations, for example:

  • set the active window
  • set the active database
  • set the active plot
  • activate a particular operator
  • change the operator's attributes
  • set the operator's attributes.
  • export the plot

Proper bookkeeping to make this possible is going to be difficult.

Starting Point / Ideas for Useful Classes (loosely based on Cyrus attempt at wrapping for data analysis, with some new features):

#
# (note for the outline of classes, pseudo python is used)
#

class Database(object):
  # general setup
  def init(path,host)
  def open()
  def close()
  # time step info & control
  def timestep()
  def set_timestep()
  def num_timesteps()
  # iterator like interface
  def has_next()
  def next()
  def reset()
  # time and cycle info
  def cycle()
  def time()
  #meta data
  def vars()
  def meshes()

class Plot(object):
  # general setup & interaction
  def init(db,plot_type,var_name)
  def var()
  def set_var()
  def update()
  def hide()
  def show()
  def export(dir_name,file_name,vars,export_type)
  def materials()
  def select_materials(mats)
  # (or more general subsetting interface)
  # operator management
  def operators()
  def add_operator(op_inst)
  def remove_operator(op_inst)
  #proposed: interface change order of operators easily
  #proposed: access to plot attributes via get & set item (aka square brackets operator)

class Operator(object):
  # general setup
  def init(op_type)
  #proposed: access to operator attributes via get & set item (aka square brackets operator)
  def update()

class Window(object)
  def init(window_id)
  def render(output_name,options) # easy ability render a window
  def view() # some how sensibly manage the view properties ... 

class Engine(object):
  # general setup
  def init(host,visit_dir)
  def open(nprocs,partition,bank,wtime)
  def close()