Changeset 1084 for framspy


Ignore:
Timestamp:
02/18/21 19:06:53 (3 years ago)
Author:
Maciej Komosinski
Message:

Introduced bool PRINT_FRAMSTICKS_OUTPUT to mute messages while evaluating creatures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksLib.py

    r1081 r1084  
    1818                FramsticksLib.py -h"""
    1919
     20        PRINT_FRAMSTICKS_OUTPUT: bool = False  # set to True for debugging
    2021        DETERMINISTIC: bool = False  # set to True to have the same results in each run
    2122
     
    2425
    2526
    26         def __init__(self, framspath, framsexe, pid=""):
    27                 self.pid = pid if pid is not None else ""
    28                 self.frams_path = framspath
    29                 self.frams_exe = framsexe if framsexe is not None else 'frams.exe' if os.name == "nt" else 'frams.linux'
    30                 self.writing_path = None
    31                 mainpath = os.path.join(self.frams_path, self.frams_exe)
    32                 # exe_call = [mainpath, '-Q', '-s', '-c', '-icliutils.ini']  # -c will be ignored in Windows Framsticks (this option is meaningless because the Windows version does not support color console, so no need to deactivate this feature using -c)
    33                 # exe_call_to_get_version = [mainpath, '-V']
    34                 # exe_call_to_get_path = [mainpath, '-?']
    35 
    36                 frams.init(framspath, "-Ddata")  # "-D"+os.path.join(framspath,"data")) # not possible (maybe python windows issue) because of the need for os.chdir(). So we assume "data" is where the dll/so is
     27        def __init__(self, frams_path, frams_lib_name):
     28                frams.init(frams_path, frams_lib_name, "-Ddata")  # "-D"+os.path.join(frams_path,"data")) # not possible (maybe python windows issue) because of the need for os.chdir(). So we assume "data" is where the dll/so is
    3729
    3830                print('Available objects:', dir(frams))
    3931                print()
    4032
    41                 self.__spawnFramsticksCLI()
    42 
    43 
    44         def __spawnFramsticksCLI(self):
    4533                print('Performing a basic test 1/2... ', end='')
    4634                simplest = self.getSimplest("1")
     
    6856                assert isinstance(genotype_list, list)  # because in python str has similar capabilities as list and here it would pretend to work too, so to avoid any ambiguity
    6957
    70                 # TODO use Logger to mute stdout (optinally just like in FramsticksCLI.py)
     58                if not self.PRINT_FRAMSTICKS_OUTPUT:
     59                        ec = frams.MessageCatcher.new()  # mute potential errors, warnings, messages
     60
    7161                frams.GenePools[0].clear()
    7262                frams.Simulator.ximport(self.EVALUATION_SETTINGS_FILE, 2 + 4 + 8 + 16)
     
    7969                while frams.Simulator.running._int():  # standard-eval.expdef sets running to 0 when the evaluation is complete
    8070                        step()
     71
     72                if not self.PRINT_FRAMSTICKS_OUTPUT:
     73                        if ec.error_count._value() > 0:  # errors are important and should not be ignored, at least display how many
     74                                print("[ERROR]", ec.error_count, "error(s) and", ec.warning_count, "warning(s) while evaluating", len(genotype_list), "genotype(s)")
     75                        ec.close()
    8176
    8277                results = []
     
    150145def parseArguments():
    151146        parser = argparse.ArgumentParser(description='Run this program with "python -u %s" if you want to disable buffering of its output.' % sys.argv[0])
    152         parser.add_argument('-path', type=ensureDir, required=True, help='Path to Framsticks CLI without trailing slash.')
    153         parser.add_argument('-exe', required=False, help='Library name. If not given, "frams.dll" or "frams.so" is assumed depending on the platform.')  # TODO dll,so, allow to change name?
     147        parser.add_argument('-path', type=ensureDir, required=True, help='Path to the Framsticks library (.dll or .so) without trailing slash.')
     148        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.')
    154149        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.')
    155150        return parser.parse_args()
     
    171166
    172167        parsed_args = parseArguments()
    173         framsDLL = FramsticksLib(parsed_args.path, parsed_args.exe, None)  # parsed_args.pid)
     168        framsDLL = FramsticksLib(parsed_args.path, parsed_args.lib)
    174169
    175170        print("Sending a direct command to Framsticks CLI that calculates \"4\"+2 yields", frams.Simulator.eval("return \"4\"+2;"))
Note: See TracChangeset for help on using the changeset viewer.