How to use the transonic.log.logger.debug function in transonic

To help you get started, we’ve selected a few transonic examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fluiddyn / transonic / transonic / backends / base.py View on Github external
return None, None, None

        if path_dir is None:
            return

        if not analyse:
            with open(path_py) as file:
                code = file.read()
            analyse = analyse_aot(code, path_py, self.name)

        code_backend, codes_ext, code_header = self._make_backend_code(
            path_py, analyse
        )
        if not code_backend:
            return
        logger.debug(f"code_{self.name}:\n{code_backend}")

        for file_name, code in codes_ext["function"].items():
            path_ext_file = path_dir / (file_name + ".py")
            write_if_has_to_write(
                path_ext_file, format_str(code), logger.info, force
            )

        for file_name, code in codes_ext["class"].items():
            path_ext_file = (
                path_dir.parent / f"__{self.name}__" / (file_name + ".py")
            )
            write_if_has_to_write(
                path_ext_file, format_str(code), logger.info, force
            )

        written = write_if_has_to_write(
github fluiddyn / transonic / transonic / justintime.py View on Github external
if not mod.is_dummy_file and has_to_build(path_backend, mod.filename):
                has_to_write = True
            else:
                has_to_write = False
        else:
            has_to_write = True

        src = None

        if has_to_write:
            src, has_to_write = backend.jit.make_backend_source(
                mod.info_analysis, func, path_backend
            )

            if has_to_write and mpi.rank == 0:
                logger.debug(f"write code in file {path_backend}")
                with open(path_backend, "w") as file:
                    file.write(src)
                    file.flush()

        if src is None and mpi.rank == 0:
            with open(path_backend) as file:
                src = file.read()

        hex_src = None
        name_mod = None
        if mpi.rank == 0:
            # hash from src (to produce the extension name)
            hex_src = make_hex(src)
            name_mod = ".".join(
                path_backend.absolute()
                .relative_to(path_root)
github fluiddyn / transonic / transonic / analyses / __init__.py View on Github external
def analyse_aot(code, pathfile, backend_name):
    """Gather the informations for ``@boost`` and blocks"""
    debug = logger.debug

    debug("extast.parse")
    module = extast.parse(code)

    debug("compute ancestors and chains")
    ancestors, duc, udc = compute_ancestors_chains(module)

    debug("filter_code_typevars")
    code_dependance_annotations = filter_code_typevars(module, duc, ancestors)
    debug(code_dependance_annotations)

    debug("find boosted objects")
    boosted_dicts = get_decorated_dicts(
        module, ancestors, duc, None, backend_name
    )
    debug(pformat(boosted_dicts))
github fluiddyn / transonic / transonic / justintime.py View on Github external
raise
                    logger.debug(error)

            if self.compiling or not _COMPILE_JIT:
                return func(*args, **kwargs)

            if (
                self.backend_func
                and error
                and error.startswith("Invalid call to pythranized function `")
            ):
                logger.debug(error)
                logger.info(
                    f"{backend.name_capitalized} function `{func_name}` called with new types."
                )
                logger.debug(
                    "Transonic is going to recompute the function for the new types."
                )

            arg_types = [
                backend.jit.compute_typename_from_object(arg)
                for arg in itertools.chain(args, kwargs.values())
            ]

            backenize_with_new_header(arg_types)
            return func(*args, **kwargs)
github fluiddyn / transonic / transonic / justintime.py View on Github external
return self.backend_func(*args, **kwargs)
            except TypeError as err:
                # need to compiled or recompile
                error = False
                if self.backend_func:
                    error = str(err)
                    if (
                        error.startswith("Invalid call to pythranized function `")
                        and " (reshaped)" in error
                    ):
                        logger.error(
                            "It seems that a jitted Pythran function has been called "
                            'with a "reshaped" array which is not supported by Pythran.'
                        )
                        raise
                    logger.debug(error)

            if self.compiling or not _COMPILE_JIT:
                return func(*args, **kwargs)

            if (
                self.backend_func
                and error
                and error.startswith("Invalid call to pythranized function `")
            ):
                logger.debug(error)
                logger.info(
                    f"{backend.name_capitalized} function `{func_name}` called with new types."
                )
                logger.debug(
                    "Transonic is going to recompute the function for the new types."
                )
github fluiddyn / transonic / tmp / methods / try_analyze.py View on Github external
func = cls.__dict__[func_name]

    signature = inspect.signature(func)
    types_func = [param.annotation for param in signature.parameters.values()][1:]
    args_func = list(signature.parameters.keys())[1:]

    src = get_source_without_decorator(func)

    tokens = []
    attributes = set()

    using_self = False

    g = tokenize(BytesIO(src.encode("utf-8")).readline)
    for toknum, tokval, a, b, c in g:
        logger.debug((tok_name[toknum], tokval))

        if using_self == "self":
            if toknum == OP and tokval == ".":
                using_self = tokval
                continue
            elif toknum == OP and tokval == ",":
                tokens.append((NAME, "self"))
                using_self = False
            else:
                raise RuntimeError

        if using_self == ".":
            if toknum == NAME and tokval in cls_annotations:
                using_self = False
                tokens.append((NAME, "self_" + tokval))
                attributes.add(tokval)
github fluiddyn / transonic / transonic / justintime.py View on Github external
logger.error(
                            "It seems that a jitted Pythran function has been called "
                            'with a "reshaped" array which is not supported by Pythran.'
                        )
                        raise
                    logger.debug(error)

            if self.compiling or not _COMPILE_JIT:
                return func(*args, **kwargs)

            if (
                self.backend_func
                and error
                and error.startswith("Invalid call to pythranized function `")
            ):
                logger.debug(error)
                logger.info(
                    f"{backend.name_capitalized} function `{func_name}` called with new types."
                )
                logger.debug(
                    "Transonic is going to recompute the function for the new types."
                )

            arg_types = [
                backend.jit.compute_typename_from_object(arg)
                for arg in itertools.chain(args, kwargs.values())
            ]

            backenize_with_new_header(arg_types)
            return func(*args, **kwargs)
github fluiddyn / transonic / transonic / backends / base_jit.py View on Github external
def write_new_header(self, path_backend_header, header, arg_types):
        mpi.barrier()
        if mpi.rank == 0:
            logger.debug(
                f"write {self.name_capitalized} signature in file "
                f"{path_backend_header} with types\n{arg_types}"
            )
            with open(path_backend_header, "w") as file:
                file.write(header)
                file.flush()