Beispiel #1
0
def process():
    """
    Returns
    -------
    errors_occurred : bool
        Flag indicating whether errors occurred during processing
    """

    errors_occurred = False

    # init log dir
    create_report_dir()
    # The handed over parameters seem to be correct, proceed with the main routine
    init_predefined()
    # now proceed to parse all models
    compilation_units = list()
    nestml_files = FrontendConfiguration.get_files()
    if not type(nestml_files) is list:
        nestml_files = [nestml_files]
    for nestml_file in nestml_files:
        parsed_unit = ModelParser.parse_model(nestml_file)
        if parsed_unit is not None:
            compilation_units.append(parsed_unit)
    if len(compilation_units) > 0:
        # generate a list of all neurons
        neurons = list()
        for compilationUnit in compilation_units:
            neurons.extend(compilationUnit.get_neuron_list())
        # check if across two files two neurons with same name have been defined
        CoCosManager.check_not_two_neurons_across_units(compilation_units)
        # now exclude those which are broken, i.e. have errors.
        if not FrontendConfiguration.is_dev:
            for neuron in neurons:
                if Logger.has_errors(neuron):
                    code, message = Messages.get_neuron_contains_errors(
                        neuron.get_name())
                    Logger.log_message(
                        node=neuron,
                        code=code,
                        message=message,
                        error_position=neuron.get_source_position(),
                        log_level=LoggingLevel.INFO)
                    neurons.remove(neuron)
                    errors_occurred = True
        # perform code generation
        _codeGenerator = CodeGenerator.from_target_name(
            FrontendConfiguration.get_target(),
            options=FrontendConfiguration.get_codegen_opts())
        _codeGenerator.generate_code(neurons)
        for neuron in neurons:
            if Logger.has_errors(neuron):
                errors_occurred = True
                break
    if FrontendConfiguration.store_log:
        store_log_to_file()
    return errors_occurred
Beispiel #2
0
    def generate_neurons(self, neurons: List[ASTNode]):
        """
        Generate code for the given neurons.

        :param neurons: a list of neurons.
        :type neurons: List[ASTNode]
        """
        from pynestml.frontend.frontend_configuration import FrontendConfiguration

        for neuron in neurons:
            self.generate_neuron_code(neuron)
            if not Logger.has_errors(neuron):
                code, message = Messages.get_code_generated(neuron.get_name(), FrontendConfiguration.get_target_path())
                Logger.log_message(neuron, code, message, neuron.get_source_position(), LoggingLevel.INFO)
Beispiel #3
0
    def generate_neurons(self, neurons):
        # type: (list(ASTNeuron)) -> None
        """
        Analyse a list of neurons, solve them and generate the corresponding code.
        :param neurons: a list of neurons.
        """
        from pynestml.frontend.frontend_configuration import FrontendConfiguration

        for neuron in neurons:
            self.generate_neuron_code(neuron)
            if not Logger.has_errors(neuron):
                code, message = Messages.get_code_generated(
                    neuron.get_name(), FrontendConfiguration.get_target_path())
                Logger.log_message(neuron, code, message,
                                   neuron.get_source_position(),
                                   LoggingLevel.INFO)
Beispiel #4
0
def main(args):
    try:
        FrontendConfiguration.config(args)
    except InvalidPathException:
        print('Not a valid path to model or directory: "%s"!' %
              FrontendConfiguration.get_path())
        return
    # init log dir
    create_report_dir()
    # The handed over parameters seem to be correct, proceed with the main routine
    init_predefined()
    # now proceed to parse all models
    compilation_units = list()
    for file in FrontendConfiguration.get_files():
        parsed_unit = ModelParser.parse_model(file)
        if parsed_unit is not None:
            compilation_units.append(parsed_unit)
    # generate a list of all neurons
    neurons = list()
    for compilationUnit in compilation_units:
        neurons.extend(compilationUnit.get_neuron_list())
    # check if across two files two neurons with same name have been defined
    CoCosManager.check_not_two_neurons_across_units(compilation_units)
    # now exclude those which are broken, i.e. have errors.
    if not FrontendConfiguration.is_dev():
        for neuron in neurons:
            if Logger.has_errors(neuron):
                code, message = Messages.get_neuron_contains_errors(
                    neuron.get_name())
                Logger.log_message(neuron=neuron,
                                   code=code,
                                   message=message,
                                   error_position=neuron.get_source_position(),
                                   log_level=LoggingLevel.INFO)
                neurons.remove(neuron)
    if not FrontendConfiguration.is_dry_run():
        analyse_and_generate_neurons(neurons)
        generate_nest_module_code(neurons)
    else:
        code, message = Messages.get_dry_run()
        Logger.log_message(neuron=None,
                           code=code,
                           message=message,
                           log_level=LoggingLevel.INFO)
    if FrontendConfiguration.store_log:
        store_log_to_file()
    return