Exemplo n.º 1
0
def main():
    # Parse input
    dir_path = sys.argv[1]
    train_instances_file_name = os.path.join(dir_path, 'subflow_data.pickle')
    runs = eval(sys.argv[4])
    # construct socket to communicate with backend
    send_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    send_sock.connect((sys.argv[2], int(sys.argv[3])))
    try:
        flow_ids = eval(sys.argv[5])
        for flow_id in flow_ids:
            flow_file_name = os.path.join(dir_path, flow_id + '.pickle')
            # Unpickle the flow and train_instances
            with open(flow_file_name, 'rb') as flow_file:
                flow = pickle.load(flow_file)
            with open(train_instances_file_name, 'rb') as train_instances_file:
                train_instances = pickle.load(train_instances_file)
            try:
                # Execute the flow
                # .. note:: the here executed flows can not store anything
                #           meta data of result collection is NOT updated!
                _, result_collection = flow(train_instances=train_instances,
                                            runs=runs)
                # Store results
                result_file_name = flow_file_name.replace(
                    '.pickle', '_result.pickle')
                with open(result_file_name, 'wb') as result_file:
                    pickle.dump(result_collection,
                                result_file,
                                protocol=pickle.HIGHEST_PROTOCOL)
            finally:
                # Delete the flow_file since we don't need it any more
                # training_file is may be used by other flows so don't delete it
                os.remove(flow_file_name)
                # Inform Backend that this flow has finished
                send_sock = LoadLevelerComHandler(
                    send_sock, sys.argv[2], int(sys.argv[3]),
                    LoadLevelerComHandler.MESSAGES.FINISHED, flow_id)
        # give backend some time to get information
        time.sleep(1)
    finally:
        send_sock.shutdown(socket.SHUT_RDWR)
        send_sock.close()
Exemplo n.º 2
0
def main():
    # Parse input
    dir_path = sys.argv[1]
    train_instances_file_name = os.path.join(dir_path,
                                             'subflow_data.pickle')
    runs = eval(sys.argv[4])
    # construct socket to communicate with backend
    send_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    send_sock.connect((sys.argv[2], int(sys.argv[3])))
    try:
        flow_ids = eval(sys.argv[5])
        for flow_id in flow_ids:
            flow_file_name = os.path.join(dir_path, flow_id + '.pickle')
            # Unpickle the flow and train_instances
            with open(flow_file_name, 'rb') as flow_file:
                flow = pickle.load(flow_file)
            with open(train_instances_file_name, 'rb') as train_instances_file:
                train_instances = pickle.load(train_instances_file)
            try:
                # Execute the flow
                # .. note:: the here executed flows can not store anything
                #           meta data of result collection is NOT updated!
                _, result_collection = flow(train_instances=train_instances, runs=runs)
                # Store results
                result_file_name = flow_file_name.replace('.pickle', '_result.pickle')
                with open(result_file_name, 'wb') as result_file:
                    pickle.dump(result_collection, result_file, protocol=pickle.HIGHEST_PROTOCOL)
            finally:
                # Delete the flow_file since we don't need it any more
                # training_file is may be used by other flows so don't delete it
                os.remove(flow_file_name)
                # Inform Backend that this flow has finished
                send_sock = LoadLevelerComHandler(send_sock, sys.argv[2], int(sys.argv[3]),
                                                  LoadLevelerComHandler.MESSAGES.FINISHED, flow_id)
        # give backend some time to get information
        time.sleep(1)
    finally:
        send_sock.shutdown(socket.SHUT_RDWR)
        send_sock.close()