Skip to content
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

FIX: Resolving/rebasing paths from/to results files #2971

Merged
merged 9 commits into from
Aug 7, 2019

Conversation

oesteban
Copy link
Contributor

@oesteban oesteban commented Jul 19, 2019

Based on functionalities added in #2970.

Summary

Searches for paths in outputs of the result object to resolve/rebase them when loading/saving the pickle.

Includes a minor variation of the test @effigies proposed.

Fixes #2944 .

Side effects

#2944 and posterior efforts to address it uncovered a couple of problems we may want to address some time (from #2970 (comment)):

  1. Whether we want to simplify/refactor the implementation of hash_files (ENH: Add resolve/rebase BasePath traits methods & tests #2970 (comment)): this PR is a drop-in replacement of traits that should allow FIX: Resolving/rebasing paths from/to results files #2971 to remain strictly scoped into reading/writing of results files (i.e., no need to rework hash_files).
  2. Whether we want to implement the config use_relative_paths, which I think fully pertains to the Interface level (i.e., it would be independent of the internal format of results files).

Acknowledgment

  • (Mandatory) I acknowledge that this contribution will be available under the Apache 2 license.

@codecov-io
Copy link

codecov-io commented Jul 19, 2019

Codecov Report

Merging #2971 into master will decrease coverage by 3.32%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2971      +/-   ##
==========================================
- Coverage   67.59%   64.27%   -3.33%     
==========================================
  Files         344      342       -2     
  Lines       43796    43780      -16     
  Branches     5476     5482       +6     
==========================================
- Hits        29606    28140    -1466     
- Misses      13473    14551    +1078     
- Partials      717     1089     +372
Flag Coverage Δ
#smoketests ?
#unittests 64.27% <88.88%> (-0.77%) ⬇️
Impacted Files Coverage Δ
nipype/interfaces/base/traits_extension.py 89.52% <0%> (-5.24%) ⬇️
nipype/pipeline/engine/nodes.py 77.31% <100%> (-6.79%) ⬇️
nipype/pipeline/engine/utils.py 70.94% <90.38%> (-9.2%) ⬇️
nipype/interfaces/nilearn.py 40% <0%> (-56.67%) ⬇️
nipype/utils/spm_docs.py 25.92% <0%> (-44.45%) ⬇️
nipype/interfaces/freesurfer/base.py 50% <0%> (-30.51%) ⬇️
nipype/utils/logger.py 59.7% <0%> (-29.86%) ⬇️
nipype/algorithms/rapidart.py 35% <0%> (-29.42%) ⬇️
nipype/interfaces/spm/base.py 57.94% <0%> (-29.14%) ⬇️
nipype/utils/provenance.py 55.73% <0%> (-28.35%) ⬇️
... and 43 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 01a2772...6dee607. Read the comment docs.

@oesteban oesteban force-pushed the fix/2944-3 branch 2 times, most recently from bf4cc49 to 682c73c Compare July 31, 2019 22:14
@oesteban oesteban force-pushed the fix/2944-3 branch 2 times, most recently from 4d13d18 to cb0892b Compare August 1, 2019 16:29
oesteban added a commit to oesteban/nipype that referenced this pull request Aug 1, 2019
It seems that nipy#2944 has uncovered a rats-nest hidden in the engine. In
resolving that issue, I found out that a great deal of boilerplate was
set in place when loading/saving results to deal with
``OutputMulti{Object,Path}`` traits. The reason being that these traits
flatten single-element-list values.

This PR fixes the pickling behavior of traited specs containing these
types of traits.

Additionally, this PR also avoids the ``modify_paths`` function that was
causing problems originally in nipy#2944. Therefore, this PR effectively
make results files static, meaning: caching if the ``base_dir`` of the
workflow is changed will not work anymore.

I plan to re-insert this feature (results file mobility) with nipy#2971.
This PR is just to split that one in more digestible bits.

All the boilerplate mentioned above has been cleaned up.
@oesteban
Copy link
Contributor Author

oesteban commented Aug 1, 2019

This contains the test from and closes #2949

@oesteban
Copy link
Contributor Author

oesteban commented Aug 2, 2019

This feels ready to merge. The diff will be easier after #2985 is merged. Hopefully, this ends my burst of refactors. Thanks for your patience!

@@ -1260,7 +1260,7 @@ def _run_interface(self, execute=True, updatehash=False):
stop_first=str2bool(
self.config['execution']['stop_on_first_crash'])))
# And store results
_save_resultfile(result, cwd, self.name)
_save_resultfile(result, cwd, self.name, rebase=False)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be self.config.getboolean('execution', 'use_relative_paths')?

Suggested change
_save_resultfile(result, cwd, self.name, rebase=False)
_save_resultfile(result, cwd, self.name,
rebase=self.config.getboolean('execution', 'use_relative_paths'))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the discussion point 2 I wanted to bring up atop. On the one hand, should we expose the inner workings of the engine - after all, adding that here does not change anything to the user (just that they won't be able to move the work directory anymore).

On the other hand, for this to be completely consistent across the node implementation, we need to also rebase/resolve the inputs pickle (actually I'll open an issue because this should be addressed).

I'm under the impression that use_relative_paths could be useful for the user at the interface level, forcing interfaces to return relative paths if desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@satra can you share your views as regards use_relative_paths

@effigies WDYT about not exposing the inner workings (paths) of the results file to the users?

Copy link
Member

Choose a reason for hiding this comment

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

My overall perspective is "Let's not change the API if we don't absolutely have to to fix the bug." Which includes config file options.

I may not be understanding your position though, so we might be talking past each other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, from that standpoint:

use_relative_paths
Should the paths stored in results (and used to look for inputs) be relative or absolute. Relative paths allow moving the whole working directory around but may cause problems with symlinks. (possible values: true and false; default value: false)

The option is clearly defined specifically for the results file. Under that perspective, yes, any rebasing should be done only if use_relative_paths is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But actually not at the point you suggested, because that one happens at MapNode aggregation.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, okay. Sorry, my attention is split a lot of ways right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, however, we may want to add parameterized tests with use_relative_paths on and off.

@oesteban
Copy link
Contributor Author

oesteban commented Aug 7, 2019

@satra @mgxd @djarecka any voices against merging this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workflow crashing with file not found due to strange nipype.pipeline.engine.utils.modify_path behavior
4 participants