Skip to content

[ENH] Improve reproducibility#342

Merged
AlexVCaron merged 17 commits intonf-neuro:mainfrom
arnaudbore:fix_threads_ants
Apr 9, 2026
Merged

[ENH] Improve reproducibility#342
AlexVCaron merged 17 commits intonf-neuro:mainfrom
arnaudbore:fix_threads_ants

Conversation

@arnaudbore
Copy link
Copy Markdown
Contributor

@arnaudbore arnaudbore commented Mar 31, 2026

Type of improvement

So far here are the automatic modifications:

  • if MRTRIX:
    export OMP_NUM_THREADS=${task.ext.single_thread ? 1 : task.cpus}
    export MRTRIX_RNG_SEED=${task.ext.mrtrix_rng_seed ? task.ext.mrtrix_rng_seed : "1234"}
  • if SCILPY:
    export OMP_NUM_THREADS=${task.ext.single_thread ? 1 : task.cpus}
  • if ANTS:
    export ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=${task.ext.single_thread ? 1 : task.cpus}
    export ANTS_RANDOM_SEED=${task.ext.ants_random_seed ?: "1234"}

I still need to check ressources for eddy/topup/fodf_msmt/noddi/freewater.

If submitting a new module or fixing a bug, please use the appropriate template.

  • Documentation
  • Development tools (e.g. linter, formatter, etc.)
  • Development container
  • Global update (please specify)
  • Other (please specify)

Describe your improvement

Write a clear and concise description of what the improvement is.

Describe how to test your improvement

Provide a full step-by-step guide to test your improvement.

Checklist before requesting a review

  • Ensure the syntax is correct (EditorConfig and Prettier must pass)
  • Run the test suites if your changes affect any module
  • Regenerate the Poetry lock file if you have updated the dependencies
  • Ensure the documentation is up-to-date

@arnaudbore arnaudbore requested a review from a team March 31, 2026 20:03
@gdevenyi
Copy link
Copy Markdown
Contributor

gdevenyi commented Apr 2, 2026

Here's claude's rundown of common thread environment varibales:
https://claude.ai/share/041b8d97-a7d5-4544-88b7-dc761565a1f2

@arnaudbore arnaudbore changed the title [WIP][ENH] Improve reproducibility [ENH] Improve reproducibility Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gdevenyi gdevenyi left a comment

Choose a reason for hiding this comment

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

Based on my reading here, I think:
OPENBLAS_NUM_THREADS=1 is needed anywhere scipy/numpy is used

TORCH_NUM_THREADS=1 is needed for tractoracle

This PR is really invasive, is it possible to set environment variables globally so we can more easily catch everything?

Copy link
Copy Markdown
Member

@gagnonanthony gagnonanthony left a comment

Choose a reason for hiding this comment

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

Great job! I noted the places where the seed arguments were not in the meta, otherwise minor comments here and there 😃

@AlexVCaron
Copy link
Copy Markdown
Contributor

Based on my reading here, I think: OPENBLAS_NUM_THREADS=1 is needed anywhere scipy/numpy is used

TORCH_NUM_THREADS=1 is needed for tractoracle

This PR is really invasive, is it possible to set environment variables globally so we can more easily catch everything?

Applying those globally would require a nextflow.config file. There you can define env (top scope, not in process) taken into account by all modules at runtime. The problem right now is this file needs to be define at the highest level (mostly pipeline), because no importing config from modules or subworkflows is not part of the pipeline template, nor automated by nf-core commands.

@gdevenyi
Copy link
Copy Markdown
Contributor

gdevenyi commented Apr 8, 2026

You're inconsistent here between ants_random_seed and ants_rng_seed, and even random_seed in registration/ants

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

Copy link
Copy Markdown
Member

@gagnonanthony gagnonanthony left a comment

Choose a reason for hiding this comment

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

LGTM! 💯

@AlexVCaron AlexVCaron added this pull request to the merge queue Apr 9, 2026
Merged via the queue into nf-neuro:main with commit 3b4ffbc Apr 9, 2026
146 checks passed
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.

5 participants