Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tensorboard/backend/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ def _serve_plugin_entry(self, request):

html = textwrap.dedent(
"""
<!DOCTYPE html>
<head><base href="plugin/{name}/" /></head>
<body><script type="module">{script_content}</script></body>
"""
<!DOCTYPE html>
<head><base href="plugin/{name}/" /></head>
<body><script type="module">{script_content}</script></body>
"""
).format(name=name, script_content=script_content)
return http_util.Respond(
request, html, "text/html", csp_scripts_sha256s=[script_sha],
Expand Down
20 changes: 10 additions & 10 deletions tensorboard/backend/event_processing/db_import_multiplexer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ def _get_runs(self):
db = self.db_connection_provider()
cursor = db.execute(
"""
SELECT
Runs.run_name
FROM Runs
ORDER BY Runs.run_name
"""
SELECT
Runs.run_name
FROM Runs
ORDER BY Runs.run_name
"""
)
return [row[0] for row in cursor]

def _get_experiments(self):
db = self.db_connection_provider()
cursor = db.execute(
"""
SELECT
Experiments.experiment_name
FROM Experiments
ORDER BY Experiments.experiment_name
"""
SELECT
Experiments.experiment_name
FROM Experiments
ORDER BY Experiments.experiment_name
"""
)
return [row[0] for row in cursor]

Expand Down
60 changes: 30 additions & 30 deletions tensorboard/backend/event_processing/reservoir.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,36 @@
class Reservoir(object):
"""A map-to-arrays container, with deterministic Reservoir Sampling.

Items are added with an associated key. Items may be retrieved by key, and
a list of keys can also be retrieved. If size is not zero, then it dictates
the maximum number of items that will be stored with each key. Once there are
more items for a given key, they are replaced via reservoir sampling, such
that each item has an equal probability of being included in the sample.

Deterministic means that for any given seed and bucket size, the sequence of
values that are kept for any given tag will always be the same, and that this
is independent of any insertions on other tags. That is:

>>> separate_reservoir = reservoir.Reservoir(10)
>>> interleaved_reservoir = reservoir.Reservoir(10)
>>> for i in xrange(100):
>>> separate_reservoir.AddItem('key1', i)
>>> for i in xrange(100):
>>> separate_reservoir.AddItem('key2', i)
>>> for i in xrange(100):
>>> interleaved_reservoir.AddItem('key1', i)
>>> interleaved_reservoir.AddItem('key2', i)

separate_reservoir and interleaved_reservoir will be in identical states.

See: https://en.wikipedia.org/wiki/Reservoir_sampling

Adding items has amortized O(1) runtime.

Fields:
always_keep_last: Whether the latest seen sample is always at the
end of the reservoir. Defaults to True.
size: An integer of the maximum number of samples.
Items are added with an associated key. Items may be retrieved by key, and
a list of keys can also be retrieved. If size is not zero, then it dictates
the maximum number of items that will be stored with each key. Once there are
more items for a given key, they are replaced via reservoir sampling, such
that each item has an equal probability of being included in the sample.

Deterministic means that for any given seed and bucket size, the sequence of
values that are kept for any given tag will always be the same, and that this
is independent of any insertions on other tags. That is:

>>> separate_reservoir = reservoir.Reservoir(10)
>>> interleaved_reservoir = reservoir.Reservoir(10)
>>> for i in xrange(100):
>>> separate_reservoir.AddItem('key1', i)
>>> for i in xrange(100):
>>> separate_reservoir.AddItem('key2', i)
>>> for i in xrange(100):
>>> interleaved_reservoir.AddItem('key1', i)
>>> interleaved_reservoir.AddItem('key2', i)

separate_reservoir and interleaved_reservoir will be in identical states.

See: https://en.wikipedia.org/wiki/Reservoir_sampling

Adding items has amortized O(1) runtime.

Fields:
always_keep_last: Whether the latest seen sample is always at the
end of the reservoir. Defaults to True.
size: An integer of the maximum number of samples.
"""

def __init__(self, size, seed=0, always_keep_last=True):
Expand Down
54 changes: 27 additions & 27 deletions tensorboard/backend/event_processing/sqlite_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def _maybe_init_user(self):
user_id = self._create_id()
cursor.execute(
"""
INSERT INTO USERS (user_id, user_name, inserted_time)
VALUES (?, ?, ?)
""",
INSERT INTO USERS (user_id, user_name, inserted_time)
VALUES (?, ?, ?)
""",
(user_id, user_name, time.time()),
)
return user_id
Expand All @@ -91,9 +91,9 @@ def _maybe_init_experiment(self, experiment_name):
cursor = self._db.cursor()
cursor.execute(
"""
SELECT experiment_id FROM Experiments
WHERE user_id = ? AND experiment_name = ?
""",
SELECT experiment_id FROM Experiments
WHERE user_id = ? AND experiment_name = ?
""",
(user_id, experiment_name),
)
row = cursor.fetchone()
Expand All @@ -104,11 +104,11 @@ def _maybe_init_experiment(self, experiment_name):
computed_time = 0
cursor.execute(
"""
INSERT INTO Experiments (
user_id, experiment_id, experiment_name,
inserted_time, started_time, is_watching
) VALUES (?, ?, ?, ?, ?, ?)
""",
INSERT INTO Experiments (
user_id, experiment_id, experiment_name,
inserted_time, started_time, is_watching
) VALUES (?, ?, ?, ?, ?, ?)
""",
(
user_id,
experiment_id,
Expand All @@ -131,9 +131,9 @@ def _maybe_init_run(self, experiment_name, run_name):
cursor = self._db.cursor()
cursor.execute(
"""
SELECT run_id FROM Runs
WHERE experiment_id = ? AND run_name = ?
""",
SELECT run_id FROM Runs
WHERE experiment_id = ? AND run_name = ?
""",
(experiment_id, run_name),
)
row = cursor.fetchone()
Expand All @@ -144,10 +144,10 @@ def _maybe_init_run(self, experiment_name, run_name):
started_time = 0
cursor.execute(
"""
INSERT INTO Runs (
experiment_id, run_id, run_name, inserted_time, started_time
) VALUES (?, ?, ?, ?, ?)
""",
INSERT INTO Runs (
experiment_id, run_id, run_name, inserted_time, started_time
) VALUES (?, ?, ?, ?, ?)
""",
(experiment_id, run_id, run_name, time.time(), started_time),
)
return run_id
Expand Down Expand Up @@ -188,11 +188,11 @@ def _maybe_init_tags(self, run_id, tag_to_metadata):
)
cursor.executemany(
"""
INSERT INTO Tags (
run_id, tag_id, tag_name, inserted_time, display_name, plugin_name,
plugin_data
) VALUES (?, ?, ?, ?, ?, ?, ?)
""",
INSERT INTO Tags (
run_id, tag_id, tag_name, inserted_time, display_name, plugin_name,
plugin_data
) VALUES (?, ?, ?, ?, ?, ?, ?)
""",
new_tag_data,
)
return tag_to_id
Expand Down Expand Up @@ -237,10 +237,10 @@ def write_summaries(self, tagged_data, experiment_name, run_name):
)
self._db.executemany(
"""
INSERT OR REPLACE INTO Tensors (
series, step, computed_time, dtype, shape, data
) VALUES (?, ?, ?, ?, ?, ?)
""",
INSERT OR REPLACE INTO Tensors (
series, step, computed_time, dtype, shape, data
) VALUES (?, ?, ?, ?, ?, ?)
""",
tensor_values,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class ExampleRawScalarsPlugin(base_plugin.TBPlugin):
def __init__(self, context):
"""Instantiates ExampleRawScalarsPlugin.

Args:
context: A base_plugin.TBContext instance.
"""
Args:
context: A base_plugin.TBContext instance.
"""
self._multiplexer = context.multiplexer

def get_plugin_apps(self):
Expand All @@ -64,10 +64,10 @@ def get_plugin_apps(self):
def _serve_tags(self, request):
"""Serves run to tag info.

Frontend clients can use the Multiplexer's run+tag structure to request data
for a specific run+tag. Responds with a map of the form:
{runName: [tagName, tagName, ...]}
"""
Frontend clients can use the Multiplexer's run+tag structure to request data
for a specific run+tag. Responds with a map of the form:
{runName: [tagName, tagName, ...]}
"""
run_tag_mapping = self._multiplexer.PluginRunToTagToContent(
_SCALAR_PLUGIN_NAME
)
Expand All @@ -81,10 +81,10 @@ def _serve_tags(self, request):
def _serve_static_file(self, request):
"""Returns a resource file from the static asset directory.

Requests from the frontend have a path in this form:
/data/plugin/example_raw_scalars/static/foo
This serves the appropriate asset: ./static/foo.
"""
Requests from the frontend have a path in this form:
/data/plugin/example_raw_scalars/static/foo
This serves the appropriate asset: ./static/foo.
"""
static_path_part = request.path[len(_PLUGIN_DIRECTORY_PATH_PART) :]
res_path = os.path.join(os.path.dirname(__file__), static_path_part)

Expand All @@ -97,9 +97,9 @@ def _serve_static_file(self, request):
def is_active(self):
"""Returns whether there is relevant data for the plugin to process.

When there are no runs with scalar data, TensorBoard will hide the plugin
from the main navigation bar.
"""
When there are no runs with scalar data, TensorBoard will hide the plugin
from the main navigation bar.
"""
return bool(
self._multiplexer.PluginRunToTagToContent(_SCALAR_PLUGIN_NAME)
)
Expand All @@ -110,20 +110,20 @@ def frontend_metadata(self):
def scalars_impl(self, tag, run):
"""Returns scalar data for the specified tag and run.

For details on how to use tags and runs, see
https://github.com/tensorflow/tensorboard#tags-giving-names-to-data
For details on how to use tags and runs, see
https://github.com/tensorflow/tensorboard#tags-giving-names-to-data

Args:
tag: string
run: string
Args:
tag: string
run: string

Returns:
A list of ScalarEvents - tuples containing 3 numbers describing entries in
the data series.
Returns:
A list of ScalarEvents - tuples containing 3 numbers describing entries in
the data series.

Raises:
errors.NotFoundError: if run+tag pair has no scalar data.
"""
Raises:
errors.NotFoundError: if run+tag pair has no scalar data.
"""
try:
tensor_events = self._multiplexer.Tensors(run, tag)
values = [
Expand Down
Loading