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

ENH: Side-track *sMRIPrep* if a path of anatomical derivatives is given #2036

Merged
merged 16 commits into from
Apr 28, 2020

Conversation

oesteban
Copy link
Member

Summary

This PR utilizes nipreps/smriprep#107 to allow a fast skip of the
anatomical workflow evaluation, and the need of maintaining the work
directory for it.

Closes #1175

Changes proposed in this pull request

Potential problems

This PR does not contain any measures to preserve the reproducibility of
fMRIPrep if the fast-track is used.

@auto-comment
Copy link

auto-comment bot commented Mar 14, 2020

Thank your for raising your pull request.

Some of the fMRIPRep maintainers will review your changes as soon as time permits.
I'm attaching below a Review Checklist for the reviewers, to check off during the
review.

PR Review

Please check off boxes as applicable, and elaborate in comments below. Your review is not limited to these topics, as described in the reviewer guide

  • As the reviewer I confirm that there are no conflicts of interest for me to review this work.

Please check what applies in the following aspects of the PR:

Code documentation

  • New functions and modules are documented following the guidelines.
  • Existing code required amendments in documentation and has been updated.
  • Sufficient inline comments ensure readability by other contributors in the long term.

Documentation site

  • The modifications to fMRIPrep in this PR do not require extra documentation. This is a common situation when a bug fix that does not change the code base substantially is submitted.
  • This PR requires documentation. The corresponding documentation will be submitted as an additional PR in the future.
  • This PR requires extra documentation, and will be included within this PR. Please check the boxes that apply best:
    • An existing feature is substantially modified, changing the interface and/or logic of a module.
    • A new feature is being added, therefore full documentation of it will be included
    • This PR addresses an error in existing documentation.
  • Yes, all expected sections of documentation were generated by the CI build, and look as expected

Tests

  • The new functionalities in this PR are covered by the existing tests
  • New test batteries have been included with this PR

Data

  • This PR does not require any additional data to be uploaded to OSF.
  • This PR requires additional data for tests.

Dependencies: smriprep

  • This PR does not require any update on smriprep; or
  • smriprep has correctly been pinned.

Dependencies: niworkflows

  • This PR does not require any update on niworkflows; or
  • niworkflows has correctly been pinned.

Dependencies: sdcflows

  • This PR does not require any update on sdcflows; or
  • sdcflows has correctly been pinned.

Dependencies: Nipype

  • This PR does not require any update on nipype; or
  • nipype has correctly been pinned.

Dependencies: other

  • This PR does not require any update on other dependencies; or
  • other dependencies have correctly been pinned.

Reports generated within CI tests

  • Yes, I have checked the reports of ds005 and they are not modified or the changes are as expected
  • Yes, I have checked the reports of ds054 and they are not modified or the changes are as expected
  • Yes, I have checked the reports of ds010 and they are not modified or the changes are as expected

@oesteban
Copy link
Member Author

I'm hitting this #2041 because sMRIPrep stores the fsnative-to-T1w (and inverse) matrices in ITK format to the output folder, but fMRIPrep expects them to be LTA for LTA concatenation (with the bbregister's LTA).

I think this is the best reason to push nitransforms forward (and actually the reason why we started with it at all originally). It should be capable of:

  • Replacing the LTA -> ITK conversions currently done with Freesurfer tools (sMRIPrep)
  • Replacing the LTA -> FSL -> ITK conversions with FreeSurfer and C3D (fMRIPrep)
  • Replacing all LTA concatenations and storing ITK concatenated (or lists, if we want to keep full provenance and full floating-point accuracy) transforms (both sMRIPrep and fMRIPrep).

Preparing nitransforms for this (generating a package, fixing nipy/nitransforms#64) will require a fair amount of work.

WDYT? - should we try to get over with this asap, or find a workaround (i.e., convert back to LTA with FS tools) and finalize later?

@oesteban oesteban modified the milestones: 20.1.x, 20.1.0 LTS Mar 25, 2020
@oesteban oesteban force-pushed the enh/1175-smriprep-fasttrack branch 2 times, most recently from c1736b7 to 8dfc8e9 Compare March 30, 2020 03:11
@oesteban
Copy link
Member Author

Unless I'm missing something, this report shows results using NiTransforms instead of mri_concatenate_lta, LTA convert and c3d (for LTA -> FSL -> ITK). I'll check in more depth tomorrow, but they look good at first glance.

The final step is to alter the smoke tests to use the new flag (and the proposed feature). It's working locally on ds005, though.

Before that final step, it might be appropriate to have a first review here (cc/ @mgxd, @effigies).

@oesteban oesteban changed the title ENH/WIP: Side-track *sMRIPrep* if a path of anatomical derivatives is given ENH: Side-track *sMRIPrep* if a path of anatomical derivatives is given Mar 30, 2020
@oesteban oesteban marked this pull request as ready for review April 2, 2020 18:46
@oesteban
Copy link
Member Author

oesteban commented Apr 2, 2020

@effigies, @mgxd this seems to be settling in. Let's see the latest CircleCI workflow. If that comes out green, I'll add the fasttrack to ds054 and ds210.

I think it's about time to finalize nipreps/smriprep#107 and get that one merged - WDYT?

Another thought is that this particular feature will make it easier to quickly tests out things on other extensions (i.e., infants). If we are given a dataset with all the anatomical derivatives we need, we can work right away on the adaptations to the functional workflow (hopefully just the sampling of CIFTI2 files) without being held up by anatomical issues.

@oesteban oesteban force-pushed the enh/1175-smriprep-fasttrack branch from 8b03e9f to 687df86 Compare April 3, 2020 08:01
@oesteban
Copy link
Member Author

oesteban commented Apr 4, 2020

Okay, the --no-fs-reconall jobs are not properly working on Circle. I believe the ordering of the segments of the segmentation is not correct. Will look into this asap

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

I don't think I finished reviewing but I won't get back to this before the afternoon, so might as well hit submit.

wrapper/fmriprep_docker.py Show resolved Hide resolved
@@ -113,7 +112,8 @@ def select_target(subject_id, space):
mem_gb=DEFAULT_MEMORY_MIN_GB)
resampling_xfm = pe.Node(LTAConvert(in_lta='identity.nofile', out_lta=True),
name='resampling_xfm')
set_xfm_source = pe.Node(ConcatenateLTA(out_type='RAS2RAS'), name='set_xfm_source')
merge_xfm = pe.Node(niu.Merge(2), name="merge_xfm", run_without_submitting=True)
concat_xfm = pe.Node(ConcatenateXFMs(out_fmt="fs"), name="concat_xfm")
Copy link
Member

Choose a reason for hiding this comment

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

Does ConcatenateXFMs with out_fmt=='fs' ensure that no line exceeds 255 characters?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's left empty because the filename = metadata is not set. But there's no failsafe for that in nitransforms right now, so one could think of setting it and getting bitten by this.

docs/faq.rst Outdated Show resolved Hide resolved
docs/faq.rst Outdated Show resolved Hide resolved
fmriprep/cli/parser.py Outdated Show resolved Hide resolved
@oesteban oesteban force-pushed the enh/1175-smriprep-fasttrack branch from f84ef4c to 0ab1a70 Compare April 17, 2020 00:53
… given

Summary
-------
This PR utilizes nipreps/smriprep#107 to allow a fast skip of the
anatomical workflow evaluation, and the need of maintaining the work
directory for it.

Closes nipreps#1175

Changes suggested
-----------------

  * [x] Added an ``--anat-derivatives`` flag to the command line.
  * [x] Integrated the new flag with the new config module.
  * [x] Estimate existing derivatives using *sMRIPrep*'s tooling.
  * [x] Pass in the existing derivatives and nipreps/smriprep#107
    skips the anatomical workflow fulfilling the workflow API.

Potential problems
------------------
This PR does not contain any measures to preserve the reproducibility of
*fMRIPrep* if the fast-track is used.
Also, update sdcflows, nitransforms pinned versions
@oesteban oesteban force-pushed the enh/1175-smriprep-fasttrack branch from 0ab1a70 to 7a5ebe7 Compare April 17, 2020 07:45
@oesteban oesteban force-pushed the enh/1175-smriprep-fasttrack branch from 7a5ebe7 to 08c4a29 Compare April 17, 2020 07:49
@oesteban oesteban marked this pull request as draft April 17, 2020 17:10
@oesteban oesteban marked this pull request as ready for review April 18, 2020 03:53
Copy link
Member Author

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

I think this is in a mergeable state now. Considering to set a merge freeze and get it in at last. LMKWYT

@@ -271,3 +266,22 @@ Therefore, if your *fMRIPrep* process crashes and you attempt to re-run it reusi
as much as it could from the previous run, you can either make sure that
the default ``$PWD/work/`` points to a reasonable, reusable path in your environment or
configure a better location on your with ``-w <PATH>``.

Can I use *fMRIPrep* for longitudinal studies?
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really know why I added this. If you feel this is worth splitting out to another PR, happy to do it.

mem_gb=mem_gb['resampled'],
name='bold_reg_wf',
omp_nthreads=omp_nthreads,
sloppy=config.execution.debug,
Copy link
Member Author

Choose a reason for hiding this comment

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

Added this sloppy mode argument downstream.

Comment on lines +686 to +694
if sloppy is True:
downsample = pe.Node(niu.Function(
function=_conditional_downsampling, output_names=["out_file", "out_mask"]),
name='downsample')
workflow.connect([
(inputnode, downsample, [("t1w_brain", "in_file")]),
(wm_mask, downsample, [("out", "in_mask")]),
(downsample, flt_bbr, [('out_file', 'reference'),
('out_mask', 'wm_seg')]),
Copy link
Member Author

Choose a reason for hiding this comment

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

With the utilization of cached, high-resolution anatomical derivatives, the time it took for flirt/bbr to run exploded. With this patch, I minimized flirt/bbr from ~5min to ~11sec (on my desktop, it must be a bit longer on CircleCI). Some other nodes have extended their duration a bit as when used pre-computed anatomical derivatives, but I think now the timing is reasonable.

I used this simple script: https://gist.github.com/oesteban/0c17459936deb18ac81377db4b4763c2 to measure times. We should consider running something like that in fmriprep to get some stats about execution etc.

numpy
pandas
psutil >= 5.4
pybids >= 0.10.0
pybids >= 0.10.2
Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary (uses build_path)

@oesteban
Copy link
Member Author

@effigies, @mgxd can you find some time window to take a second pass on this? Let's try to get it merged before Friday - WDYT?

@effigies
Copy link
Member

Yup. Will have a look this afternoon.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

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

Mostly rewording documentation. One question about a potential qform/sform footgun.

docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
docs/usage.rst Outdated Show resolved Hide resolved
fmriprep/workflows/bold/registration.py Show resolved Hide resolved
Co-Authored-By: Chris Markiewicz <effigies@gmail.com>
Copy link
Collaborator

@mgxd mgxd left a comment

Choose a reason for hiding this comment

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

minor comments, LGTM

docs/usage.rst Outdated Show resolved Hide resolved
@@ -25,14 +26,15 @@ install_requires =
nibabel ~= 3.0
nipype ~= 1.4
nitime
nitransforms >= 20.0.0rc3,<20.2
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we pin this to master as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

we'll need to set a release pin to cut the RC, so I'd leave this. 20.2 should be tolerant enough to allow nitransforms progress without breaking anything used in here.

wrapper/fmriprep_docker.py Outdated Show resolved Hide resolved
Co-Authored-By: Mathias Goncalves <goncalves.mathias@gmail.com>
@oesteban
Copy link
Member Author

brace yourselves

@oesteban oesteban merged commit 9509b31 into nipreps:master Apr 28, 2020
@oesteban oesteban deleted the enh/1175-smriprep-fasttrack branch April 28, 2020 00:20
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.

Support independent jobs across sessions
3 participants