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
16 changes: 7 additions & 9 deletions tensorboard/components/tf_backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {compareTagNames} from '../vz-sorting/sorting.js';
import {RequestManager} from './requestManager.js';
import {getRouter} from './router.js';
namespace tf_backend {

export type RunToTag = {
[run: string]: string[];
Expand Down Expand Up @@ -44,13 +41,13 @@ export type DebuggerNumericsAlertReportResponse = DebuggerNumericsAlertReport[];
export const TYPES = [];

/** Given a RunToTag, return sorted array of all runs */
export function getRuns(r: RunToTag): string[] {
return _.keys(r).sort(compareTagNames);
export function getRunsNamed(r: RunToTag): string[] {
return _.keys(r).sort(vz_sorting.compareTagNames);
}

/** Given a RunToTag, return array of all tags (sorted + dedup'd) */
export function getTags(r: RunToTag): string[] {
return _.union.apply(null, _.values(r)).sort(compareTagNames);
return _.union.apply(null, _.values(r)).sort(vz_sorting.compareTagNames);
}

/**
Expand All @@ -61,7 +58,7 @@ export function getTags(r: RunToTag): string[] {
export function filterTags(r: RunToTag, runs: string[]): string[] {
let result = [];
runs.forEach((x) => result = result.concat(r[x]));
return _.uniq(result).sort(compareTagNames);
return _.uniq(result).sort(vz_sorting.compareTagNames);
}

function timeToDate(x: number): Date {
Expand Down Expand Up @@ -91,9 +88,10 @@ function detupler<T, G>(xform: (x: T) => G): (t: TupleData<T>) => Datum & G {
};
};


/**
* The following interface (TupleData) describes how the data is sent
* over from the backend.
*/
type TupleData<T> = [number, number, T]; // wall_time, step

} // namespace tf_backend
3 changes: 3 additions & 0 deletions tensorboard/components/tf_backend/canceller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
namespace tf_backend {

/**
* A class that allows marking promises as cancelled.
Expand Down Expand Up @@ -63,3 +64,5 @@ export class Canceller {
this.cancellationCount++;
}
}

} // namespace tf_backend
4 changes: 4 additions & 0 deletions tensorboard/components/tf_backend/requestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
namespace tf_backend {

interface ResolveReject {
resolve: Function;
reject: Function;
}

/**
* Manages many fetch requests. Launches up to nSimultaneousRequests
* simultaneously, and maintains a LIFO queue of requests to process when
Expand Down Expand Up @@ -175,3 +177,5 @@ export class RequestManager {
});
}
}

} // namespace tf_backend
5 changes: 3 additions & 2 deletions tensorboard/components/tf_backend/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {addParams} from './urlPathHelpers.js';
namespace tf_backend {

export interface Router {
logdir: () => string;
Expand Down Expand Up @@ -76,3 +75,5 @@ export function setRouter(router: Router): void {
}
_router = router;
}

} // namespace tf_backend
6 changes: 3 additions & 3 deletions tensorboard/components/tf_backend/runsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {RequestManager} from './requestManager.js';
import {getRouter} from './router.js';
namespace tf_backend {

let runs: string[] = [];

Expand Down Expand Up @@ -66,3 +64,5 @@ export function fetchRuns(): Promise<void> {
export function getRuns(): string[] {
return runs.slice();
}

} // namespace tf_backend
1 change: 0 additions & 1 deletion tensorboard/components/tf_backend/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ ts_web_library(
"//tensorboard/components/tf_imports:webcomponentsjs",
],
)

14 changes: 6 additions & 8 deletions tensorboard/components/tf_backend/test/backendTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {filterTags, getRuns, getTags, RunToTag, TYPES} from '../backend.js';
import {RequestManager} from '../requestManager.js';
import {createRouter, setRouter} from '../router.js';
import {addParams} from '../urlPathHelpers.js';
namespace tf_backend {

describe('urlPathHelpers', () => {
it('addParams leaves input untouched when there are no parameters', () => {
Expand Down Expand Up @@ -67,17 +63,19 @@ describe('backend tests', () => {
};
const empty1: RunToTag = {};
const empty2: RunToTag = {run1: [], run2: []};
chai.assert.deepEqual(getRuns(r2t), ['a', 'run1', 'run2']);
chai.assert.deepEqual(getRunsNamed(r2t), ['a', 'run1', 'run2']);
chai.assert.deepEqual(getTags(r2t), ['bar', 'foo', 'zod', 'zoink']);
chai.assert.deepEqual(filterTags(r2t, ['run1', 'run2']), getTags(r2t));
chai.assert.deepEqual(filterTags(r2t, ['run1']), ['bar', 'foo', 'zod']);
chai.assert.deepEqual(
filterTags(r2t, ['run2', 'a']), ['foo', 'zod', 'zoink']);

chai.assert.deepEqual(getRuns(empty1), []);
chai.assert.deepEqual(getRunsNamed(empty1), []);
chai.assert.deepEqual(getTags(empty1), []);

chai.assert.deepEqual(getRuns(empty2), ['run1', 'run2']);
chai.assert.deepEqual(getRunsNamed(empty2), ['run1', 'run2']);
chai.assert.deepEqual(getTags(empty2), []);
});
});

} // namespace tf_backend
5 changes: 3 additions & 2 deletions tensorboard/components/tf_backend/test/requestManagerTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {RequestManager, RequestNetworkError} from '../requestManager.js';
namespace tf_backend {

interface MockRequest {
resolve: Function;
Expand Down Expand Up @@ -292,3 +291,5 @@ describe('backend', () => {
});
});
});

} // namespace tf_backend
4 changes: 4 additions & 0 deletions tensorboard/components/tf_backend/urlPathHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
namespace tf_backend {

/**
* A query parameter value can either be a string or a list of strings.
* A string `"foo"` is encoded as `key=foo`; a list `["foo", "bar"]` is
Expand Down Expand Up @@ -51,3 +53,5 @@ function _encodeURIComponent(x: string): string {
// Replace parentheses for consistency with Python's urllib.urlencode.
return encodeURIComponent(x).replace(/\(/g, '%28').replace(/\)/g, '%29');
}

} // namespace tf_backend
2 changes: 1 addition & 1 deletion tensorboard/components/tf_card_heading/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ts_web_library(
"tf-card-heading.html",
"tf-card-heading-style.html",
"util.html",
"util.js",
"util.ts",
],
path = "/tf-card-heading",
visibility = ["//visibility:public"],
Expand Down
4 changes: 1 addition & 3 deletions tensorboard/components/tf_card_heading/tf-card-heading.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@
</style>
</template>
<script>
import {pickTextColor} from './util.js';

Polymer({
is: "tf-card-heading",

Expand Down Expand Up @@ -153,7 +151,7 @@
},

_computeRunColor(color) {
return pickTextColor(color);
return tf_card_heading.pickTextColor(color);
},

_computeNameLabel(displayName, tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
namespace tf_card_heading {

/**
* Formats timestamp for the card header.
Expand All @@ -26,7 +27,6 @@ export function formatDate(date) {
return date.toString().replace(/GMT-\d+ \(([^)]+)\)/, '$1');
}


/**
* Returns CSS color that will contrast against background.
* @param {?string} background RGB hex color code, e.g. #eee, #eeeeee.
Expand All @@ -44,7 +44,6 @@ export function pickTextColor(background) {
return brightness > 125 ? 'inherit' : '#eee';
}


/**
* Turns a hex string into an RGB array.
* @param {?string} color RGB hex color code, e.g. #eee, #eeeeee.
Expand All @@ -67,3 +66,5 @@ function convertHexToRgb(color) {
parseInt(m[2], 16),
parseInt(m[3], 16)];
}

} // namespace tf_card_heading
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {compareTagNames} from '../vz-sorting/sorting.js';
import {getTags} from '../tf-backend/backend.js';
namespace tf_categorization_utils {

/**
* Functions to extract categories of tags and/or run-tag combinations
Expand Down Expand Up @@ -110,7 +108,7 @@ export function categorizeTags(
runToTag: RunToTag,
selectedRuns: string[],
query?: string): TagCategory[] {
const tags = getTags(runToTag);
const tags = tf_backend.getTags(runToTag);
const categories = categorize(tags, query);
const tagToRuns: {[tag: string]: string[]} = {};
tags.forEach(tag => {
Expand All @@ -132,11 +130,11 @@ export function categorizeTags(
}

function compareTagRun(a, b: {tag: string, run: string}): number {
const c = compareTagNames(a.tag, b.tag);
const c = vz_sorting.compareTagNames(a.tag, b.tag);
if (c != 0) {
return c;
}
return compareTagNames(a.run, b.run);
return vz_sorting.compareTagNames(a.run, b.run);
}

export function categorizeRunTagCombinations(
Expand All @@ -157,3 +155,5 @@ export function categorizeRunTagCombinations(
}
return tagCategories.map(explodeCategory);
}

} // namespace tf_categorization_utils
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as CategorizationUtils from '../categorizationUtils';
namespace tf_categorization_utils {

const assert = chai.assert;

describe('categorizationUtils', () => {
const {CategoryType} = CategorizationUtils;
const {CategoryType} = tf_categorization_utils;

describe('categorizeByPrefix', () => {
const {categorizeByPrefix} = CategorizationUtils;
const {categorizeByPrefix} = tf_categorization_utils;
const metadata = {type: CategoryType.PREFIX_GROUP};

it('returns empty array on empty tags', () => {
Expand Down Expand Up @@ -79,7 +78,7 @@ describe('categorizationUtils', () => {
});

describe('categorizeBySearchQuery', () => {
const {categorizeBySearchQuery} = CategorizationUtils;
const {categorizeBySearchQuery} = tf_categorization_utils;
const baseMetadata = {
type: CategoryType.SEARCH_RESULTS,
validRegex: true,
Expand Down Expand Up @@ -152,7 +151,7 @@ describe('categorizationUtils', () => {
});

describe('categorize', () => {
const {categorize} = CategorizationUtils;
const {categorize} = tf_categorization_utils;

it('merges the results of the query and the prefix groups', () => {
const query = 'ba(?:na){2,}s';
Expand Down Expand Up @@ -197,3 +196,5 @@ describe('categorizationUtils', () => {
});

});

} // namespace tf_categorization_utils
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
</style>
</template>
<script>
import {CategoryType} from "./categorizationUtils.js";
Polymer({
is: "tf-category-pane",
properties: {
Expand Down Expand Up @@ -176,23 +175,23 @@
// Show a category unless it's a search results category where
// there wasn't actually a search query.
return !(
category.metadata.type === CategoryType['SEARCH_RESULTS']
category.metadata.type === tf_categorization_utils.CategoryType['SEARCH_RESULTS']
&& category.name === "");
},

_computeIsSearchResults(type) {
return type === CategoryType['SEARCH_RESULTS'];
return type === tf_categorization_utils.CategoryType['SEARCH_RESULTS'];
},

_computeIsInvalidSearchResults(metadata) {
return (
metadata.type === CategoryType['SEARCH_RESULTS']
metadata.type === tf_categorization_utils.CategoryType['SEARCH_RESULTS']
&& !metadata.validRegex);
},

_computeIsUniversalSearchQuery(metadata) {
return (
metadata.type === CategoryType['SEARCH_RESULTS']
metadata.type === tf_categorization_utils.CategoryType['SEARCH_RESULTS']
&& metadata.universalRegex);
},
});
Expand Down
12 changes: 6 additions & 6 deletions tensorboard/components/tf_color_scale/colorScale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as RunsStore from '../tf-backend/runsStore.js';
import {standard as standardPalette} from './palettes.js';
namespace tf_color_scale {

// Example usage:
// runs = ["train", "test", "test1", "test2"]
Expand All @@ -32,7 +30,7 @@ export class ColorScale {
* Array of hex strings. Defaults to the standard palette.
*/
constructor(
private readonly palette: string[] = standardPalette) {}
private readonly palette: string[] = standard) {}

/**
* Set the domain of strings.
Expand Down Expand Up @@ -70,7 +68,9 @@ export const runsColorScale: ((runName: string) => string) =
_runsColorScale.scale.bind(_runsColorScale);

function updateRunsColorScale(): void {
_runsColorScale.domain(RunsStore.getRuns());
_runsColorScale.domain(tf_backend.getRuns());
}
RunsStore.addListener(updateRunsColorScale);
tf_backend.addListener(updateRunsColorScale);
updateRunsColorScale();

} // tf_color_scale
Loading