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 multiprocess in dev tracking #676

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion scilpy/tracking/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def get_next_n_pos(self, random_generator, indices, which_seeds):

Return
------
seed_pos: List[tuple]
seed_pos: List[List]
Positions of next seeds expressed seed_generator's space and
origin.
"""
Expand Down
17 changes: 9 additions & 8 deletions scilpy/tracking/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import multiprocessing
import os
import sys
import traceback
from tempfile import TemporaryDirectory
from time import perf_counter
import traceback
from typing import Union

import nibabel as nib
import numpy as np

from dipy.data import get_sphere
from dipy.io.stateful_tractogram import Space, StatefulTractogram
from dipy.io.stateful_tractogram import Space
from dipy.reconst.shm import sh_to_sf_matrix
from dipy.tracking.streamlinespeed import compress_streamlines

Expand All @@ -31,7 +31,8 @@ class Tracker(object):
def __init__(self, propagator: AbstractPropagator, mask: DataVolume,
seed_generator: SeedGenerator, nbr_seeds, min_nbr_pts,
max_nbr_pts, max_invalid_dirs, compression_th=0.1,
nbr_processes=1, save_seeds=False, mmap_mode=None,
nbr_processes=1, save_seeds=False,
mmap_mode: Union[str, None] = None,
rng_seed=1234, track_forward_only=False, skip=0):
"""
Parameters
Expand Down Expand Up @@ -131,7 +132,7 @@ def track(self):
else:
# Each process will use get_streamlines_at_seeds
chunk_ids = np.arange(self.nbr_processes)
with nib.tmpdirs.InTemporaryDirectory() as tmpdir:
with TemporaryDirectory() as tmpdir:

pool = self._prepare_multiprocessing_pool(tmpdir)

Expand Down Expand Up @@ -198,10 +199,10 @@ def _prepare_multiprocessing_pool(self, tmpdir):
pool = multiprocessing.Pool(
self.nbr_processes,
initializer=self._send_multiprocess_args_to_global,
initargs={
initargs=({
'data_file_name': data_file_name,
'mmap_mode': self.mmap_mode
})
},))

return pool

Expand Down