Exemplo n.º 1
0
 def __init__(self, compute_module, use_head=False):
     self.compute_imp: ComputeImp = compute_module.ComputeCls
     check_implementation(ComputeInterface, self.compute_imp)
     self.remote_functions = {}
     self.available_nodes = []
     self.use_head = use_head
     self.head_node = None
Exemplo n.º 2
0
    def init_compute(self, compute_module):
        compute_imp = compute_module.ComputeCls

        # Check that all of kernel interface is implemented.
        systems_utils.check_implementation(ComputeInterface, compute_imp)
        if getattr(compute_module, "RNG", None) is None:
            raise Exception("No random number generator implemented "
                            "for compute module %s" % str(compute_module))
        self.rng_cls = compute_module.RNG

        # Collect implemented module functions.
        module_functions = systems_utils.extract_functions(compute_imp)
        # Collect function signatures.
        function_signatures: dict = {}
        required_methods = inspect.getmembers(ComputeInterface(),
                                              predicate=inspect.ismethod)
        for name, func in required_methods:
            function_signatures[name] = func
        for name, func in module_functions.items():
            func_sig = function_signatures[name]
            try:
                remote_params = func_sig.remote_params
            except Exception as _:
                remote_params = {}
            self.register(name, func, remote_params)

        # Add functions as methods of this class.
        for name, _ in module_functions.items():
            self.methods[name] = self.get_callable(name)
Exemplo n.º 3
0
 def __init__(self, compute_module):
     self.compute_module: ModuleType = compute_module
     self.compute_imp = compute_module.ComputeCls
     self.methods: dict = {}
     # Check that all of kernel interface is implemented.
     check_implementation(ComputeInterface, self.compute_imp)
     # Collect implemented module functions.
     self.module_functions = extract_functions(self.compute_imp)
     if getattr(compute_module, "RNG", None) is None:
         raise Exception("No random number generator implemented "
                         "for compute module %s" % str(compute_module))
     self.rng_cls = compute_module.RNG