geneticengine.grammar.metahandlers.smt ====================================== .. py:module:: geneticengine.grammar.metahandlers.smt Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/geneticengine/grammar/metahandlers/smt/lang/index /autoapi/geneticengine/grammar/metahandlers/smt/parser/index Attributes ---------- .. autoapisummary:: geneticengine.grammar.metahandlers.smt.p_expr Classes ------- .. autoapisummary:: geneticengine.grammar.metahandlers.smt.Grammar geneticengine.grammar.metahandlers.smt.RandomSource geneticengine.grammar.metahandlers.smt.MetaHandlerGenerator geneticengine.grammar.metahandlers.smt.SMT Functions --------- .. autoapisummary:: geneticengine.grammar.metahandlers.smt.is_metahandler geneticengine.grammar.metahandlers.smt.simplify_type Package Contents ---------------- .. py:class:: Grammar(starting_symbol, considered_subtypes = None, expansion_depthing = False) .. py:attribute:: starting_symbol :type: type .. py:attribute:: alternatives :type: dict[type, list[type]] .. py:attribute:: distanceToTerminal :type: dict[Any, int] .. py:attribute:: all_nodes :type: set[type] .. py:attribute:: recursive_prods :type: set[type] .. py:attribute:: terminals :type: set[type] .. py:attribute:: non_terminals :type: set[type] .. py:attribute:: abstract_dist_to_t :type: dict[type, dict[type, int]] .. py:attribute:: considered_subtypes :value: [] .. py:attribute:: expansion_depthing :value: False .. py:method:: validate() .. py:method:: register_alternative(nonterminal, nodetype) Register a production A->B Call multiple times with same A to register many possible alternatives. .. py:method:: register_type(ty) .. py:method:: __repr__() .. py:method:: get_all_symbols() All symbols in the current grammar, including terminals. .. py:method:: collect_types(ty) .. py:method:: get_all_mentioned_symbols() .. py:method:: get_distance_to_terminal(ty) Returns the current distance to terminal of a given type. .. py:method:: get_min_tree_depth() Returns the minimum depth a tree must have. .. py:method:: get_max_node_depth() Returns the maximum minimum depth a node can have. .. py:method:: preprocess() Computes distanceToTerminal via a fixpoint algorithm. .. py:method:: get_weights() .. py:method:: update_weights(learning_rate, extra_weights) .. py:method:: is_reachable(t1, t2) .. py:method:: 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. .. py:method:: usable_grammar() Returns a subset of the grammar that is actually reachable. .. py:method:: 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 .. py:function:: 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 .. py:class:: RandomSource Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:method:: randint(min, max) :abstractmethod: .. py:method:: random_float(min, max) :abstractmethod: .. py:method:: choice(choices) .. py:method:: choice_weighted(choices, weights) .. py:method:: shuffle(lst) .. py:method:: pop_random(lst) .. py:method:: random_bool() .. py:method:: normalvariate(mean, sigma) .. py:class:: MetaHandlerGenerator Bases: :py:obj:`abc.ABC` MetaHandlers are type refinements. They override the generation procedure of the base type. .. py:method:: validate(Any) :abstractmethod: .. py:method:: generate(random, grammar, base_type, rec, dependent_values, parent_values) :abstractmethod: Generates an instance of type base_type, according to some criterion. :param Source r: Random source for generation :param Grammar g: 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 :param int depth: the current depth budget :param Type base_type: The inner type being annotated :param str argname: 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 .. py:method:: get_dependencies() .. py:data:: p_expr .. py:function:: simplify_type(t) .. py:class:: SMT(restriction_as_str='true==true') Bases: :py:obj:`geneticengine.grammar.metahandlers.base.MetaHandlerGenerator` MetaHandlers are type refinements. They override the generation procedure of the base type. .. py:attribute:: restriction_as_str :value: 'true==true' .. py:attribute:: restriction .. py:method:: validate(v) .. py:method:: generate(random, grammar, base_type, rec, dependent_values, parent_values) Generates an instance of type base_type, according to some criterion. :param Source r: Random source for generation :param Grammar g: 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 :param int depth: the current depth budget :param Type base_type: The inner type being annotated :param str argname: 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 .. py:method:: __repr__()