Skip to content

Commit

Permalink
Runner refac
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Jan 29, 2024
1 parent 5563921 commit c2610e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
46 changes: 23 additions & 23 deletions narps_open/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,38 +106,38 @@ def start(self, first_level_only: bool = False, group_level_only: bool = False)
if first_level_only and group_level_only:
raise AttributeError('first_level_only and group_level_only cannot both be True')

# Generate workflow list
workflow_list = []
# Generate workflow lists
first_level_workflows = []
group_level_workflows = []

if not group_level_only:
workflow_list += [
for workflow in [
self._pipeline.get_preprocessing(),
self._pipeline.get_run_level_analysis(),
self._pipeline.get_subject_level_analysis(),
]
if not first_level_only:
workflow_list += [
self._pipeline.get_group_level_analysis()
]
self._pipeline.get_subject_level_analysis()]:

nb_procs = Configuration()['runner']['nb_procs']
if isinstance(workflow, list):
for sub_workflow in workflow:
first_level_workflows.append(sub_workflow)
else:
first_level_workflows.append(workflow)

if not first_level_only:
for workflow in [self._pipeline.get_group_level_analysis()]:
if isinstance(workflow, list):
for sub_workflow in workflow:
group_level_workflows.append(sub_workflow)
else:
group_level_workflows.append(workflow)

# Launch workflows
for workflow in workflow_list:
for workflow in first_level_workflows + group_level_workflows:
if workflow is None:
pass
elif isinstance(workflow, list):
for sub_workflow in workflow:
if not isinstance(sub_workflow, Workflow):
raise AttributeError('Workflow must be of type nipype.Workflow')

if nb_procs > 1:
sub_workflow.run('MultiProc', plugin_args = {'n_procs': nb_procs})
else:
sub_workflow.run()
elif not isinstance(workflow, Workflow):
raise AttributeError('Workflow must be of type nipype.Workflow')
else:
if not isinstance(workflow, Workflow):
raise AttributeError('Workflow must be of type nipype.Workflow')

nb_procs = Configuration()['runner']['nb_procs']
if nb_procs > 1:
workflow.run('MultiProc', plugin_args = {'n_procs': nb_procs})
else:
Expand Down
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ def test_pipeline_execution(
- keep intermediate levels : boolean in PipelineRunner
"""
# A list of number of subject to iterate over
nb_subjects_subgroup = Configuration()['testing']['pipelines']['nb_subjects_per_group']
nb_subjects_list = [s for s in range(nb_subjects_subgroup, nb_subjects, nb_subjects_subgroup)]
nb_subjects_list = list(range(
Configuration()['testing']['pipelines']['nb_subjects_per_group'],
nb_subjects,
Configuration()['testing']['pipelines']['nb_subjects_per_group'])
)
nb_subjects_list.append(nb_subjects)

# Initialize the pipeline
Expand Down

0 comments on commit c2610e1

Please sign in to comment.