qnet.utils.check_rules module

Utilities for algebraic rules

Summary

Functions:

check_rules_dict Verify the rules that classes may use for the _rules or _binary_rules class attribute.

Reference

qnet.utils.check_rules.check_rules_dict(rules)[source]

Verify the rules that classes may use for the _rules or _binary_rules class attribute.

Specifically, rules must be a OrderedDict-compatible object (list of key-value tuples, dict, OrderedDict) that maps a rule name (str) to a rule. Each rule consists of a Pattern and a replaceent callable. The Pattern must be set up to match a ProtoExpr. That is, the Pattern should be constructed through the pattern_head() routine.

Raises:
  • TypeError – If rules is not compatible with OrderedDict, the keys in rules are not strings, or rule is not a tuple of (Pattern, callable)
  • ValueError – If the head-attribute of each Pattern is not an instance of ProtoExpr, or if there are duplicate keys in rules
Returns:

OrderedDict of rules