Skip to content

[FIX] Make ignore_exception a class attribute #2414

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

Merged
merged 3 commits into from
Jan 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions doc/users/saving_workflows.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,34 @@ This will create a file "outputtestsave.py" with the following content:
inode = Node(IdentityInterface(fields=['a'], mandatory_inputs=True), name="inode")
# Node: testsave.testfunc
testfunc = Node(Function(input_names=['a'], output_names=['output']), name="testfunc")
testfunc.interface.ignore_exception = False
def testfunc_1(in1):
"""dummy func
"""
out = in1 + 'foo' + "out1"
return out

testfunc.inputs.function_str = getsource(testfunc_1)
testfunc.inputs.ignore_exception = False
testfunc.inputs.in1 = '-sub'
testsave.connect(inode, "a", testfunc, "in1")
# Node: testsave.bet2
bet2 = MapNode(BET(), iterfield=['infile'], name="bet2")
bet2.interface.ignore_exception = False
bet2.iterables = ('frac', [0.4, 0.5])
bet2.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
bet2.inputs.ignore_exception = False
bet2.inputs.output_type = 'NIFTI_GZ'
bet2.terminal_output = 'stream'
# Node: testsave.bet
bet = Node(BET(), name="bet")
bet.interface.ignore_exception = False
bet.iterables = ('frac', [0.3, 0.4])
bet.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
bet.inputs.ignore_exception = False
bet.inputs.output_type = 'NIFTI_GZ'
bet.terminal_output = 'stream'
# Node: testsave.maths
maths = Node(ImageMaths(), name="maths")
maths.interface.ignore_exception = False
maths.inputs.environ = {'FSLOUTPUTTYPE': 'NIFTI_GZ'}
maths.inputs.ignore_exception = False
maths.inputs.output_type = 'NIFTI_GZ'
maths.terminal_output = 'stream'
testsave.connect(bet2, ('mask_file', func), maths, "in_file2")
Expand Down
7 changes: 4 additions & 3 deletions nipype/interfaces/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,14 @@ class BaseInterface(Interface):
references_ = []
resource_monitor = True # Enabled for this interface IFF enabled in the config

def __init__(self, from_file=None, resource_monitor=None, **inputs):
def __init__(self, from_file=None, resource_monitor=None,
ignore_exception=False, **inputs):
if not self.input_spec:
raise Exception(
'No input_spec in class: %s' % self.__class__.__name__)

self.inputs = self.input_spec(**inputs)
self.ignore_exception = ignore_exception

if resource_monitor is not None:
self.resource_monitor = resource_monitor
Expand Down Expand Up @@ -470,7 +472,6 @@ def run(self, cwd=None, **inputs):
os.chdir(cwd) # Change to the interface wd

enable_rm = config.resource_monitor and self.resource_monitor
force_raise = not getattr(self.inputs, 'ignore_exception', False)
self.inputs.trait_set(**inputs)
self._check_mandatory_inputs()
self._check_version_requirements(self.inputs)
Expand Down Expand Up @@ -530,7 +531,7 @@ def run(self, cwd=None, **inputs):
runtime.traceback_args = ('\n'.join(
['%s' % arg for arg in exc_args]), )

if force_raise:
if not self.ignore_exception:
raise
finally:
# This needs to be done always
Expand Down
4 changes: 2 additions & 2 deletions nipype/workflows/smri/ants/ANTSBuildTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def ANTSTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
output_names=['out']),
run_without_submitting=True,
name='MakeTransformsLists')
MakeTransformsLists.inputs.ignore_exception = True
MakeTransformsLists.interface.ignore_exception = True
TemplateBuildSingleIterationWF.connect(
BeginANTS, 'warp_transform', MakeTransformsLists, 'warpTransformList')
TemplateBuildSingleIterationWF.connect(BeginANTS, 'affine_transform',
Expand Down Expand Up @@ -263,7 +263,7 @@ def ANTSTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
output_names=['TransformListWithGradientWarps']),
run_without_submitting=True,
name='MakeTransformListWithGradientWarps')
ApplyInvAverageAndFourTimesGradientStepWarpImage.inputs.ignore_exception = True
ApplyInvAverageAndFourTimesGradientStepWarpImage.interface.ignore_exception = True

TemplateBuildSingleIterationWF.connect(
AvgAffineTransform, 'affine_transform',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def antsRegistrationTemplateBuildSingleIterationWF(iterationPhasePrefix=''):
output_names=['TransformListWithGradientWarps']),
run_without_submitting=True,
name='99_MakeTransformListWithGradientWarps')
ApplyInvAverageAndFourTimesGradientStepWarpImage.inputs.ignore_exception = True
ApplyInvAverageAndFourTimesGradientStepWarpImage.interface.ignore_exception = True

TemplateBuildSingleIterationWF.connect(
AvgAffineTransform, 'affine_transform',
Expand Down