New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New version of the vtk package #998
Conversation
Still very much in progress, main work is on improving the port specs and specifying them explicitly. vtk_classes.py is huge due to docstrings and tons of classes. A simple head example works!
I did a very quick toy example: https://gist.github.com/remram44/f85405f6473a326ad4a3 A priori, loading Python code is way slower (0.07s) than JSON+dynamic creation (0.03s), although loading compiled bytecode (.pyc) is faster (0.02s). But all this is very comparable, so insertion into the registry will probably be the bottleneck. |
Cool, so dynamic creation should not be a problem. The intermediate format is currently xml. We could use either json, xml, or python classes as a final representation. @dakoop worries about readability when debugging, so this will be a tradeoff between parsing speed and readability. Maybe some well-structured json would not be too bad? If we keep the python classes where should it be stored? It will be generated the first time the package is loaded and when the vtk version changes? Adding @dakoop's previous comments: |
@dakoop are you suggesting a common XML(or json?) for all wrappers where there is a core that specifies e.g. name/function/inputs/outputs and an extension section that specifies things like alternatePortSpecs? Extensions could be passed to the registry but is it not easier to add it to the dynamically created module? Is that what you mean by the XML mirroring the registry specifications? For patching, does this mean adding/removing/changing/correcting things in the intermediate representation using different patterns? This should be easy to code by hand but we could have methods for doing common tasks? |
@rexissimus, if we have a standard intermediate representation (json/xml), my argument is that it should mirror the registry schema (which defines db classes for packages, module descriptors, and port specs). The matplotlib xml representation differs from the registry schema because it contains items that affect the automated compute method construction as well as the structure of the package. Such items are useful for patching as well; it is much easier for me to create an alternatePortSpec than to make manual changes to both the module inputs/outputs and compute method. Note the matplotlib package requires compute methods that are not simple maps from input ports -> input parameters and output values -> output ports. Thus, for that package (and perhaps others), I would need extensions to the proposed intermediate representation that would allow rules that impact both the specification and the compute method. Or, I could use a secondary intermediate specification where those edits could be made and the compute methods updated. In either case, we need some way to specify what the compute method should look like in the intermediate representation. The compute methods can be specified by recipes that are templates (perhaps mako which I've used elsewhere in the code). |
With dynamic wrapping you can still do that. The compute method would be shared, like gen_module_ufunc. The alternatePortSpec would be stored as an extension and used for both specification and as input to the compute method when the module is dynamically created. I just don't see the advantages of your way? |
@rexissimus, I am missing something---is there a proposed architecture that should be linked to this PR? Could you clarify what "my way" is; is this the matplotlib/vtk wrapping method? I am fine building off of the VTTools or other infrastructure, and the main concern I have with dynamic generation is debugging. I also want to make sure that whatever is adopted is general enough to work for something like the matplotlib wrapping. Some questions:
|
I meant the way you want to make the intermediate representation similar to the registry schema. I am trying to understand how that would work.
|
Conflicts: vistrails/packages/vtk/identifiers.py vistrails/packages/vtk/init.py vistrails/packages/vtk/tf_widget.py vistrails/packages/vtk/vtkcell.py
Ok, I think I see your point now after working with the code. The intermediate representation should mirror the registry so that it is easy to see what the final module will look like. Patching will affect both the specification and the shape of the final compute method that would have to be specified by some kind of extension. |
@dakoop I would also point out I have been thinking about how to coerce matplotlib to fit in better with a the functional nature of VT (which involves an |
Modules are now loaded directly from vtk/vtk.xml The package loads but some patterns are not working yet
* VTK classes are dynamically wrapped as python functions that are independent of vistrails ** Function output can be single, list, or dict ** spec describes how to wrap function into a vistrails module ** module wrapper can be used with any python function ** Exporting to script could convert modules into the wrapped functions.
TODO: * Auto-generate xml and store somewhere * Inspectors * Make VTKCell optional * Upgrades VTK classes are wrapped into functions that have some magic attributes: * _callback(float) - used to report progress to logger * _tempfile - function for creating tempfile (for using FilePool) * _outputs - list of connected output ports for optional output generation
This is needed to make sure data files are parsed correctly on non-C locales.
VTK is wrapped using a spec describing how to transform a vtk class into a vistrails module New Class wrapper handles VTK style Set/Get classes where class instanciation takes no arguments * All VTK examples works * TODO: Refactor general classes to vistrails core generate/parse.py: Removed arg usage generate/specs.py: New specs for python classes and python functions init.py: New Class wrapper inspectors.py: Fixed missing attribute vtk_classes.py: Port logic moved to class wrapper deleted: base_module.py generate/vtk.xml generate/vtk_raw.xml
core\wrapper - contains code for executing wrapped objects package\vtk\vtk_wrapper - a vtk class wrapper independent of vistrails new: common.py - common functionality for wrapper types new: core/wrapper/pythonclass.py: code for executing a python class new: core/wrapper/pythonfunction.py: code for executing a python function renamed: generate/specs.py -> ../../core/wrapper/specs.py new: vtk_wrapper/specs.py: Placeholder for core/wrapper/specs.py renamed: generate/class_tree.py -> vtk_wrapper/class_tree.py renamed: fix_classes.py -> vtk_wrapper/fix_classes.py renamed: generate/parse.py -> vtk_wrapper/parse.py renamed: vtk_classes.py -> vtk_wrapper/vtk_classes.py renamed: generate/vtk_module.py -> vtk_wrapper/vtk_module.py renamed: generate/vtk_parser.py -> vtk_wrapper/vtk_parser.py moved: vtk -> vtk_wrapper/wrapper.py deleted: class_tree.py deleted: generate/generate.py deleted: generate/mixins.py deleted: generate/vtk_template.py.mako deleted: vtk_parser.py
All vtk examples works! Fixed vtkPLOT3DReader upgrade to MultiBlockPLOT3DReader Using custom output port StructuredGrid to get normal output Added SetInputData-style support TODO: Make sure files can be opened on both VTK5 and VTK6 by using Set*Data on VTK6 and Set* on VTK5 init.py vtk_wrapper/parse.py vtk_wrapper/vtk_classes.py
.vt files should now work on both VTK5 and VTK6. The new VTK6 SetInputData-style names are always used now. TODO: This needs more testing
All vtk_examples now work on both VTK5 and VTK6 init.py: Added more upgrades for Set and overloads vtk_wrapper/parse.py: Removed more Set prefixes Fixed VTK5 name upgrades vtk_wrapper/vtk_classes.py: Fixed comment
Conflicts: vistrails/packages/vtk/base_module.py vistrails/packages/vtk/init.py vistrails/packages/vtk/vtk_wrapper/vtk_parser.py vistrails/packages/vtk/vtkviewcell.py
Conflicts: vistrails/packages/vtk/base_module.py
This is for including it without exposing the wrapper api
New vtk package with the wrapping code bundled
This is finished, but could use some more testing.
.vistrails
folder asvtk-spec-VERSION.xml
.SetInputData
) are used even on VTK5.VTKCell
is now used in place ofVTKViewCell
(fixes Remove vtkviewcell #1019).vtkMultiBlockPlot3Dreader
replacesvtkPLOT3DReader
.