Skip to content

[FIX] load_results in nodes.py now uses node output directory as wd #2694

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

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
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
45 changes: 23 additions & 22 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,28 +559,29 @@ def _load_results(self):
result, aggregate, attribute_error = _load_resultfile(cwd, self.name)
# try aggregating first
if aggregate:
logger.debug('aggregating results')
if attribute_error:
old_inputs = loadpkl(op.join(cwd, '_inputs.pklz'))
self.inputs.trait_set(**old_inputs)
if not isinstance(self, MapNode):
self._copyfiles_to_wd(linksonly=True)
aggouts = self._interface.aggregate_outputs(
needed_outputs=self.needed_outputs)
runtime = Bunch(
cwd=cwd,
returncode=0,
environ=dict(os.environ),
hostname=socket.gethostname())
result = InterfaceResult(
interface=self._interface.__class__,
runtime=runtime,
inputs=self._interface.inputs.get_traitsfree(),
outputs=aggouts)
_save_resultfile(result, cwd, self.name)
else:
logger.debug('aggregating mapnode results')
result = self._run_interface()
with indirectory(cwd):
logger.debug('aggregating results')
if attribute_error:
old_inputs = loadpkl(op.join(cwd, '_inputs.pklz'))
self.inputs.trait_set(**old_inputs)
if not isinstance(self, MapNode):
self._copyfiles_to_wd(linksonly=True)
aggouts = self._interface.aggregate_outputs(
needed_outputs=self.needed_outputs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I think we want to try narrowing the "critical section" where we modify the working directory. I think it might actually just be here:

with indirectory(cwd):
    aggouts = self._interface.aggregate_outputs(
        needed_outputs=self.needed_outputs)

Almost all other function calls use the cwd directly.

By keeping it narrow, we effectively mark places where we're working-directory dependent, which may be useful in future refactors.

runtime = Bunch(
cwd=cwd,
returncode=0,
environ=dict(os.environ),
hostname=socket.gethostname())
result = InterfaceResult(
interface=self._interface.__class__,
runtime=runtime,
inputs=self._interface.inputs.get_traitsfree(),
outputs=aggouts)
_save_resultfile(result, cwd, self.name)
else:
logger.debug('aggregating mapnode results')
result = self._run_interface()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here's a potential other place we might want to wrap in indirectory(cwd). I would test without, first.

return result

def _run_command(self, execute, copyfiles=True):
Expand Down