:py:mod:`omnisolver.common.plugin` ================================== .. py:module:: omnisolver.common.plugin .. autoapi-nested-parse:: Hook specifications for omnisolver. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: omnisolver.common.plugin.Plugin Functions ~~~~~~~~~ .. autoapisummary:: omnisolver.common.plugin.plugin_from_specification omnisolver.common.plugin.get_plugin omnisolver.common.plugin.filter_namespace_by_iterable omnisolver.common.plugin.add_argument omnisolver.common.plugin.import_object Attributes ~~~~~~~~~~ .. autoapisummary:: omnisolver.common.plugin.T omnisolver.common.plugin.plugin_spec omnisolver.common.plugin.plugin_impl omnisolver.common.plugin.TYPE_MAP .. py:data:: T .. py:data:: plugin_spec .. py:data:: plugin_impl .. py:class:: Plugin Bases: :py:obj:`NamedTuple` Namedtuple storing all information needed from plugin. .. py:attribute:: name :type: str .. py:attribute:: description :type: str .. py:attribute:: create_sampler :type: Callable[Ellipsis, dimod.Sampler] .. py:attribute:: populate_parser :type: Callable[[argparse.ArgumentParser], None] .. py:attribute:: init_args :type: Iterable[str] .. py:attribute:: sample_args :type: Iterable[str] .. py:function:: plugin_from_specification(specification, loader=importlib.import_module) -> Plugin Create Plugin constructed from given specification. :param specification: dictionary specifying properties of the solver. For reference, see random.yml in omnisolver.random package. :param loader: function used for loading modules. Usually no need to override this. :returns: a instance of Plugin with the following properties: - plugin.name is taken from "name" in specification - create_solver of a class pointed to by specification["sampler_class"] - populate_parser acts in such a way, that it adds to the target parser all arguments present in specification["args"] .. py:function:: get_plugin() -> Plugin Hook for defining plugin instances. .. py:function:: filter_namespace_by_iterable(namespace: argparse.Namespace, attribute_filter: Iterable[str]) -> Dict[str, Any] Filter namespace, leaving only attribute present in given filter. :param namespace: namespace to be filtered. :param attribute_filter: iterable of attribute names to be used as a filter. return dictionary containing mapping attribute name -> attribute value for every attribute of a signature such that its name is in attribute_filter. .. py:data:: TYPE_MAP .. py:function:: add_argument(parser: argparse.ArgumentParser, specification: Dict[str, Any]) -> None Given specification of the argument, add it to parser. .. py:function:: import_object(dotted_path: str, loader=importlib.import_module) Imports object specified by its full dotted_path. :param dotted_path: full path of the object, e.g. omnisolver.random.sampler.RandomSampler. :param loader: function used to load module from the given path. Usually you don't need to specify that, this is here for testability purposes. :returns: whatever dotted path points to.