def _replayWatcher(connections, dumpPipe): print("Starting replay watcher") collectedGamesThisCycle = 0 MemoryBuffers.clearReplayBuffer() startTimeSelfPlay = time.time() while (True): msg, data = dumpPipe.get() # Data passed from a listener if (msg == Constants.RemoteProtocol.DUMP_REPLAY_DATA_TO_OVERLORD): amountOfGames, states, evals, polices, weights = data MemoryBuffers.addLabelsToReplayBuffer(states, evals, polices) collectedGamesThisCycle += amountOfGames # Display a formatted message cycleProgressMsg = "{} / {}".format( collectedGamesThisCycle, Hyperparameters.AMOUNT_OF_NEW_GAMES_PER_CYCLE) elapsedTime = np.around(time.time() - startTimeSelfPlay, 3) elapsedTimeMsg = "Time: {}".format(elapsedTime) gamesPerSecondMsg = "Games/Sec: {}".format( np.around(collectedGamesThisCycle / elapsedTime, 3)) print(cycleProgressMsg + "\t\t" + elapsedTimeMsg + "\t\t" + gamesPerSecondMsg) # Upon receving sufficent number of games we send a message to all Remote Workers to abort if (collectedGamesThisCycle >= Hyperparameters.AMOUNT_OF_NEW_GAMES_PER_CYCLE): _stopRemoteWorkers(connections) return
def sendToOverlord(overlordConnection, localPipe, amountOfWorkers, endPipe): # Needed in the end when we wish to count the bitmaps import time time.sleep(3) print("Starting init") import StartInit StartInit.init() runningCycle = True amountOfCollectedGames = 0 amountOfCollectedWorkers = 0 collectedVisitedStates = [] while (runningCycle): tupleMsg = localPipe.get() msgType = tupleMsg[0] if (msgType == C.LocalWorkerProtocol.DUMP_TO_REPLAY_BUFFER): _, amountOfGames, states, evals, polices, weights = tupleMsg MemoryBuffers.addLabelsToReplayBuffer(states, evals, polices) amountOfCollectedGames += amountOfGames if (amountOfCollectedGames >= MachineSpecificSettings.GAMES_BATCH_SIZE_TO_OVERLORD): print("Sending to oracle from dataworker") dStates, dEvals, dPolices, dWeights = MemoryBuffers.getAllTrainingData( ) dumpMsg = (amountOfCollectedGames, dStates, dEvals, dPolices, dWeights) overlordConnection.sendMessage( C.RemoteProtocol.DUMP_REPLAY_DATA_TO_OVERLORD, dumpMsg) amountOfCollectedGames = 0 MemoryBuffers.clearReplayBuffer() elif (msgType == C.LocalWorkerProtocol.DUMP_MOST_VISITED_STATES): amountOfCollectedWorkers += 1 _, states = tupleMsg if (amountOfCollectedWorkers >= amountOfWorkers): print("collected states from all local workers: ", len(collectedVisitedStates)) sendMostVisitedStatesToOverlord(overlordConnection, collectedVisitedStates) print("Sent message to all workers") runningCycle = False endPipe.put("Ending by datamanager") print("Ending sending thread")