Skip to content
This repository has been archived by the owner on Oct 15, 2019. It is now read-only.

2. Fix blacklistpolicy and add query #92

Merged
merged 4 commits into from
Dec 4, 2016
Merged

2. Fix blacklistpolicy and add query #92

merged 4 commits into from
Dec 4, 2016

Conversation

lryta
Copy link
Member

@lryta lryta commented Dec 3, 2016

Fix namespace problem and add query for blacklistpolicy.

Passed all tests.

@jermainewang
Copy link
Member

Could we put the query in the base Policy class? So we could get the result even if we are not using ABL policy.

@lryta
Copy link
Member Author

lryta commented Dec 3, 2016

@jermainewang This query is designed for blacklist rule. The rules won't be loaded before first switch to ABL.

@lryta lryta changed the title Fix blacklistpolicy and add query 2. Fix blacklistpolicy and add query Dec 3, 2016
if ns_path not in cls._rules or name not in cls._rules[ns_path]:
return 'No rule for {} is found in {}.'.format(name, ns_path)
else:
from tabulate import tabulate
Copy link
Member

Choose a reason for hiding this comment

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

Please make sure this dependency works under python3

Copy link
Member Author

Choose a reason for hiding this comment

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

tabulate works in python3. No worries.

self._rules.setdefault(nspace, {})
self._rules[nspace].setdefault(name, [])
self._hash.setdefault(nspace, {})
self._hash[nspace].setdefault(name, set())
Copy link
Member

Choose a reason for hiding this comment

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

Use collections.defaultdict to replace these?

Copy link
Member Author

Choose a reason for hiding this comment

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

I try to fix, but it seems that YAML will use some chars to record since it is a class different from ordinary dict. The current solution don't need to record extra chars or do explicit conversion between defaultdict and dict when saving the dict into YAML file.

@@ -253,3 +268,37 @@ def _get_arg_rule_key(self, args, kwargs):
arg_key = [self._get_type_signiture(x) for x in args]
kwarg_key = sorted(kwargs.keys())
return '-'.join(arg_key) + '+' + '-'.join(kwarg_key)

@classmethod
Copy link
Member

Choose a reason for hiding this comment

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

This is a little bit weird here. You take a cls argument and use the _rules belongs to it. This means one might create multiple policy objects and they have different rules associate with it, which is quite counter-intuitive. I think it is better to have only one policy object for one policy type. When we switch the policy, we are not constructing an object, but instead:

policy.set_global_policy("only_numpy")
# policy.set_global_policy("auto_blacklist")
# policy.set_global_policy("prefer_mxnet")

This will also avoid importing the policy python file. What do you think?

Copy link
Member Author

@lryta lryta Dec 4, 2016

Choose a reason for hiding this comment

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

@jermainewang In fact they cannot create different rules. The rule is associated with class instead of objects. Ending with this solution is a compromise of all existing features like with statement of a policy object. I've emphasized in the doc.

Copy link
Member

Choose a reason for hiding this comment

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

I think with statement is also not recommended based on our design of ABL.

Copy link
Member

Choose a reason for hiding this comment

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

The question is still here. If all the object's states are associated with the class, then the object itself is meaningless. We should instead have API like:

policy.AutoBlackListPolicy.query(name)

@jermainewang jermainewang mentioned this pull request Dec 3, 2016
@jermainewang
Copy link
Member

Let's move discussions to #93 .

@lryta lryta merged commit 7177f64 into master Dec 4, 2016
@lryta lryta deleted the fix_ns_and_add_query branch December 6, 2016 04:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants