[Nipy-devel] [nipype] traited branch

Christopher Burns cburns@berkeley....
Wed Jan 13 17:37:11 CST 2010


On Wed, Jan 13, 2010 at 6:56 AM, Satrajit Ghosh <satra@mit.edu> wrote:
> how about, making a copy of inputs at the beginning of _parse_inputs and
> then using that throughout the code.
>
> self._inputs = deepcopy(self.inputs)
>
> within the interface, we only use self._inputs? This way you can update
> whatever field in self._inputs without affecting the hash.

Actually I think the fewer 'copies' of these parameters we have around
the better.  Even the fewer places that touch self.inputs the better.
This will help with stability and maintenance.

For example, I like the mandatory metadata tag for handling required
params in the traited branch. In the trunk, mandatory params are
specified in the run method:

def run(self, cwd=None, infile=None, outfile=None, **inputs):

And then we have all these if-blocks to check them:
        if infile:
            self.inputs.infile = infile
        if self.inputs.infile is None:
            raise ValueError('Bet requires an input file')

Not bad in itself, but then we have similar code in every Interface.

With the traited version, you specify an input as mandatory as such:
       infile = traits.Str(argstr='%s', position=0, mandatory=True)

The check for the mandatory inputs can then be generalized, so it's
all done in the base class and we don't need the if-blocks in each run
method.  Instead we have a simple call:
        self.check_mandatory_inputs()

The metadata approach is nice in that all the elements that specify a
self.inputs attribute are in one line of code.  And they can all be
generalized so we have one method in a base class to handle all of the
parameter formatting.  Instead of the current situation where we call
the base class _parse_inputs, passing in a list of mandatory params to
skip, then handle the position and mandatory params in the subclass
_parse_inputs.

Thanks Dav for pushing this, I think it will improve the code greatly!
Chris



More information about the Nipy-devel mailing list