def testQueryInvalidTimeIndex(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data = np.array([[1, 2], [3, 4]]) store.add(watch_key, data) with self.assertRaises(IndexError): store.query("A:0:DebugIdentity", time_indices="10")
def __init__(self, receive_port): """Receives health pills from a debugger and writes them to disk. Args: receive_port: The port at which to receive health pills from the TensorFlow debugger. always_flush: A boolean indicating whether the EventsWriter will be flushed after every write. Can be used for testing. """ super(InteractiveDebuggerDataServer, self).__init__( receive_port, InteractiveDebuggerDataStreamHandler ) self._incoming_channel = queue.Queue() self._outgoing_channel = comm_channel_lib.CommChannel() self._run_states = RunStates(breakpoints_func=lambda: self.breakpoints) self._tensor_store = tensor_store_lib.TensorStore() self._source_manager = SourceManager() curried_handler_constructor = functools.partial( InteractiveDebuggerDataStreamHandler, self._incoming_channel, self._outgoing_channel, self._run_states, self._tensor_store, ) grpc_debug_server.EventListenerBaseServicer.__init__( self, receive_port, curried_handler_constructor )
def testQueryNonexistentWatchKey(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data = np.array([[1, 2], [3, 4]]) store.add(watch_key, data) with self.assertRaises(KeyError): store.query("B:0:DebugIdentity")
def testQuery1DTensorHistoryWithImagePngMapping(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" store.add(watch_key, np.array([0, 2, 4, 6, 8])) store.add(watch_key, np.array([1, 3, 5, 7, 9])) output = store.query(watch_key, time_indices=":", mapping="image/png") decoded = im_util.decode_png(base64.b64decode(output)) self.assertEqual((2, 5, 3), decoded.shape)
def testQeuryWithTimeIndicesAllRange(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" store.add(watch_key, np.array(1)) store.add(watch_key, np.array(3)) store.add(watch_key, np.array(3)) store.add(watch_key, np.array(7)) self.assertAllClose([1, 3, 3, 7], store.query(watch_key, time_indices=":"))
def testQeuryWithTimeIndicesStopAndStep(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" store.add(watch_key, np.array(1)) store.add(watch_key, np.array(3)) store.add(watch_key, np.array(3)) store.add(watch_key, np.array(7)) self.assertAllClose([3, 7], store.query(watch_key, time_indices='1::2'))
def testQueryMultipleTensorsAtOnce(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data1 = np.array([[1, 2], [3, 4]]) data2 = np.array([[-1, -2], [-3, -4]]) store.add(watch_key, data1) store.add(watch_key, data2) self.assertAllClose([[[1, 2], [3, 4]], [[-1, -2], [-3, -4]]], store.query(watch_key, time_indices='[0:2]'))
def testAddAndQueryMultipleTensorForSameWatchKeyWithSlicing(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data1 = np.array([[1, 2], [3, 4]]) data2 = np.array([[-1, -2], [-3, -4]]) store.add(watch_key, data1) store.add(watch_key, data2) self.assertAllClose( [[2, 4], [-2, -4]], store.query(watch_key, time_indices="0:2", slicing="[:,1]"), )
def testAddAndQueryMultipleTensorForSameWatchKey(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data1 = np.array([[1, 2], [3, 4]]) data2 = np.array([[-1, -2], [-3, -4]]) store.add(watch_key, data1) store.add(watch_key, data2) self.assertAllClose([data2], store.query(watch_key)) self.assertAllClose([data1], store.query(watch_key, time_indices="0")) self.assertAllClose([data2], store.query(watch_key, time_indices="1")) self.assertAllClose([data2], store.query(watch_key, time_indices="-1"))
def testTensorValuesExceedingMemBytesLimitAreDiscarded(self): store = tensor_store.TensorStore(watch_mem_bytes_limit=150) watch_key = "A:0:DebugIdentity" value = np.eye(3, dtype=np.float64) self.assertEqual(72, value.nbytes) store.add(watch_key, value) self.assertAllEqual([value], store.query(watch_key, time_indices=":")) store.add(watch_key, value * 2) self.assertAllEqual([value, value * 2], store.query(watch_key, time_indices=":")) store.add(watch_key, value * 3) result = store.query(watch_key, time_indices=":") self.assertIsNone(result[0]) self.assertAllEqual([value * 2, value * 3], result[1:])
def testAddAndQuerySingleTensorWithSlicing(self): store = tensor_store.TensorStore() watch_key = "A:0:DebugIdentity" data = np.array([[1, 2], [3, 4]]) store.add(watch_key, data) self.assertAllClose([[2, 4]], store.query(watch_key, slicing="[:, 1]"))