Changeset 947 for framspy


Ignore:
Timestamp:
06/10/20 10:53:01 (4 years ago)
Author:
Maciej Komosinski
Message:

Added DETERMINISTIC boolean choice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • framspy/FramsticksCLI.py

    r939 r947  
    1212        You can perform basic operations like mutation, crossover, and evaluation of genotypes.
    1313        This way you can perform evolution controlled by python, access and manipulate genotypes.
     14        You can even design and use in evolution your own genetic representation implemented entirely in python.
    1415
    1516        You need to provide one or two parameters when you run this class: the path to Framsticks CLI
     
    1819
    1920        PRINT_FRAMSTICKS_OUTPUT: bool = False  # set to True for debugging
     21        DETERMINISTIC: bool = False  # set to True to have the same results on each run
    2022
    2123        GENO_SAVE_FILE_FORMAT = Enum('GENO_SAVE_FILE_FORMAT', 'NATIVEFRAMS RAWGENO')  # how to save genotypes
     
    9294                assert self.isValid("X[0:0],") == False
    9395                print('OK.')
    94                 self.child.sendline(self.RANDOMIZE_CMD)
     96                if not self.DETERMINISTIC:
     97                        self.child.sendline(self.RANDOMIZE_CMD)
    9598                self.child.sendline(self.SETEXPEDEF_CMD)
    9699
     
    178181                Returns:
    179182                        Dictionary -- genotype evaluated with self.EVALUATE_COMMAND. Note that for whatever reason (e.g. incorrect genotype),
    180                         the dictionary you get may be empty or partially empty and may not have the fields you expected, so handle this case
    181                         properly.
     183                        the dictionary you will get may be empty or partially empty and may not have the fields you expected, so handle such cases properly.
    182184                """
    183185                files = self.__runCommand(self.EVALUATE_CMD, [genotype], self.EVALUATE_FILE, self.GENO_SAVE_FILE_FORMAT["NATIVEFRAMS"])
     
    212214                with open(files[-1]) as f:
    213215                        dissimilarity_matrix = np.genfromtxt(f, dtype=np.float64, comments='#', encoding=None, delimiter='\t')
    214                 # we would like to skip column #1 while reading and read everything else, but... https://stackoverflow.com/questions/36091686/exclude-columns-from-genfromtxt-with-numpy
    215                 # too complicated, so strings in column #1 become NaN as floats (unless they
    216                 # accidentally are numbers?) - not great, not terrible
     216                # We would like to skip column #1 while reading and read everything else, but... https://stackoverflow.com/questions/36091686/exclude-columns-from-genfromtxt-with-numpy
     217                # This would be too complicated, so strings (names) in column #1 become NaN as floats (unless they accidentally are valid numbers) - not great, not terrible
    217218                EXPECTED_SHAPE = (2, 4)
    218219                assert dissimilarity_matrix.shape == EXPECTED_SHAPE, f"Not a correct dissimilarity matrix, expected {EXPECTED_SHAPE} "
     
    249250if __name__ == "__main__":
    250251        # A demo run.
     252
     253        # TODO ideas:
     254        # - check_validity with three levels (invalid, corrected, valid)
     255        # - use threads for non-blocking reading from frams' stdout and thus not relying on specific strings printed by frams
     256        # - a pool of binaries run at the same time, balance load - in particular evaluation
     257        # - if we read genotypes in "org:" format anywhere: import https://pypi.org/project/framsreader/0.1.2/ and use it if successful,
     258        #    if not then print a message "framsreader not available, using simple internal method to save a genotype" and proceed as it is now.
     259        #    So far we don't read, but we should use the proper writer to handle all special cases like quoting etc.
     260
    251261        parsed_args = parseArguments()
    252262        framsCLI = FramsticksCLI(parsed_args.path, parsed_args.exe)
Note: See TracChangeset for help on using the changeset viewer.