def execute(self, server_info, channel): api_client = export_service_pb2_grpc.TensorBoardExporterServiceStub( channel) fieldmask = experiment_pb2.ExperimentMask( name=True, description=True, create_time=True, update_time=True, num_runs=True, num_tags=True, num_scalars=True, total_tensor_bytes=True, total_blob_bytes=True, ) gen = exporter_lib.list_experiments(api_client, fieldmask=fieldmask) count = 0 if self.json: formatter = formatters.JsonFormatter() else: formatter = formatters.ReadableFormatter() for experiment in gen: count += 1 experiment_id = experiment.experiment_id url = server_info_lib.experiment_url(server_info, experiment_id) print(formatter.format_experiment(experiment, url)) sys.stdout.flush() if not count: sys.stderr.write( "No experiments. Use `tensorboard dev upload` to get started.\n" ) else: sys.stderr.write("Total: %d experiment(s)\n" % count) sys.stderr.flush()
def test_mixed_experiments_and_ids(self): mock_api_client = _create_mock_api_client() def stream_experiments(request, **kwargs): del request # unused # Should include `experiment_ids` when no `experiments` given. response = export_service_pb2.StreamExperimentsResponse() response.experiment_ids.append("123") response.experiment_ids.append("456") yield response # Should ignore `experiment_ids` in the presence of `experiments`. response = export_service_pb2.StreamExperimentsResponse() response.experiment_ids.append("999") # will be omitted response.experiments.add(experiment_id="789") response.experiments.add(experiment_id="012") yield response # Should include `experiments` even when no `experiment_ids` are given. response = export_service_pb2.StreamExperimentsResponse() response.experiments.add(experiment_id="345") response.experiments.add(experiment_id="678") yield response mock_api_client.StreamExperiments = mock.Mock(wraps=stream_experiments) gen = exporter_lib.list_experiments(mock_api_client) mock_api_client.StreamExperiments.assert_not_called() self.assertEqual(list(gen), ["123", "456", "789", "012", "345", "678"])
def test_experiment_ids_only(self): mock_api_client = _create_mock_api_client() def stream_experiments(request, **kwargs): del request # unused yield export_service_pb2.StreamExperimentsResponse( experiment_ids=["123", "456"]) yield export_service_pb2.StreamExperimentsResponse( experiment_ids=["789"]) mock_api_client.StreamExperiments = mock.Mock(wraps=stream_experiments) gen = exporter_lib.list_experiments(mock_api_client) mock_api_client.StreamExperiments.assert_not_called() self.assertEqual(list(gen), ["123", "456", "789"])
def test_experiment_ids_only(self): # Legacy server behavior; should raise an error. mock_api_client = _create_mock_api_client() def stream_experiments(request, **kwargs): del request # unused yield export_service_pb2.StreamExperimentsResponse( experiment_ids=["123", "456"]) yield export_service_pb2.StreamExperimentsResponse( experiment_ids=["789"]) mock_api_client.StreamExperiments = mock.Mock(wraps=stream_experiments) with self.assertRaises(RuntimeError) as cm: list(exporter_lib.list_experiments(mock_api_client)) self.assertIn(repr(["123", "456"]), str(cm.exception))
def execute(self, server_info, channel): api_client = export_service_pb2_grpc.TensorBoardExporterServiceStub( channel) gen = exporter_lib.list_experiments(api_client) count = 0 for experiment_id in gen: count += 1 url = server_info_lib.experiment_url(server_info, experiment_id) print(url) sys.stdout.flush() if not count: sys.stderr.write( 'No experiments. Use `tensorboard dev upload` to get started.\n' ) else: sys.stderr.write('Total: %d experiment(s)\n' % count) sys.stderr.flush()
def test_experiments_only(self): mock_api_client = _create_mock_api_client() def stream_experiments(request, **kwargs): del request # unused response = export_service_pb2.StreamExperimentsResponse() response.experiments.add(experiment_id="789", name="one") response.experiments.add(experiment_id="012", description="two") yield response mock_api_client.StreamExperiments = mock.Mock(wraps=stream_experiments) gen = exporter_lib.list_experiments(mock_api_client) mock_api_client.StreamExperiments.assert_not_called() expected = [ experiment_pb2.Experiment(experiment_id="789", name="one"), experiment_pb2.Experiment(experiment_id="012", description="two"), ] self.assertEqual(list(gen), expected)
def execute(self, channel): api_client = export_service_pb2_grpc.TensorBoardExporterServiceStub( channel) gen = exporter_lib.list_experiments(api_client) count = 0 for experiment_id in gen: count += 1 # TODO(@wchargin): Once #2879 is in, remove this hard-coded URL pattern. url = 'https://tensorboard.dev/experiment/%s/' % experiment_id print(url) sys.stdout.flush() if not count: sys.stderr.write( 'No experiments. Use `tensorboard dev upload` to get started.\n' ) else: sys.stderr.write('Total: %d experiment(s)\n' % count) sys.stderr.flush()
def execute(self, server_info, channel): api_client = export_service_pb2_grpc.TensorBoardExporterServiceStub( channel ) fieldmask = experiment_pb2.ExperimentMask( create_time=True, update_time=True, num_scalars=True, num_runs=True, num_tags=True, ) gen = exporter_lib.list_experiments(api_client, fieldmask=fieldmask) count = 0 for experiment in gen: count += 1 if not isinstance(experiment, experiment_pb2.Experiment): url = server_info_lib.experiment_url(server_info, experiment) print(url) continue experiment_id = experiment.experiment_id url = server_info_lib.experiment_url(server_info, experiment_id) print(url) data = [ ("Name", experiment.name or "[No Name]"), ("Description", experiment.description or "[No Description]"), ("Id", experiment.experiment_id), ("Created", util.format_time(experiment.create_time)), ("Updated", util.format_time(experiment.update_time)), ("Scalars", str(experiment.num_scalars)), ("Runs", str(experiment.num_runs)), ("Tags", str(experiment.num_tags)), ] for (name, value) in data: print("\t%s %s" % (name.ljust(12), value)) sys.stdout.flush() if not count: sys.stderr.write( "No experiments. Use `tensorboard dev upload` to get started.\n" ) else: sys.stderr.write("Total: %d experiment(s)\n" % count) sys.stderr.flush()
def test_mixed_experiments_and_ids(self): mock_api_client = _create_mock_api_client() def stream_experiments(request, **kwargs): del request # unused # Should ignore `experiment_ids` in the presence of `experiments`. response = export_service_pb2.StreamExperimentsResponse() response.experiment_ids.append("999") # will be omitted response.experiments.add(experiment_id="789") response.experiments.add(experiment_id="012") yield response mock_api_client.StreamExperiments = mock.Mock(wraps=stream_experiments) gen = exporter_lib.list_experiments(mock_api_client) mock_api_client.StreamExperiments.assert_not_called() expected = [ experiment_pb2.Experiment(experiment_id="789"), experiment_pb2.Experiment(experiment_id="012"), ] self.assertEqual(list(gen), expected)
def execute(self, server_info, channel): api_client = export_service_pb2_grpc.TensorBoardExporterServiceStub( channel) fieldmask = export_service_pb2.ExperimentMask( create_time=True, update_time=True, num_scalars=True, num_runs=True, num_tags=True, ) gen = exporter_lib.list_experiments(api_client, fieldmask=fieldmask) count = 0 for experiment in gen: count += 1 if not isinstance(experiment, export_service_pb2.Experiment): url = server_info_lib.experiment_url(server_info, experiment) print(url) continue experiment_id = experiment.experiment_id url = server_info_lib.experiment_url(server_info, experiment_id) print(url) data = [ ('Id', experiment.experiment_id), ('Created', util.format_time(experiment.create_time)), ('Updated', util.format_time(experiment.update_time)), ('Scalars', str(experiment.num_scalars)), ('Runs', str(experiment.num_runs)), ('Tags', str(experiment.num_tags)), ] for (name, value) in data: print('\t%s %s' % (name.ljust(10), value)) sys.stdout.flush() if not count: sys.stderr.write( 'No experiments. Use `tensorboard dev upload` to get started.\n' ) else: sys.stderr.write('Total: %d experiment(s)\n' % count) sys.stderr.flush()