Ignore:
Timestamp:
02/01/23 23:03:50 (15 months ago)
Author:
Maciej Komosinski
Message:

When importing *.sim files, make problems fatal because error messages are easy to overlook in output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1177 r1196  
    88
    99class FramsticksLib:
    10         """Communicates directly with Framsticks library (.dll or .so).
     10        """Communicates directly with Framsticks library (.dll or .so or .dylib).
    1111        You can perform basic operations like mutation, crossover, and evaluation of genotypes.
    1212        This way you can perform evolution controlled by python as well as access and manipulate genotypes.
     
    1616        Should you want to modify or extend this class, first see and test the examples in frams-test.py.
    1717
    18         You need to provide one or two parameters when you run this class: the path to Framsticks where .dll/.so resides
    19         and, optionally, the name of the Framsticks dll/so (if it is non-standard). See::
     18        You need to provide one or two parameters when you run this class: the path to Framsticks where .dll/.so/.dylib resides
     19        and, optionally, the name of the Framsticks dll/so/dylib (if it is non-standard). See::
    2020                FramsticksLib.py -h"""
    2121
     
    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
     65               
    6566                for simfile in self.EVALUATION_SETTINGS_FILE:
     67                        ec = frams.MessageCatcher.new()  # catch potential errors, warnings, messages - just to detect if there are ERRORs
     68                        ec.store = 2; # store all, because they are caught by MessageCatcher and will not appear on console (which we want)
    6669                        frams.Simulator.ximport(simfile, 4 + 8 + 16)
     70                        ec.close()
     71                        print(ec.messages) # output all caught messages
     72                        assert ec.error_count._value() == 0, "Problem while importing file '%s'" % simfile # make missing files fatal because error messages are easy to overlook
    6773
    6874
     
    101107                if not self.PRINT_FRAMSTICKS_OUTPUT:
    102108                        if ec.error_count._value() > 0:  # errors are important and should not be ignored, at least display how many
    103                                 print("[ERROR]", ec.error_count, "error(s) and", ec.warning_count, "warning(s) while evaluating", len(genotype_list), "genotype(s)")
     109                                print("[ERROR]", ec.error_count, "error(s) and", ec.warning_count-ec.error_count, "warning(s) while evaluating", len(genotype_list), "genotype(s)")
    104110                        ec.close()
    105111
     
    198204def parseArguments():
    199205        parser = argparse.ArgumentParser(description='Run this program with "python -u %s" if you want to disable buffering of its output.' % sys.argv[0])
    200         parser.add_argument('-path', type=ensureDir, required=True, help='Path to the Framsticks library (.dll or .so) without trailing slash.')
    201         parser.add_argument('-lib', required=False, help='Library name. If not given, "frams-objects.dll" or "frams-objects.so" is assumed depending on the platform.')
     206        parser.add_argument('-path', type=ensureDir, required=True, help='Path to the Framsticks library (.dll or .so or .dylib) without trailing slash.')
     207        parser.add_argument('-lib', required=False, help='Library name. If not given, "frams-objects.dll" (or .so or .dylib) is assumed depending on the platform.')
    202208        parser.add_argument('-simsettings', required=False, help='The name of the .sim file with settings for evaluation, mutation, crossover, and similarity estimation. If not given, "eval-allcriteria.sim" is assumed by default. Must be compatible with the "standard-eval" expdef.')
    203209        parser.add_argument('-genformat', required=False, help='Genetic format for the demo run, for example 4, 9, or S. If not given, f1 is assumed.')
Note: See TracChangeset for help on using the changeset viewer.