Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from transonic.justintime import _get_module_jit
mod = _get_module_jit(backend_name=backend.name, index_frame=5)
if mpi.rank == 0:
python_path = mpi.PathSeq(python_path)
python_code = (
mod.info_analysis["codes_dependance_classes"][cls_name] + "\n"
)
python_code += backend.jit.produce_code_class(cls)
write_if_has_to_write(python_path, python_code)
python_path = mpi.Path(python_path)
mpi.barrier()
# 2. import the file
python_mod_name = path_jit_class.name + "." + mod_name + "." + cls_name
module = import_from_path(python_path, python_mod_name)
# 3. replace the methods
for name_method, method in jit_methods.items():
func = method.func
name_new_method = f"__new_method__{cls.__name__}__{name_method}"
new_method = getattr(module, name_new_method)
setattr(cls, name_method, functools.wraps(func)(new_method))
return cls
def reload_module_backend(self, module_backend_name=None):
if module_backend_name is None:
module_backend_name = self.module_backend.__name__
if self.path_extension.exists() and not self.is_compiling:
self.module_backend = import_from_path(
self.path_extension, module_backend_name
)
elif self.path_backend.exists():
self.module_backend = import_from_path(
self.path_backend, module_backend_name
)
else:
self.is_transpiled = False
self.is_compiled = False
----------
name : str
The name of the block.
"""
if not self.is_transpiled:
raise ValueError(
"`use_block` has to be used protected by `if ts.is_transpiled`"
)
if self.is_compiling and not self.process.is_alive(raise_if_error=True):
self.is_compiling = False
time.sleep(0.1)
self.module_backend = import_from_path(
self.path_extension, self.module_backend.__name__
)
assert self.backend.check_if_compiled(self.module_backend)
self.is_compiled = True
func = getattr(self.module_backend, name)
argument_names = self.arguments_blocks[name]
frame = inspect.currentframe()
try:
locals_caller = frame.f_back.f_locals
finally:
del frame
arguments = [locals_caller[name] for name in argument_names]
return func(*arguments)
+ hex_header
+ backend.suffix_extension
)
self.path_extension = path_backend.with_name(name_ext_file)
self.compiling, self.process = backend.compile_extension(
path_backend,
name_ext_file,
native=self.native,
xsimd=self.xsimd,
openmp=self.openmp,
)
# for backend like numba
if not self.compiling:
backend_module = import_from_path(self.path_extension, name_mod)
assert backend.check_if_compiled(backend_module)
self.backend_func = getattr(backend_module, func_name)
def reload_module_backend(self, module_backend_name=None):
if module_backend_name is None:
module_backend_name = self.module_backend.__name__
if self.path_extension.exists() and not self.is_compiling:
self.module_backend = import_from_path(
self.path_extension, module_backend_name
)
elif self.path_backend.exists():
self.module_backend = import_from_path(
self.path_backend, module_backend_name
)
else:
self.is_transpiled = False
self.is_compiled = False