def ack(self, tId, peerId, approved): tx = find(PATH['TX_MINE'], tId) if tx is None: # Transaction is not mine # Send acknowledgement to previous peer prev = Protocol(NET_GROUP['PREV']) prev.sendParams('ack', tId, peerId, approved) prev.close() else: # Transaction is mine # Add acknowledgement to the proper ack group handler = AckHandler(PATH['ACKS'], tId) handler.add(peerId, approved) print('Acknowledgement received\n' 'TID:\t\t%d\n' 'From:\t\t%d\n' 'Remaining:\t%d/%d\n' % (tId, peerId, handler.count, PEERS_COUNT)) # If every peer sent their acknowledgements if handler.count == PEERS_COUNT: remove(PATH['TX_MINE'], tId) approved = handler.approved == ACKS_TO_APPROVE # Removes acknowledgements that are no longer needed handler.clear() # Sends commit to everyone self.chaining(('commit', tId, approved))
def chaining(self, params, counter=0, direction='NEXT'): counter += 1 self.execute(params) if counter < PEERS_COUNT: proto = Protocol(NET_GROUP[direction]) proto.sendParams('chaining', params, counter, direction) proto.close()
G=G, tau_z_pre_ampa=tau_z_pre_ampa, tau_z_post_ampa=tau_z_pre_ampa, tau_p=tau_p, z_transfer=False, diagonal_zero=False, strict_maximum=False, perfect=perfect, k_perfect=k_perfect, always_learning=always_learning) # Build the manager manager = NetworkManager(nn=nn, dt=dt, values_to_save=values_to_save) # Build the protocol for training protocol = Protocol() patterns_indexes = [i for i in range(n_patterns)] protocol.simple_protocol(patterns_indexes, training_time=training_time, inter_pulse_interval=inter_pulse_interval, inter_sequence_interval=inter_sequence_interval, epochs=epochs) # Train epoch_history = manager.run_network_protocol(protocol=protocol, verbose=True) z_training = manager.history['z_pre_ampa'] o_training = manager.history['o'] w_training = manager.history['w_ampa'][:, to_pattern, from_pattern] time_training = np.linspace(0, manager.T_total, num=o_training.shape[0]) p = manager.history['p_pre']
from globl import * from network import Protocol import time import uuid proto = Protocol((NET_LOCAL['HOST'], NET_LOCAL['PORT'])) proto.sendParams('chaining', ('transaction', uuid.uuid4().int, time.time(), 10, 1, 2, 1)) proto.close()