:py:mod:`medcat.utils.config_utils` =================================== .. py:module:: medcat.utils.config_utils Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: medcat.utils.config_utils.WAFCarrier Functions ~~~~~~~~~ .. autoapisummary:: medcat.utils.config_utils.is_old_type_config_dict medcat.utils.config_utils.fix_waf_lambda medcat.utils.config_utils.ensure_backward_compatibility medcat.utils.config_utils.get_and_del_weighted_average_from_config medcat.utils.config_utils.weighted_average medcat.utils.config_utils.default_weighted_average medcat.utils.config_utils.attempt_fix_weighted_average_function medcat.utils.config_utils._fix_waf Attributes ~~~~~~~~~~ .. autoapisummary:: medcat.utils.config_utils.logger .. py:class:: WAFCarrier Bases: :py:obj:`Protocol` Base class for protocol classes. Protocol classes are defined as:: class Proto(Protocol): def meth(self) -> int: ... Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:: class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:: class GenProto(Protocol[T]): def meth(self) -> T: ... .. py:property:: weighted_average_function :type: Callable[[float], int] .. py:data:: logger .. py:function:: is_old_type_config_dict(d) Checks if the dict provided is an old style (jsonpickle) config. This checks for json-pickle specific keys such as py/object and py/state. If both of those are keys somewhere within the 2 initial layers of the nested dict, it's considered old style. :param d: Loaded config. :type d: dict :Returns: **bool** -- Whether it's an old style (jsonpickle) config. .. py:function:: fix_waf_lambda(carrier) .. py:function:: ensure_backward_compatibility(config, workers) .. py:function:: get_and_del_weighted_average_from_config(config) .. py:function:: weighted_average(step, factor) .. py:function:: default_weighted_average(step) .. py:function:: attempt_fix_weighted_average_function(waf) Attempf fix weighted_average_function. When saving a model (dill.dump) in older python versions (3.10 and before) and then loading it back up with newer versions of python (3.11 and later) there can be an issue with loading `config.linking.weighted_average_function`. The value attributed to this is generally a `functools.partial`. And it loads just fine, but cannot subsequently be called. This method fixes the issue if the default function is used. It retains the arguments and keyword arguments of the original `partial. What this method does is recreate the partial function based on the arguments originally provided. Along with the fix, it logs a warning. However, if a non-default method is used, we are unable to fix it. That is because we do not know which method may have been used. In that case, a warning is logged. :param waf: The weighted average function. :type waf: Callable[[int], float] :Returns: **Callable[[int], float]** -- The (potentially) fixed function. .. py:function:: _fix_waf(waf)