def test_read_blob_sequences(self): res = data_provider_pb2.ReadBlobSequencesResponse() run = res.runs.add(run_name="test") tag = run.tags.add(tag_name="input_image") tag.data.step.extend([0, 1]) tag.data.wall_time.extend([1234.0, 1235.0]) seq0 = tag.data.values.add() seq0.blob_refs.add(blob_key="step0img0") seq0.blob_refs.add(blob_key="step0img1") seq1 = tag.data.values.add() seq1.blob_refs.add(blob_key="step1img0") self.stub.ReadBlobSequences.return_value = res actual = self.provider.read_blob_sequences( self.ctx, experiment_id="123", plugin_name="images", run_tag_filter=provider.RunTagFilter(runs=["test", "nope"]), downsample=4, ) expected = { "test": { "input_image": [ provider.BlobSequenceDatum( step=0, wall_time=1234.0, values=( provider.BlobReference(blob_key="step0img0"), provider.BlobReference(blob_key="step0img1"), ), ), provider.BlobSequenceDatum( step=1, wall_time=1235.0, values=(provider.BlobReference( blob_key="step1img0"), ), ), ], }, } self.assertEqual(actual, expected) req = data_provider_pb2.ReadBlobSequencesRequest() req.experiment_id = "123" req.plugin_filter.plugin_name = "images" req.run_tag_filter.runs.names.extend(["nope", "test"]) # sorted req.downsample.num_points = 4 self.stub.ReadBlobSequences.assert_called_once_with(req)
def read_blob_sequences( self, ctx, experiment_id, plugin_name, downsample=None, run_tag_filter=None, ): with timing.log_latency("build request"): req = data_provider_pb2.ReadBlobSequencesRequest() req.experiment_id = experiment_id req.plugin_filter.plugin_name = plugin_name _populate_rtf(run_tag_filter, req.run_tag_filter) req.downsample.num_points = downsample with timing.log_latency("_stub.ReadBlobSequences"): with _translate_grpc_error(): res = self._stub.ReadBlobSequences(req) with timing.log_latency("build result"): result = {} for run_entry in res.runs: tags = {} result[run_entry.run_name] = tags for tag_entry in run_entry.tags: series = [] tags[tag_entry.tag_name] = series d = tag_entry.data for (step, wt, blob_sequence) in zip( d.step, d.wall_time, d.values ): values = [] for ref in blob_sequence.blob_refs: values.append( provider.BlobReference( blob_key=ref.blob_key, url=ref.url or None ) ) point = provider.BlobSequenceDatum( step=step, wall_time=wt, values=tuple(values) ) series.append(point) return result