geneticengine.grammar.metahandlers.smt
Submodules
Attributes
Classes
Helper class that provides a standard way to create an ABC using |
|
MetaHandlers are type refinements. |
|
MetaHandlers are type refinements. |
Functions
|
Returns if type is a metahandler. AnnotatedType[int, IntRange(3,10)] is |
Package Contents
- class geneticengine.grammar.metahandlers.smt.Grammar(starting_symbol, considered_subtypes=None, expansion_depthing=False)
- Parameters:
starting_symbol (type)
considered_subtypes (list[type] | None)
expansion_depthing (bool)
- starting_symbol: type
- alternatives: dict[type, list[type]]
- distanceToTerminal: dict[Any, int]
- all_nodes: set[type]
- recursive_prods: set[type]
- terminals: set[type]
- non_terminals: set[type]
- abstract_dist_to_t: dict[type, dict[type, int]]
- considered_subtypes = []
- expansion_depthing = False
- validate()
- register_alternative(nonterminal, nodetype)
Register a production A->B Call multiple times with same A to register many possible alternatives.
- Parameters:
nonterminal (type)
nodetype (type)
- register_type(ty)
- Parameters:
ty (type)
- __repr__()
- get_all_symbols()
All symbols in the current grammar, including terminals.
- Return type:
tuple[set[type], set[type], set[type]]
- collect_types(ty)
- Parameters:
ty (type)
- get_all_mentioned_symbols()
- Return type:
set[type]
- get_distance_to_terminal(ty)
Returns the current distance to terminal of a given type.
- Parameters:
ty (type)
- Return type:
int
- get_min_tree_depth()
Returns the minimum depth a tree must have.
- get_max_node_depth()
Returns the maximum minimum depth a node can have.
- preprocess()
Computes distanceToTerminal via a fixpoint algorithm.
- Return type:
None
- get_weights()
- update_weights(learning_rate, extra_weights)
- is_reachable(t1, t2)
- Parameters:
t1 (Type)
t2 (Type)
- Return type:
bool
- reaches_leaf(t, visited=None)
Returns whether a given type reaches a leaf type, or None if it causes a loop.
Loops should be ignored only if there is an alternative path.
- Parameters:
t (Type)
visited (set | None)
- Return type:
bool | None
- get_grammar_properties_summary()
Returns a summary of grammar properties:
A depth range (minimum depth and maximum depth of the grammar)
The number of Non-Terminal symbols in the grammar
- A summary of production statistics:
Frequency of Productions in the Right Hand side
The number of recursive productions
Per non-terminal, all the alternative productions
The total number of productions
The average number of productions per non-terminal
The average non-terminals per production for each non-terminal
- Return type:
- geneticengine.grammar.metahandlers.smt.is_metahandler(ty)
Returns if type is a metahandler. AnnotatedType[int, IntRange(3,10)] is an example of a Metahandler.
Verification is done using the __metadata__, which is the first argument of Annotated
- Parameters:
ty (type)
- Return type:
bool
- class geneticengine.grammar.metahandlers.smt.RandomSource
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstractmethod randint(min, max)
- Parameters:
min (int)
max (int)
- Return type:
int
- abstractmethod random_float(min, max)
- Parameters:
min (float)
max (float)
- Return type:
float
- choice(choices)
- Parameters:
choices (list[T])
- Return type:
T
- choice_weighted(choices, weights)
- Parameters:
choices (list[T])
weights (list[float])
- Return type:
T
- shuffle(lst)
- Parameters:
lst (list[T])
- pop_random(lst)
- Parameters:
lst (list[T])
- Return type:
T
- random_bool()
- Return type:
bool
- normalvariate(mean, sigma)
- Parameters:
mean (float)
sigma (float)
- Return type:
float
- class geneticengine.grammar.metahandlers.smt.MetaHandlerGenerator
Bases:
abc.ABCMetaHandlers are type refinements.
They override the generation procedure of the base type.
- abstractmethod validate(Any)
- Return type:
bool
- abstractmethod generate(random, grammar, base_type, rec, dependent_values, parent_values)
Generates an instance of type base_type, according to some criterion.
- Parameters:
r (Source) – Random source for generation
g (Grammar) – Grammar to follow in the generation :param Callable[[int, Type], Any] rec: The method to generate a new instance of type and maximum depth d
depth (int) – the current depth budget
base_type (Type) – The inner type being annotated
argname (str) – The name of the field of the parent object which is being generated :param Dict[str, Type] context: The names and types of all fields in the parent object :param Dict[str, Type] dependent_values: The names and values of all previous fields in the parent object
grammar (geneticengine.grammar.grammar.Grammar)
rec (Callable[[type[T]], T])
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- Return type:
Any
- get_dependencies()
- geneticengine.grammar.metahandlers.smt.p_expr
- geneticengine.grammar.metahandlers.smt.simplify_type(t)
- Parameters:
t (type)
- Return type:
type
- class geneticengine.grammar.metahandlers.smt.SMT(restriction_as_str='true==true')
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorMetaHandlers are type refinements.
They override the generation procedure of the base type.
- restriction_as_str = 'true==true'
- restriction
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
Generates an instance of type base_type, according to some criterion.
- Parameters:
r (Source) – Random source for generation
g (Grammar) – Grammar to follow in the generation :param Callable[[int, Type], Any] rec: The method to generate a new instance of type and maximum depth d
depth (int) – the current depth budget
base_type (Type) – The inner type being annotated
argname (str) – The name of the field of the parent object which is being generated :param Dict[str, Type] context: The names and types of all fields in the parent object :param Dict[str, Type] dependent_values: The names and values of all previous fields in the parent object
grammar (geneticengine.grammar.grammar.Grammar)
rec (Any)
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- __repr__()