def test_execute_decompress_elias_code_omega(self, mocked_elias_decompress, mocked_elias_compress, mocked_lzw_decompress, mocked_lzw_compress, mocked_default_write_file, mocked_code_type): command = _decompress_command code_type = _omega_code_type divergence_str = None mocked_default_write_file.return_value = _write_file_path arguments = _get_arguments_dict(False, True, _read_file_path, None, False, True, divergence_str, code_type) execution.execute(arguments) self.assertFalse(mocked_code_type.called) mocked_default_write_file.assert_called_with(_read_file_path, command) self.assertFalse(mocked_lzw_compress.called) self.assertFalse(mocked_lzw_decompress.called) self.assertFalse(mocked_elias_compress.called) mocked_elias_decompress.assert_called_with(_read_file_path, _write_file_path, code_type=code_type)
def test_execute_compress_write_file_elias_divergence(self, mocked_elias_decompress, mocked_elias_compress, mocked_lzw_decompress, mocked_lzw_compress, mocked_default_write_file, mocked_code_type): code_type = _test_code_type divergence_str = _specified_divergence_str divergence = _specified_divergence mocked_default_write_file.return_value = _write_file_path mocked_code_type.return_value = code_type arguments = _get_arguments_dict(True, False, _read_file_path, _write_file_path, False, True, divergence_str, None) execution.execute(arguments) mocked_code_type.assert_called_with(_read_file_path, distribution_divergence=divergence) self.assertFalse(mocked_default_write_file.called) self.assertFalse(mocked_lzw_compress.called) self.assertFalse(mocked_lzw_decompress.called) mocked_elias_compress.assert_called_with(_read_file_path, _write_file_path, code_type=code_type) self.assertFalse(mocked_elias_decompress.called)
def test_execute_decompress_write_file_lzw(self, mocked_elias_decompress, mocked_elias_compress, mocked_lzw_decompress, mocked_lzw_compress, mocked_default_write_file): arguments = _get_arguments_dict(False, True, _read_file_path, _write_file_path, True, False, None, None) execution.execute(arguments) self.assertFalse(mocked_default_write_file.called) self.assertFalse(mocked_lzw_compress.called) mocked_lzw_decompress.assert_called_with(_read_file_path, _write_file_path) self.assertFalse(mocked_elias_compress.called) self.assertFalse(mocked_elias_decompress.called)
def test_execute_compress_lzw(self, mocked_elias_decompress, mocked_elias_compress, mocked_lzw_decompress, mocked_lzw_compress, mocked_default_write_file): command = _compress_command mocked_default_write_file.return_value = _write_file_path arguments = _get_arguments_dict(True, False, _read_file_path, None, True, False, None, None) execution.execute(arguments) mocked_default_write_file.assert_called_with(_read_file_path, command) mocked_lzw_compress.assert_called_with(_read_file_path, _write_file_path) self.assertFalse(mocked_lzw_decompress.called) self.assertFalse(mocked_elias_compress.called) self.assertFalse(mocked_elias_decompress.called)
def main(): # execute_parsed_program() # execute_compiler() # execute_random_program() # try: parser = argparse.ArgumentParser() parser.add_argument('program') parser.add_argument('statuses', nargs='+') associations = exact_associations # By default use exact associations/gates parser.add_argument('-a', '--approximate', action="store_true", help="Use approximate gates.") parser.add_argument('-e', '--exact', action="store_true", help="Use exact gates.") args = parser.parse_args() if (args.approximate): associations = approximate_associations #Can change default associations/gates if (args.exact): associations = exact_associations #Can change default associations/gates with open(args.program) as file: quantum_program = file.read() for status_file_name in args.statuses: #it was a file name with open(status_file_name) as status_file: # print status_file_name status = status_file.read() execute(quantum_program, status, associations)
def execute(args): if (args.colourDistribution == ''): path = args.relationship + "/" + args.method + "/" else: path = args.relationship + "/" + args.method + "/" + args.colourDistribution + "/" + str( args.static) + "/" #paths to store results imagePath = "out/results/" + path csvPath = "out/csv/" + path jsonPath = "out/json/" + path for i in range(args.i): if (args.relationship == "colours"): if os.path.exists("out/dcel_pS_c") and os.path.exists( "out/polygons_pS_c"): with open("out/dcel_pS_c", "rb") as read_file: dcel = pickle.load(read_file) read_file.close() with open("out/polygons_pS_c", "rb") as read_file: polygons = pickle.load(read_file) read_file.close() else: dcel, polygons = pre_execute(args.maxExecs, args.relationship, args.colourDistribution) else: if os.path.exists("out/dcel_pS") and os.path.exists( "out/polygons_pS"): with open("out/dcel_pS", "rb") as read_file: dcel = pickle.load(read_file) read_file.close() with open("out/polygons_pS", "rb") as read_file: polygons = pickle.load(read_file) read_file.close() else: dcel, polygons = pre_execute(args.maxExecs, args.relationship, args.colourDistribution) start = time.time() bestPSet, bestSD, bestsDs, sDs, temps, its, acceptance = execution.execute( dcel, polygons, args.l, args.r, args.maxExecs, args.minR, args.maxR, args.relationship, args.method, args.colourDistribution, args.static, imagePath, i) end = time.time() print("\t\texecution nº:" + str(i) + " finished") accepted = acceptance.count(1) denied = acceptance.count(0) #save results with open(csvPath + 'result.csv', 'a') as f: fnames = [ 'relationship', 'method', 'colourDistribution', 'static', 'l', 'r', 'maxExecsPS', 'result', 'p_acc', 'p_den', 'time' ] writer = csv.DictWriter(f, fieldnames=fnames) #writer.writeheader() #new file writer.writerow({ 'relationship': args.relationship, 'method': args.method, 'colourDistribution': args.colourDistribution, 'static': str(args.static), 'l': str(args.l), 'r': str(args.r), 'maxExecsPS': str(args.maxExecs), 'result': str(bestSD), 'p_acc': str(accepted / (accepted + denied)), 'p_den': str(denied / (accepted + denied)), 'time': str(end - start) }) with open(csvPath + str(bestSD) + ".csv", 'a') as f: fnames = ['temp', 'it', 'bestsd', 'sd', 'acc'] writer = csv.DictWriter(f, fieldnames=fnames) writer.writeheader() for temp, it, bestsd, sd, acc in zip(temps, its, bestsDs, sDs, acceptance): writer.writerow({ 'temp': str(temp), 'it': str(it), 'bestsd': str(bestsd), 'sd': str(sd), 'acc': str(acc) }) #save points with open(jsonPath + str(bestSD) + ".json", "w") as write_file: json.dump(bestPSet, write_file, indent=4)
def execute_files(settings_files): for settings in load_settings(settings_files): execute(settings)
from execution import execute how_deep = int(input("URL 얼마나 깊이 볼까 ? : ")) Url = input("URL을 입력하세요 : ") Keyword = input("아니 시발 도대체 무슨 키워드를 알고싶은건데?? : ") option = int(input("옵션정보 입력 (1 : 2) : ")) execute(Url, how_deep, Keyword, option)
from execution import execute # fill in the directory where the input file (with feature vectors) is located in_dir = "/Users/Tristan/Downloads/data/" # fill in the directory where you want the output to be saved out_dir = '/Users/Tristan/Downloads/data' #some dir # Put the algorithms that you want to train in the following list # Options: SVM, CART, RF LR, XGBoost, COX, survSVM, GBS algorithms = ['LR', 'RF'] # Choose whether you want to use feature selection (True/False) feature_selection = True # Specify whether the algorithms you want to test are binary or survival (can not do both at the same time) survival = False # Specify the column that identies each unique patient record_id = 'ID' # Specify whether you want to use oversampling (only for binary) oversampling = False # Specify whether you want to use undersampling (only for binary) undersampling = False execute(in_dir, out_dir, record_id, algorithms, feature_selection, survival, oversampling, undersampling)
"""Compressor. Usage: compressor.py compress <read_file> [-o <write_file>] [--lzw|--elias [--divergence <divergence>|--code <code>]] compressor.py decompress <read_file> [-o <write_file>] (--lzw|--elias --code <code>) Options: --help Show this screen. --version Show version. -o Specify output file. --lzw Use lzw algorithm. --elias Use elias codes. -d --divergence=<divergence> Specify characters distribution divergence. --code=<code> Specify elias code type. --hp Use hyper-threading for high performance. """ from docopt import docopt import execution if __name__ == '__main__': arguments = docopt(__doc__, version='Compressor 1.0') print(arguments) try: execution.execute(arguments) except Exception as e: print(e.args)