Skip to content
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

How can we improve internal option handling? #49

Open
leeping opened this issue Feb 26, 2014 · 2 comments
Open

How can we improve internal option handling? #49

leeping opened this issue Feb 26, 2014 · 2 comments
Labels

Comments

@leeping
Copy link
Owner

leeping commented Feb 26, 2014

Thinking out loud here..

Currently a ForceBalance calculation reads from the input file a set of general options for the calculation and one set of target options for each target. Options that are not set in the input file are set to their default values as declared in the parser. This is done by first copying the default general options / target options and then inserting user-provided values. Simple right?

Wrong; it turns out we often want to define default values at the target level. That is to say, different targets might want to have different default values for a given option. The default values for XYZ coordinates is an example.

I have tried (unsuccessfully) to implement this. The set_option method defined for all ForceBalance classes allows you to enter a default value. This value is used if the options dictionaries (passed into the target initialization) do not contain the key in question. However, since the options dictionaries always contain the default values from parser.py, the target-level default values are never used, so we don't have the fine-grained control over target options that we desire.

I think there ought to be a hierarchy of ways to set target options:

  • User-provided input (in the input file) is always used.
  • Defaults provided at the target level are next highest in priority.
  • Global defaults provided in parser.py are lowest priority.

One way to implement this would be to simply not copy the global defaults when initially creating the global option / target option dictionaries, so they are empty except for the user-provided values when passed into the class initialization. This could break a few existing things, but thank goodness for unit tests.

Also: Certain True/False options have previously defaulted to False, but the proposed change would make it so that the option doesn't exist at all. This means several places in the code I have to do this clumsiness:

-        if not options['continue']: 
+        if ('continue' not in options) or (not options['continue']): 

It's not too clumsy but somehow it seems wrong.

Let me know what you think.

@rmcgibbo
Copy link

You mention the 'hierarchy' of different ways that a given option can be set, with direct user input at the highest level and different 'levels' of defaults having lower priority below that. What about directly translating that idea into code?

e.g. https://gist.github.com/rmcgibbo/9224580

Each time you register a value for an option, you'd just mark what priority it has and then let the library give you the highest priority value each time you query it.

@leeping
Copy link
Owner Author

leeping commented Feb 26, 2014

That sounds like exactly what I need and well executed. I'll implement it and try it out when I get a chance! :)

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

No branches or pull requests

2 participants