Skip to content

Do user-defined interfaces need TraitedSpec classes? #2081

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

Closed
mwaskom opened this issue Jun 19, 2017 · 6 comments
Closed

Do user-defined interfaces need TraitedSpec classes? #2081

mwaskom opened this issue Jun 19, 2017 · 6 comments

Comments

@mwaskom
Copy link
Member

mwaskom commented Jun 19, 2017

There is a lot of boilerplate required to define an interface. From the docs a "simple" example of a custom Interface requires defining three classes:

class ExampleInputSpec(TraitedSpec):
    input_volume = File(desc="Input volume", exists=True, mandatory=True)
    parameter = traits.Int(desc="some parameter")

class ExampleOutputSpec(TraitedSpec):
    output_volume = File(desc="Output volume", exists=True)

class Example(Interface):
    input_spec = ExampleInputSpec
    output_spec = ExampleOutputSpec

Is there a technical reason why the user has to define the input and output specs as classes, rather than let the user define dictionaries of inputs and output traits and have nipype define the classes internally? i.e.

class Example(Interface):

    input_spec = dict(
        input_volume=File(desc="Input volume", exists=True, mandatory=True),
        parameter=traits.Int(desc="some parameter")
    )

    output_spec = dict(
        output_volume=File(desc = "Output volume", exists = True)
    )
@satra
Copy link
Member

satra commented Jun 20, 2017

@mwaskom - it's so that we can derive classes and functionality. also the dict formulation won't support all the functionality that is basetraitedspec and traitedspec.

that being said we will revisit this in both our current push to traitlets and with API v2.

@mwaskom
Copy link
Member Author

mwaskom commented Jun 20, 2017

@satra I understand why it's useful to have them in nipype, my question is whether it's possible to let users specify dictionaries of inputs/outputs and have nipype create the TraitedSpec objects and inject the traits internally, to save users from writing unnecessary boilerplate. I've found that given the limitations of the Function interface it can be cleaner to write an Interface to do one-off things, but it's annoying to have to define three classes.

@satra
Copy link
Member

satra commented Jun 20, 2017

@mwaskom - that's a fair point. i think we should rethink the user oriented design of nipype and minimize boilerplate where possible.

@mwaskom
Copy link
Member Author

mwaskom commented Jun 20, 2017

i think we should rethink the user oriented design of nipype and minimize boilerplate where possible.

👍👍👍👍👍

@mwaskom
Copy link
Member Author

mwaskom commented Jun 20, 2017

I'll try to take a stab at this. No promises, though.

@mwaskom
Copy link
Member Author

mwaskom commented Jun 20, 2017

See #2083 -- not battle-tested yet, but it was straightforward to implement a proof of principle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants