Esempio n. 1
0
 def _neuron_parameters_are_available_in_loaded_parameters(
         string_parameters, loaded_parameters):
     """
     Check that all parameters in brackets are available in the loaded_parameters dict
     
     E.g:
     string_parameters = "this is a {{ parameter1 }}"
     
     Will return true if the loaded_parameters looks like the following
     loaded_parameters { "parameter1": "a value"}        
     
     :param string_parameters: The string that contains one or more parameters in brace brackets
     :param loaded_parameters: Dict of parameter
     :return: True if all parameters in brackets have an existing key in loaded_parameters dict
     """
     list_parameters_with_brackets = Utils.find_all_matching_brackets(
         string_parameters)
     # remove brackets to keep only the parameter name
     for parameter_with_brackets in list_parameters_with_brackets:
         parameter = Utils.remove_spaces_in_brackets(
             parameter_with_brackets)
         parameter = parameter.replace("{{", "").replace("}}", "")
         if loaded_parameters is None or parameter not in loaded_parameters:
             Utils.print_danger(
                 "The parameter %s is not available in the order" %
                 str(parameter))
             return False
     return True
Esempio n. 2
0
 def start_neuron(cls, neuron, parameters_dict=None):
     """
     Execute each neuron from the received neuron_list.
     Replace parameter if exist in the received dict of parameters_dict
     :param neuron: Neuron object to run
     :param parameters_dict: dict of parameter to load in each neuron if expecting a parameter
     :return: List of the instantiated neurons (no errors detected)
     """
     if neuron.parameters is not None:
         try:
             neuron.parameters = cls._replace_brackets_by_loaded_parameter(
                 neuron.parameters, parameters_dict)
         except NeuronParameterNotAvailable:
             Utils.print_danger(
                 "Missing parameter in neuron %s. Execution skipped" %
                 neuron.name)
             return None
     try:
         instantiated_neuron = NeuronLauncher.launch_neuron(neuron)
     except NeuronExceptions as e:
         Utils.print_danger("ERROR: Fail to execute neuron '%s'. "
                            '%s'
                            ". -> Execution skipped" %
                            (neuron.name, e.message))
         return None
     return instantiated_neuron
Esempio n. 3
0
 def start_neuron(cls, neuron, parameters_dict=dict()):
     """
     Execute each neuron from the received neuron_list.
     Replace parameter if exist in the received dict of parameters_dict
     :param neuron: Neuron object to run
     :param parameters_dict: dict of parameter to load in each neuron if expecting a parameter
     :return: List of the instantiated neurons (no errors detected)
     """
     if neuron.parameters is not None:
         try:
             neuron.parameters = cls._replace_brackets_by_loaded_parameter(
                 neuron.parameters, parameters_dict)
         except NeuronParameterNotAvailable:
             Utils.print_danger(
                 "Missing parameter in neuron %s. Execution skipped" %
                 neuron.name)
             return None
     try:
         instantiated_neuron = NeuronLauncher.launch_neuron(neuron)
     except Exception as e:
         Utils.print_danger(
             f"ERROR: Fail to execute neuron '{neuron.name}'. "
             'e.message'
             ". -> Execution skipped, run with debug flag for more information"
         )
         logger.debug(traceback.format_exc())
         return None
     return instantiated_neuron
Esempio n. 4
0
 def start_neuron(cls, neuron, parameters_dict=None):
     """
     Execute each neuron from the received neuron_list.
     Replace parameter if exist in the received dict of parameters_dict
     :param neuron: Neuron object to run
     :param parameters_dict: dict of parameter to load in each neuron if expecting a parameter
     :return: List of the instantiated neurons (no errors detected)
     """
     if neuron.parameters is not None:
         try:
             neuron.parameters = cls._replace_brackets_by_loaded_parameter(
                 neuron.parameters, parameters_dict)
         except NeuronParameterNotAvailable:
             Utils.print_danger("The neuron %s cannot be launched" %
                                neuron.name)
             return None
     instantiated_neuron = NeuronLauncher.launch_neuron(neuron)
     return instantiated_neuron
Esempio n. 5
0
 def start_neuron(cls, neuron, parameters_dict=dict()):
     """
     Execute each neuron from the received neuron_list.
     Replace parameter if exist in the received dict of parameters_dict
     :param neuron: Neuron object to run
     :param parameters_dict: dict of parameter to load in each neuron if expecting a parameter
     :return: List of the instantiated neurons (no errors detected)
     """
     if neuron.parameters is not None:
         try:
             neuron.parameters = cls._replace_brackets_by_loaded_parameter(neuron.parameters, parameters_dict)
         except NeuronParameterNotAvailable:
             Utils.print_danger("Missing parameter in neuron %s. Execution skipped" % neuron.name)
             return None
     try:
         instantiated_neuron = NeuronLauncher.launch_neuron(neuron)
     except NeuronExceptions as e:
         Utils.print_danger("ERROR: Fail to execute neuron '%s'. "
                            '%s' ". -> Execution skipped" % (neuron.name, e.message))
         return None
     return instantiated_neuron
Esempio n. 6
0
 def _neuron_parameters_are_available_in_loaded_parameters(string_parameters, loaded_parameters):
     """
     Check that all parameters in brackets are available in the loaded_parameters dict
     
     E.g:
     string_parameters = "this is a {{ parameter1 }}"
     
     Will return true if the loaded_parameters looks like the following
     loaded_parameters { "parameter1": "a value"}        
     
     :param string_parameters: The string that contains one or more parameters in brace brackets
     :param loaded_parameters: Dict of parameter
     :return: True if all parameters in brackets have an existing key in loaded_parameters dict
     """
     list_parameters_with_brackets = Utils.find_all_matching_brackets(string_parameters)
     # remove brackets to keep only the parameter name
     for parameter_with_brackets in list_parameters_with_brackets:
         parameter = Utils.remove_spaces_in_brackets(parameter_with_brackets)
         parameter = parameter.replace("{{", "").replace("}}", "")
         if loaded_parameters is None or parameter not in loaded_parameters:
             Utils.print_danger("The parameter %s is not available in the order" % str(parameter))
             return False
     return True
Esempio n. 7
0
    def _start_neuron(neuron, params):
        """
        Associate params and Starts a neuron.

        :param neuron: the neuron to start
        :param params: the params to check and associate to the neuron args.
        """

        problem_in_neuron_found = False
        if isinstance(neuron.parameters, dict):
            # print neuron.parameters
            if "args" in neuron.parameters:
                logger.debug("The neuron waits for parameter")
                # check that the user added parameters to his order
                if params is None:
                    # we don't raise an error and break the program but we don't run the neuron
                    problem_in_neuron_found = True
                    Utils.print_danger(
                        "Error: The neuron %s is waiting for argument. "
                        "Argument found in bracket in the given order" %
                        neuron.name)
                else:
                    # we add wanted arguments the existing neuron parameter dict
                    for arg in neuron.parameters["args"]:
                        if arg in params:
                            logger.debug(
                                "Parameter %s added to the current parameter "
                                "of the neuron: %s" % (arg, neuron.name))
                            neuron.parameters[arg] = params[arg]
                        else:
                            # we don't raise an error and break the program but
                            # we don't run the neuron
                            problem_in_neuron_found = True
                            Utils.print_danger(
                                "Error: Argument \"%s\" not found in the"
                                " order" % arg)

        # if no error detected, we run the neuron
        if not problem_in_neuron_found:
            NeuronLauncher.start_neuron(neuron)
        else:
            Utils.print_danger("A problem has been found in the Synapse.")