Changeset 1200 for framspy


Ignore:
Timestamp:
02/06/23 20:29:12 (22 months ago)
Author:
Maciej Komosinski
Message:

Make errors during evaluation of creatures Python exceptions so they are more noticeable and consequential

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1199 r1200  
    3232
    3333
    34         # This function is not needed because in python, "For efficiency reasons, each module is only imported once per interpreter session."
     34        # This function is not needed because in Python, "For efficiency reasons, each module is only imported once per interpreter session."
    3535        # @staticmethod
    3636        # def getFramsModuleInstance():
     
    6060                frams.Simulator.expdef = "standard-eval"  # this expdef (or fully compatible) must be used by EVALUATION_SETTINGS_FILE
    6161                if sim_settings_files is not None:
    62                         self.EVALUATION_SETTINGS_FILE = sim_settings_files
     62                        self.EVALUATION_SETTINGS_FILE = sim_settings_files # overwrite defaults
    6363                print('Using settings:', self.EVALUATION_SETTINGS_FILE)
    6464                assert isinstance(self.EVALUATION_SETTINGS_FILE, list)  # ensure settings file(s) are provided as a list
     
    7171                        print(ec.messages) # output all caught messages
    7272                        if ec.error_count._value() > 0:
    73                                 raise ValueError("Problem while importing file '%s'" % simfile) # make missing files or incorrect paths fatal because they would not stop Framsticks from further processing, and error messages are easy to overlook in output
     73                                raise ValueError("Problem while importing file '%s'" % simfile) # make missing files or incorrect paths fatal because error messages are easy to overlook in output, and these errors would not prevent Framsticks simulator from performing genetic operations, starting and running in evaluate()
    7474
    7575
     
    8989                if not self.PRINT_FRAMSTICKS_OUTPUT:
    9090                        ec = frams.MessageCatcher.new()  # mute potential errors, warnings, messages
     91                        ec.store = 2; # store all, because they are caught by MessageCatcher and will not appear on console
    9192
    9293                frams.GenePools[0].clear()
     
    107108
    108109                if not self.PRINT_FRAMSTICKS_OUTPUT:
    109                         if ec.error_count._value() > 0:  # errors are important and should not be ignored, at least display how many
    110                                 print("[ERROR]", ec.error_count, "error(s) and", ec.warning_count-ec.error_count, "warning(s) while evaluating", len(genotype_list), "genotype(s)")
    111110                        ec.close()
     111                        if ec.error_count._value() > 0:
     112                                print(ec.messages) # if errors occurred, output all caught messages for debugging
     113                                raise RuntimeError("[ERROR] %d error(s) and %d warning(s) while evaluating %d genotype(s)" % (ec.error_count._value(), ec.warning_count._value()-ec.error_count._value(), len(genotype_list))) # make errors fatal; by default they stop the simulation anyway so let's not use potentially incorrect or partial results and fix the cause first.
    112114
    113115                results = []
Note: See TracChangeset for help on using the changeset viewer.