Given a tag regex and single run, return ScalarEvents.

    Args:
      run: A run string.
      tag_regex_string: A regular expression that captures portions of tags.

    Raises:
      ValueError: if the scalars plugin is not registered.

    Returns:
      A dictionary that is the JSON-able response.

def scalars_impl(self, run, tag_regex_string):
    """Given a tag regex and single run, return ScalarEvents.

    Args:
      run: A run string.
      tag_regex_string: A regular expression that captures portions of tags.

    Raises:
      ValueError: if the scalars plugin is not registered.

    Returns:
      A dictionary that is the JSON-able response.
    """
    if not tag_regex_string:
      # The user provided no regex.
      return {
          _REGEX_VALID_PROPERTY: False,
          _TAG_TO_EVENTS_PROPERTY: {},
      }

    # Construct the regex.
    try:
      regex = re.compile(tag_regex_string)
    except re.error:
      return {
          _REGEX_VALID_PROPERTY: False,
          _TAG_TO_EVENTS_PROPERTY: {},
      }

    # Fetch the tags for the run. Filter for tags that match the regex.
    run_to_data = self._multiplexer.PluginRunToTagToContent(
        scalars_metadata.PLUGIN_NAME)

    tag_to_data = None
    try:
      tag_to_data = run_to_data[run]
    except KeyError:
      # The run could not be found. Perhaps a configuration specified a run that
      # TensorBoard has not read from disk yet.
      payload = {}

    if tag_to_data:
      scalars_plugin_instance = self._get_scalars_plugin()
      if not scalars_plugin_instance:
        raise ValueError(('Failed to respond to request for /scalars. '
                          'The scalars plugin is oddly not registered.'))

      form = scalars_plugin.OutputFormat.JSON
      payload = {
        tag: scalars_plugin_instance.scalars_impl(tag, run, None, form)[0]
            for tag in tag_to_data.keys()
            if regex.match(tag)
      }

    return {
        _REGEX_VALID_PROPERTY: True,
        _TAG_TO_EVENTS_PROPERTY: payload,
    }