Esempio n. 1
0
 def test_metadata_format(self):
     """Tests that metadata content must be passed as a serialized
     string."""
     with six.assertRaisesRegex(
         self, TypeError, r"Content type must be bytes."
     ):
         metadata.parse_plugin_metadata(123)
Esempio n. 2
0
 def test_metadata_version(self):
     """Tests that only the latest version of metadata is supported."""
     self._create_metadata()
     # Change the version.
     with patch.object(metadata, 'get_current_version', return_value=100):
         # Try to parse metadata from a prior version.
         with self.assertRaises(ValueError):
             metadata.parse_plugin_metadata(
                 self.summary_metadata.plugin_data.content)
Esempio n. 3
0
 def test_op(self):
     """Tests merged summary with different types of data."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(
         100, add_faces=True, add_colors=True
     )
     config_dict = {"foo": 1}
     with tf.compat.v1.Graph().as_default():
         tensor_summary = summary.op(
             name,
             tensor_data.vertices,
             faces=tensor_data.faces,
             colors=tensor_data.colors,
             config_dict=config_dict,
         )
         with self.test_session() as sess:
             proto = self.pb_via_op(tensor_summary)
             self.verify_proto(proto, name)
             plugin_metadata = metadata.parse_plugin_metadata(
                 proto.value[0].metadata.plugin_data.content
             )
             self.assertEqual(
                 json.dumps(config_dict, sort_keys=True),
                 plugin_metadata.json_config,
             )
Esempio n. 4
0
 def test_default_components(self):
     """Tests that defult components are added when necessary."""
     self._create_metadata()
     stored_metadata = plugin_data_pb2.MeshPluginData(
         version=metadata.get_current_version(), components=0)
     parsed_metadata = metadata.parse_plugin_metadata(
         stored_metadata.SerializeToString())
     self.assertGreater(parsed_metadata.components, 0)
Esempio n. 5
0
 def _instance_tags(self, run, tag):
     """Gets the instance tag names for a user-facing tag."""
     index = self._multiplexer.GetAccumulator(run).PluginTagToContent(
         metadata.PLUGIN_NAME)
     return [
         instance_tag for (instance_tag, content) in six.iteritems(index)
         if tag == metadata.parse_plugin_metadata(content).name
     ]
Esempio n. 6
0
 def test_parse_plugin_metadata(self):
   """Tests parsing of saved plugin metadata."""
   self._create_metadata()
   parsed_metadata = metadata.parse_plugin_metadata(
       self.summary_metadata.plugin_data.content)
   self.assertEqual(self.name, parsed_metadata.name)
   self.assertEqual(plugin_data_pb2.MeshPluginData.ContentType.Value('VERTEX'),
                    parsed_metadata.content_type)
   self.assertEqual(self.shape, parsed_metadata.shape)
   self.assertEqual(self.json_config, parsed_metadata.json_config)
Esempio n. 7
0
 def _instance_tag_metadata(self, ctx, experiment, run, instance_tag):
     """Gets the `MeshPluginData` proto for an instance tag."""
     results = self._data_provider.list_tensors(
         ctx,
         experiment_id=experiment,
         plugin_name=metadata.PLUGIN_NAME,
         run_tag_filter=provider.RunTagFilter(runs=[run],
                                              tags=[instance_tag]),
     )
     content = results[run][instance_tag].plugin_content
     return metadata.parse_plugin_metadata(content)
Esempio n. 8
0
 def _instance_tags(self, ctx, experiment, run, tag):
     """Gets the instance tag names for a user-facing tag."""
     index = self._data_provider.list_tensors(
         ctx,
         experiment_id=experiment,
         plugin_name=metadata.PLUGIN_NAME,
         run_tag_filter=provider.RunTagFilter(runs=[run]),
     )
     return [
         instance_tag for (instance_tag, ts) in index.get(run, {}).items()
         if tag == metadata.parse_plugin_metadata(ts.plugin_content).name
     ]
Esempio n. 9
0
 def test_pb(self):
     """Tests ProtoBuf interface."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     proto = summary.mesh_pb(name,
                             tensor_data.vertices,
                             faces=tensor_data.faces,
                             colors=tensor_data.colors,
                             config_dict=config_dict)
     plugin_metadata = metadata.parse_plugin_metadata(
         proto.value[0].metadata.plugin_data.content)
     self.assertEqual(json.dumps(config_dict, sort_keys=True),
                      plugin_metadata.json_config)
Esempio n. 10
0
 def test_pb(self):
     """Tests merged summary protobuf with different types of data."""
     name = "my_mesh"
     tensor_data = test_utils.get_random_mesh(100,
                                              add_faces=True,
                                              add_colors=True)
     config_dict = {"foo": 1}
     proto = summary.pb(name,
                        tensor_data.vertices,
                        faces=tensor_data.faces,
                        colors=tensor_data.colors,
                        config_dict=config_dict)
     self.verify_proto(proto, name)
     plugin_metadata = metadata.parse_plugin_metadata(
         proto.value[0].metadata.plugin_data.content)
     self.assertEqual(json.dumps(config_dict, sort_keys=True),
                      plugin_metadata.json_config)
Esempio n. 11
0
  def prepare_metadata(self):
    """Processes all tags and caches metadata for each."""
    if self._tag_to_instance_tags:
      return
    # This is a dictionary mapping from run to (tag to string content).
    # To be clear, the values of the dictionary are dictionaries.
    all_runs = self._multiplexer.PluginRunToTagToContent(MeshPlugin.plugin_name)

    # tagToContent is itself a dictionary mapping tag name to string
    # SummaryMetadata.plugin_data.content. Retrieve the keys of that dictionary
    # to obtain a list of tags associated with each run. For each tag, estimate
    # the number of samples.
    self._tag_to_instance_tags = collections.defaultdict(list)
    self._instance_tag_to_metadata = dict()
    for run, tag_to_content in six.iteritems(all_runs):
      for tag, content in six.iteritems(tag_to_content):
        meta = metadata.parse_plugin_metadata(content)
        self._instance_tag_to_metadata[(run, tag)] = meta
        # Remember instance_name (instance_tag) for future reference.
        self._tag_to_instance_tags[(run, meta.name)].append(tag)
        self._instance_tag_to_tag[(run, tag)] = meta.name
Esempio n. 12
0
    def _serve_tags(self, request):
        """A route (HTTP handler) that returns a response with tags.

        Args:
          request: The werkzeug.Request object.

        Returns:
          A response that contains a JSON object. The keys of the object
          are all the runs. Each run is mapped to a (potentially empty)
          list of all tags that are relevant to this plugin.
        """
        ctx = plugin_util.context(request.environ)
        experiment = plugin_util.experiment_id(request.environ)
        all_runs = self._data_provider.list_tensors(
            ctx,
            experiment_id=experiment,
            plugin_name=metadata.PLUGIN_NAME,
        )

        # tagToContent is itself a dictionary mapping tag name to string
        # SummaryMetadata.plugin_data.content. Retrieve the keys of that dictionary
        # to obtain a list of tags associated with each run. For each tag estimate
        # number of samples.
        response = dict()
        for run, tags in all_runs.items():
            response[run] = dict()
            for (instance_tag, metadatum) in tags.items():
                md = metadata.parse_plugin_metadata(metadatum.plugin_content)
                if not self._version_checker.ok(md.version, run, instance_tag):
                    continue
                # Make sure we only operate on user-defined tags here.
                tag = self._tag(ctx, experiment, run, instance_tag)
                meta = self._instance_tag_metadata(
                    ctx, experiment, run, instance_tag
                )
                # Batch size must be defined, otherwise we don't know how many
                # samples were there.
                response[run][tag] = {"samples": meta.shape[0]}
        return http_util.Respond(request, response, "application/json")
Esempio n. 13
0
 def get_components(self, proto):
     return metadata.parse_plugin_metadata(
         proto.metadata.plugin_data.content).components
Esempio n. 14
0
 def get_metadata(self, event):
     return metadata.parse_plugin_metadata(
         event.summary.value[0].metadata.plugin_data.content)
Esempio n. 15
0
 def _instance_tag_metadata(self, run, instance_tag):
     """Gets the `MeshPluginData` proto for an instance tag."""
     summary_metadata = self._multiplexer.SummaryMetadata(run, instance_tag)
     content = summary_metadata.plugin_data.content
     return metadata.parse_plugin_metadata(content)