refactor: Move PVMergeBlocksEnhanced plugin and create the VTK filter#129
Conversation
jafranc
left a comment
There was a problem hiding this comment.
IMO it may help to raise error and keep the old semantics of mergeBlocks() other than that 👍
| ) | ||
|
|
||
| from geos.utils.Logger import ( getLogger, Logger, logging, CountWarningHandler ) | ||
| from geos.utils.Logger import getLogger, Logger, CountWarningHandler |
There was a problem hiding this comment.
Let's keep parenthesis when doing multiple import other than standard
| from geos.utils.Logger import getLogger, Logger, CountWarningHandler | |
| from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler ) |
| vtkUnstructuredGrid ) | ||
| from vtkmodules.vtkFiltersCore import vtkAppendDataSets | ||
| from geos.mesh.utils.arrayModifiers import fillAllPartialAttributes | ||
| from geos.utils.Logger import getLogger, Logger |
There was a problem hiding this comment.
| from geos.utils.Logger import getLogger, Logger | |
| from geos.utils.Logger import ( getLogger, Logger ) |
| meshMerged: vtkUnstructuredGrid | ||
| if isinstance( mesh, vtkMultiBlockDataSet ): | ||
| _, meshMerged = mergeBlocks( mesh ) | ||
| else: | ||
| meshMerged = mesh |
There was a problem hiding this comment.
wouldn't it be simpler if the behavior of mergeBlocks(mesh) returned mesh if not a vtkMultiBlockDataSet with warning ?
|
|
||
| # merge blocks | ||
| return mergeBlocks( compositeBlock ) | ||
| _, mergedBlocks = mergeBlocks( compositeBlock ) |
There was a problem hiding this comment.
| _, mergedBlocks = mergeBlocks( compositeBlock ) | |
| mergedBlocks = vtkUnstructuredGrid() | |
| _, mergedBlocks = mergeBlocks( compositeBlock ) |
There was a problem hiding this comment.
would help typecheck (maybe)
| @@ -196,7 +196,7 @@ def RequestData( | |||
| if isinstance( serverMesh, vtkUnstructuredGrid ): | |||
There was a problem hiding this comment.
Maybe it would be easier to return the merged mesh if composite or multiblock, the unstructured grid input if unstructured and raise an error if other case occur that you could catch here
| if not inputMesh.IsA( "vtkMultiBlockDataSet" ) and not inputMesh.IsA( "vtkCompositeDataSet" ): | ||
| logger.error( | ||
| "The input mesh should be either a vtkMultiBlockDataSet or a vtkCompositeDataSet. Cannot proceed with the block merge." | ||
| ) | ||
| return False, outputMesh | ||
|
|
||
| # Fill the partial attributes with default values to keep them during the merge. | ||
| if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ): | ||
| logger.error( "Failed to fill partial attributes. Cannot proceed with the block merge." ) | ||
| return False, outputMesh | ||
|
|
||
| af: vtkAppendDataSets = vtkAppendDataSets() |
There was a problem hiding this comment.
Maybe raise a user define error there to avoid the Tuple return
There was a problem hiding this comment.
I agree with @jafranc here, this function should only return a vtkUnstructuredGrid and raise errors when failure.
alexbenedicto
left a comment
There was a problem hiding this comment.
As suggested by @jafranc , the mergeBlocks function needs to be reworked to raise errors which will require error handling in all the scripts using it
| if not inputMesh.IsA( "vtkMultiBlockDataSet" ) and not inputMesh.IsA( "vtkCompositeDataSet" ): | ||
| logger.error( | ||
| "The input mesh should be either a vtkMultiBlockDataSet or a vtkCompositeDataSet. Cannot proceed with the block merge." | ||
| ) | ||
| return False, outputMesh | ||
|
|
||
| # Fill the partial attributes with default values to keep them during the merge. | ||
| if keepPartialAttributes and not fillAllPartialAttributes( inputMesh, logger ): | ||
| logger.error( "Failed to fill partial attributes. Cannot proceed with the block merge." ) | ||
| return False, outputMesh | ||
|
|
||
| af: vtkAppendDataSets = vtkAppendDataSets() |
There was a problem hiding this comment.
I agree with @jafranc here, this function should only return a vtkUnstructuredGrid and raise errors when failure.
|
|
||
| success: bool | ||
| outputMesh: vtkUnstructuredGrid | ||
| success, outputMesh = mergeBlocks( self.inputMesh, True, self.logger ) |
There was a problem hiding this comment.
Following the comments made on mergeBlocks function, a try/except block can be used here to evaluate the success of the mergeBlocks function
jafranc
left a comment
There was a problem hiding this comment.
I think is we want to properly propagate the error, we should raise it where it happens mergeBlock and deal with it where it makes most sense and where it can either be recovered from or end cleanly.
In most cases I think it is in the PV plugins, and if used outside of it, we should document the errors raised.
I'll push a commit with a proposal for this case
jafranc
left a comment
There was a problem hiding this comment.
These last 4-5 commits are proposal on how to handle errors.
As we are dealing with vtkLogger error that are rather registering callbacks than using handlers, there is quite a workaround throwing everything into a buffer to throw on match (here with vtkExecutive ) but could/should be improved.
This is open to comments and rewrite/extension/removal.
I also create an specific VTKError class that is the first of specific PVPluginError (hopefully) if go this path and chose to raise errors rather deep and catch them in RequestData() or other high level.
…https://github.com/GEOS-DEV/geosPythonPackages into pmartinez/refactor/createMergeBlockEnhancedVTKFilter
|
I created a child logger inside the |
alexbenedicto
left a comment
There was a problem hiding this comment.
Tested the last version with the child logger, works great.
| filter: vtkMergeBlocks = vtkMergeBlocks() | ||
| filter.SetInputData( inputMesh ) | ||
| filter.Update() |
There was a problem hiding this comment.
Genuinely asking, should we also call the VTKCaptureLog here because we are using the vtkMergeBlocks like done in the else block ?
with VTKCaptureLog() as captured_log:
filter: vtkMergeBlocks = vtkMergeBlocks()
filter.SetInputData( inputMesh )
filter.Update()
captured_log.seek( 0 )
captured = captured_log.read().decode()
logger.debug( captured.strip() )
And in a more general view, should we use the VTKCaptureLog anytime we use a vtk filter ?
There was a problem hiding this comment.
There is a short and a long answer, but IMO yes.
I will incorporate it in #144 and I think from there we can decide if we want to inc. it everywhere.
jafranc
left a comment
There was a problem hiding this comment.
Great ! Great starting point for Error propagation and handling 👍
Closes #92