Skip to content

Parameter classes#53

Merged
reelmatt merged 11 commits intomasterfrom
dev/samir
Apr 16, 2020
Merged

Parameter classes#53
reelmatt merged 11 commits intomasterfrom
dev/samir

Conversation

@reddigari
Copy link
Collaborator

  • Adds a base Parameter class with subclasses for StringParameter, FileParameter, etc. These take default values, labels, and docstrings to characterize the parameter's role in the processing node.
  • Every concrete node must define OPTIONS, a dictionary with Parameter values
  • The descriptor classes Options and OptionTypes provide access to those options from both the Node class and instances.
    • Accessing .option_types from either the class or instance returns a dictionary representation of the defaults for use in the front end
    • Accessing .options from the instance returns copies of the default parameters, with values taken from the instance's option_values attribute. This attribute is what .options used to be. Accessing them through the Options descriptor allows us to use the power of the Paramter classes (e.g. validation)
  • Fixes some file access logic in pyworkflow (retrieve_node_data is no longer static, because it needs access to the workflow's root_dir to look up filenames)

This might seem a little overly complex at first glance, and I've been staring at it for so long that I'm no longer sure it's not. But it feels like all of the boilerplate I was able to remove from node.py means it's worthwhile. Concrete classes no longer need to implement their own __init__ to bubble things upward. Using descriptor-style access means the parameters must only be defined once (as Node.OPTIONS), and can be accessed flexibly depending on what the caller needs to know. Also means all the parameter metadata (type, docstring) no longer needs to be serialized in the networkx graph.

Copy link
Member

@reelmatt reelmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks fantastic! One comment about updating the front-end, and then a few minor tweaks on the back-end.

I agree it does look complex, but it made more and more sense as I read through it.

Just to re-phrase some of the explanation you gave above, to see if I fully understand things:

  • Option and OptionTypes are similar in that they return Parameter information. Option kind of works as a Parameter factory, whereas OptionTypes is really just for read-only info to pass to the front-end.
  • .option_values is just a regular dict() that stores information passed from the form when creating/updating a Node.
  • .options is the "same" as .option_values except in translates the dict into a Parameter class which gets you the validation you mention. Therefore we could use either, but .options is more powerful/useful.

That's just me working through it in my head. Hopefully that matches with what you described above, but let me know if any of that is off.

@reddigari
Copy link
Collaborator Author

@reelmatt Those explanations are spot on. Latest commits resolve all your comments.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants