Interface works with 'MultiProc' but not with 'PBSGraph'

Dear Neurostars-community,

I would like to run an interface for a command line tool that is not yet incorporated in nipype (the code is below). The interface works perfectly when executed using the ‘MultiProc’ plugin, but I get this error when I use PBSGraph:
Traceback (most recent call last):
File “/gpfs1/scratch/30days/uqsbollm/temp/CONCUSSION-Q0538_test/qsm/batch/”, line 32, in
info = loadpkl(pklfile)
File “/gpfs1/scratch/90days/uqsbollm/software/miniconda3/lib/python3.6/site-packages/nipype/utils/”, line 668, in loadpkl
raise e
File “/gpfs1/scratch/90days/uqsbollm/software/miniconda3/lib/python3.6/site-packages/nipype/utils/”, line 659, in loadpkl
unpkl = pickle.load(pkl_file)
ModuleNotFoundError: No module named ‘nipype_interface_tgv_qsm’

This is how I use the interface in my code:
import nipype_interface_tgv_qsm as tgv

qsm_n = MapNode(tgv.QSMappingInterface(iterations=1000, alpha=[0.0015, 0.0005], num_threads=1),
name=‘qsm_node’, iterfield=[‘file_phase’, ‘file_mask’, ‘TE’, ‘b0’])

This is the code for the interface:
Created on Sun Aug 3 11:46:42 2014

@author: epracht
from future import division
import os
from nipype.interfaces.base import CommandLine, traits, TraitedSpec, File, CommandLineInputSpec
from nipype.interfaces.base.traits_extension import isdefined
from nipype.utils.filemanip import fname_presuffix, split_filename


def gen_filename(fname, suffix, newpath, use_ext=True):
return fname_presuffix(fname, suffix=suffix, newpath=newpath, use_ext=use_ext)

class QSMappingInputSpec(CommandLineInputSpec):
# TODO This is incomplete and just gives some basic parameters
file_phase = File(exists=True, desc=‘Phase image’, mandatory=True, argstr="-p %s")
file_mask = File(exists=True, desc=‘Image mask’, mandatory=True, argstr="-m %s")
num_threads = traits.Int(-1, usedefault=True, nohash=True, desc=“Number of threads to use, by default $NCPUS”)
TE = traits.Float(desc=‘Echo Time [sec]’, mandatory=True, argstr="-t %f")
b0 = traits.Float(desc=‘Field Strength [Tesla]’, mandatory=True, argstr="-f %f")
# Only support of one alpha here!
alpha = traits.List([0.0015, 0.0005], minlen=2, maxlen=2, desc=‘Regularisation alphas’, usedefault=True,
argstr="–alpha %s")
# We only support one iteration - easier to handle in nipype
iterations = traits.Int(1000, desc=‘Number of iterations to perform’, usedefault=True, argstr="-i %d")
erosions = traits.Int(5, desc=‘Number of mask erosions’, usedefault=True, argstr="-e %d")
out_suffix = traits.String("_qsm_recon", desc=‘Suffix for output files. Will be followed by 000 (reason - see CLI)’,
usedefault=True, argstr="-o %s")

class QSMappingOutputSpec(TraitedSpec):
out_file = File(desc=‘Computed susceptibility map’)

class QSMappingInterface(CommandLine):
input_spec = QSMappingInputSpec
output_spec = QSMappingOutputSpec

# We use here an interface to the CLI utility
_cmd = "tgv_qsm"

def __init__(self, **inputs):
    super(QSMappingInterface, self).__init__(**inputs)
    self.inputs.on_trait_change(self._num_threads_update, 'num_threads')

    if not isdefined(self.inputs.num_threads):
        self.inputs.num_threads = self._num_threads

def _list_outputs(self):
    outputs = self.output_spec().get()
    pth, fname, ext = split_filename(self.inputs.file_phase)
    outputs['out_file'] = gen_filename(self.inputs.file_phase, suffix=self.inputs.out_suffix + "_000",
    return outputs

def _num_threads_update(self):
    self._num_threads = self.inputs.num_threads
    if self.inputs.num_threads == -1:
        self.inputs.environ.update({THREAD_CONTROL_VARIABLE: '$NCPUS'})
        self.inputs.environ.update({THREAD_CONTROL_VARIABLE: '%s' % self.inputs.num_threads})

What am I doing wrong here :? Thank you for any hint how I could debug this.

I don’t have experience with PBS plugin, but it looks to me that this is a similar problem to the one described in the question 1 in this post

Dear djarecka,

the missing python path was exactly the problem. I just added the directory where my interface file is located to the $PYTHONPATH environment variable and it now works perfectly.

Thank you so much for the hint

1 Like