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

Conditional outputs#303 #549

Merged
merged 32 commits into from
Dec 17, 2019
Merged

Conversation

DarrinFong
Copy link
Contributor

Purpose

Enables Conditional-path-template in descriptor's output-files. CPT will contain a list of objects whose key represents a boolean expression (python syntax), the first true expression's corresponding path will be selected (top down). If the output-file is required, a default key is must be included in the list of CPT.

PT and CPT are mutex properties within an output-file

Current behaviour

"output-files": [{
  ... ,
  "path-template": "[PARAM1].txt"
}]

New behaviour

"output-files": [{
  ... ,
  "path-template": "[PARAM1].txt"
}, {
  ... , 
  "optional": false,
  "conditional-path-template":
  [
    {"opt1 and (opt2 > 10)": "[OPT1]-thing_large.txt"},
    {"opt1":                 "[OPT1]-thing.txt"},
    {"opt2 > 10":            "[PARAM1]-thing_large.txt"},
    {"default":              "[PARAM1]-thing.txt"}
  ]
}]

@glatard
Copy link
Member

glatard commented Oct 17, 2019

Hi @DarrinFong, tests are currently failing, would you like to have a look?

@coveralls
Copy link

coveralls commented Oct 17, 2019

Coverage Status

Coverage increased (+2.08%) to 93.957% when pulling 3cdc5ab on DarrinFong:conditional_outputs#303 into 0469a3d on boutiques:develop.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 93.905% when pulling e566b3e on DarrinFong:conditional_outputs#303 into f904c2a on boutiques:develop.

parsedExp.append(word)
# If expression is true, set fileName
# Stop checking (if-elif...)
if " ".join("{0}".format(w) for w in parsedExp) == "default":
Copy link
Member

Choose a reason for hiding this comment

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

I may be reading this wrong, but aren't what you have written on #L1078 (parsedExp = ["False"]) and what you're checking here, ( .... == "default") incompatible, so defaults would never be added? You know what's going on in here much better than I, @DarrinFong, so please just double check and let me know :)

Copy link
Contributor Author

@DarrinFong DarrinFong Nov 6, 2019

Choose a reason for hiding this comment

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

if word in in_out_dict:
    # in_out_dict are k:v pairs that will be in the output of simulate
elif word in all_ids:
    parsedExp = ["False"]
    break

The elif block should only 'falsify' the expressions that contain an ID which is both:

  • in descriptor's inputs/output-files IDs
  • NOT in selected values for simulate

Which means the only way for 'default' to be evaluated False is when an ID of name 'default' is present in the descriptor's inputs/output-files IDs. (This raises a concern of whether we have to add 'default' to the list of invalid IDs).

Copy link
Member

Choose a reason for hiding this comment

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

Great - thank you for the clarification :)

I do think that maybe we want to add "default" as a restricted word in the schema so that it can't be used as an ID... @glatard, thoughts?

@gkiar
Copy link
Member

gkiar commented Nov 5, 2019

Hey @DarrinFong - I added some comments. Overall, this looks awesome! Thanks so much :)

…ession variables exist in descriptor inputs/output-files). Added unit tests for those.
…perties (review), attempting check variable against type of input for CPT's expressions
@gkiar
Copy link
Member

gkiar commented Nov 11, 2019

@DarrinFong - want to investigate why this is failing, and we can re-review once that is fixed? Thanks!

docopt==0.6.2
nexus-sdk;
python_version >= '3.5';
Copy link
Member

Choose a reason for hiding this comment

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

This will break installation from pypi for Python<3.5. The solution has to work with the following install command:

pip install -r requirements.txt

For Python<3.5.
The nexus line should be written as:
nexus-sdk; python_version >= '3.5'

@DarrinFong
Copy link
Contributor Author

DarrinFong commented Dec 13, 2019

@gkiar Hey Greg, can you take a look at the conditions validation you mentioned in a conversation above?
The current validation is to recursively (by parentheses) replace the values neighbouring a valid operator (==, !=, >=, <=, >, <) by their types (Flag, Number, String, Path) and check if they are of the same type. Thanks a lot!

@@ -58,6 +62,82 @@ def inById(i):
return descriptor["inputs"][inputGet("id").index(i)]
return {}

def conditionalExpFormat(s):
Copy link
Member

Choose a reason for hiding this comment

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

This function appears to exist in both localExec.py and validator.py, so perhaps we could move it to a utils file and import it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function moved to utils.py!

@@ -22,6 +23,9 @@ def validate_descriptor(json_file, **kwargs):
"""
path, fil = op.split(bfile)
schema_file = op.join(path, "schema", "descriptor.schema.json")
allowed_keywords = ['and', 'or', 'false', 'true']
Copy link
Member

Choose a reason for hiding this comment

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

Because capitalization may be funny/distinct across representations (in particular True versus true), we may want to either a) add more capitalizations to this list, or b) convert everything to an upper/lowercase value when we compare. Essentially just an extra precaution to avoid the hole of evaluating a JSON true and a boolean Python True to be distinct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I opted for option b), just in case someone needs to write ANd 😄

Copy link
Member

@gkiar gkiar left a comment

Choose a reason for hiding this comment

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

Hey @DarrinFong - thanks for this! It looks awesome, I'm really excited to have this rolled in 😄
I left a few comments, but they're all minor and non-blocking if you're too swamped to get to them/we can just create issues to tie up the ends. Lmk if what you think!

Thanks again :D

@gkiar gkiar merged commit b79df4e into boutiques:develop Dec 17, 2019
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.

None yet

4 participants