- Timestamp:
- 06/10/20 10:53:01 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
framspy/FramsticksCLI.py
r939 r947 12 12 You can perform basic operations like mutation, crossover, and evaluation of genotypes. 13 13 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. 14 15 15 16 You need to provide one or two parameters when you run this class: the path to Framsticks CLI … … 18 19 19 20 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 20 22 21 23 GENO_SAVE_FILE_FORMAT = Enum('GENO_SAVE_FILE_FORMAT', 'NATIVEFRAMS RAWGENO') # how to save genotypes … … 92 94 assert self.isValid("X[0:0],") == False 93 95 print('OK.') 94 self.child.sendline(self.RANDOMIZE_CMD) 96 if not self.DETERMINISTIC: 97 self.child.sendline(self.RANDOMIZE_CMD) 95 98 self.child.sendline(self.SETEXPEDEF_CMD) 96 99 … … 178 181 Returns: 179 182 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. 182 184 """ 183 185 files = self.__runCommand(self.EVALUATE_CMD, [genotype], self.EVALUATE_FILE, self.GENO_SAVE_FILE_FORMAT["NATIVEFRAMS"]) … … 212 214 with open(files[-1]) as f: 213 215 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 217 218 EXPECTED_SHAPE = (2, 4) 218 219 assert dissimilarity_matrix.shape == EXPECTED_SHAPE, f"Not a correct dissimilarity matrix, expected {EXPECTED_SHAPE} " … … 249 250 if __name__ == "__main__": 250 251 # 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 251 261 parsed_args = parseArguments() 252 262 framsCLI = FramsticksCLI(parsed_args.path, parsed_args.exe)
Note: See TracChangeset
for help on using the changeset viewer.