Skip to content

FIX: Copy num_threads to MapNode-generated Nodes #2019

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

Merged
merged 3 commits into from
May 16, 2017
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
12 changes: 8 additions & 4 deletions nipype/pipeline/engine/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1112,9 +1112,14 @@ def _make_nodes(self, cwd=None):
nitems = len(filename_to_list(getattr(self.inputs, self.iterfield[0])))
for i in range(nitems):
nodename = '_' + self.name + str(i)
node = Node(deepcopy(self._interface), name=nodename)
node.overwrite = self.overwrite
node.run_without_submitting = self.run_without_submitting
node = Node(deepcopy(self._interface),
n_procs=self._interface.num_threads,
mem_gb=self._interface.estimated_memory_gb,
overwrite=self.overwrite,
needed_outputs=self.needed_outputs,
run_without_submitting=self.run_without_submitting,
base_dir=op.join(cwd, 'mapflow'),
name=nodename)
node.plugin_args = self.plugin_args
node._interface.inputs.set(
**deepcopy(self._interface.inputs.get()))
Expand All @@ -1126,7 +1131,6 @@ def _make_nodes(self, cwd=None):
logger.debug('setting input %d %s %s', i, field, fieldvals[i])
setattr(node.inputs, field, fieldvals[i])
node.config = self.config
node.base_dir = op.join(cwd, 'mapflow')
yield i, node

def _node_runner(self, nodes, updatehash=False):
Expand Down
22 changes: 22 additions & 0 deletions nipype/pipeline/engine/tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,28 @@ def func1(in1):
assert "can only concatenate list" in str(excinfo.value)


def test_mapnode_expansion(tmpdir):
os.chdir(str(tmpdir))
from nipype import MapNode, Function

def func1(in1):
return in1 + 1

mapnode = MapNode(Function(function=func1),
iterfield='in1',
name='mapnode')
mapnode.inputs.in1 = [1, 2]
mapnode.interface.num_threads = 2
mapnode.interface.estimated_memory_gb = 2

for idx, node in mapnode._make_nodes():
for attr in ('overwrite', 'run_without_submitting', 'plugin_args'):
assert getattr(node, attr) == getattr(mapnode, attr)
for attr in ('num_threads', 'estimated_memory_gb'):
assert (getattr(node._interface, attr) ==
getattr(mapnode._interface, attr))


def test_node_hash(tmpdir):
wd = str(tmpdir)
os.chdir(wd)
Expand Down