Skip to content

DRAFT: Revisit Node Map #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
229 changes: 229 additions & 0 deletions src/OneExplorer/Artifact.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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 vscode from "vscode";

export type ArtifactType =
| "DIRECTORY"
| "BASEMODEL_TFLITE"
| "BASEMODEL_ONNX"
| "BASEMODEL_PB"
| "CONFIG_ONE"
| "PRODUCT_CIRCLE"
| "PRODUCT_TVN"
| "PRODUCT_MONDRIAN"
| "PRODUCT_CHROME_TRACE"
| "PRODUCT_TV2W"
| "PRODUCT_TV2O"
| "PRODUCT_TV2M"
| "PRODUCT_CIRCLE_LOG";


export interface Artifact {
type: ArtifactType;
path: string;
}

/**
* @reference (OneExplorer) Node
*/
export interface NodeAttr {
ext?: string;
hidable?: boolean;
}

/**
* @reference vscode.TreeItem
*/
export interface TreeItemAttr {
icon?: vscode.ThemeIcon;
openViewType?: string;
collapsibleState?: vscode.TreeItemCollapsibleState;
}

export interface ArtifactAttr extends NodeAttr, TreeItemAttr {}

class DirectoryArtifactAttr implements ArtifactAttr {
readonly ext = undefined;
readonly hidable = false;
icon?: vscode.ThemeIcon;
readonly openViewType = undefined;
readonly collapsibleState = vscode.TreeItemCollapsibleState.Expanded;
}

class BaseModelArtifactAttr implements ArtifactAttr {
ext?: string;
readonly hidable = false;
icon?: vscode.ThemeIcon;
openViewType?: string;
readonly collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
}

class ConfigArtifactAttr implements ArtifactAttr {
ext?: string;
readonly hidable = false;
icon?: vscode.ThemeIcon;
openViewType?: string;
readonly collapsibleState = vscode.TreeItemCollapsibleState.Collapsed;
}

class ProductArtifactAttr implements ArtifactAttr {
ext?: string;
hidable?: boolean;
icon?: vscode.ThemeIcon;
openViewType?: string;
readonly collapsibleState = vscode.TreeItemCollapsibleState.None;
}

export interface IArtifactAttrProvider {
to: (type: ArtifactType) => ArtifactAttr;
}

export class ArtifactAttrProvider implements IArtifactAttrProvider {
to(type: ArtifactType): ArtifactAttr {
switch (type) {
case "DIRECTORY":
return DIRECTORY_ARTIFACT_ATTR;
case "BASEMODEL_TFLITE":
return BASEMODEL_TFLITE_ARTIFACT_ATTR;
case "BASEMODEL_ONNX":
return BASEMODEL_ONNX_ARTIFACT_ATTR;
case "BASEMODEL_PB":
return BASEMODEL_PB_ARTIFACT_ATTR;
case "CONFIG_ONE":
return CONFIG_ONE_ARTIFACT_ATTR;
case "PRODUCT_CIRCLE":
return PRODUCT_CIRCLE_ARTIFACT_ATTR;
case "PRODUCT_TVN":
return PRODUCT_TVN_ARTIFACT_ATTR;
case "PRODUCT_MONDRIAN":
return PRODUCT_MONDRIAN_ARTIFACT_ATTR;
case "PRODUCT_CHROME_TRACE":
return PRODUCT_CHROME_TRACE_ARTIFACT_ATTR;
case "PRODUCT_TV2W":
return PRODUCT_TV2W_ARTIFACT_ATTR;
case "PRODUCT_TV2O":
return PRODUCT_TV2O_ARTIFACT_ATTR;
case "PRODUCT_TV2M":
return PRODUCT_TV2M_ARTIFACT_ATTR;
case "PRODUCT_CIRCLE_LOG":
return PRODUCT_CIRCLE_LOG_ARTIFACT_ATTR;
}
}
}

// DIRECTORY //
export const DIRECTORY_ARTIFACT_ATTR: DirectoryArtifactAttr = {
ext: undefined,
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: undefined,
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
};

// BASEMODEL //
export const BASEMODEL_TFLITE_ARTIFACT_ATTR: BaseModelArtifactAttr = {
ext: ".tflite",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.viewer.circle",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
};

export const BASEMODEL_ONNX_ARTIFACT_ATTR: BaseModelArtifactAttr = {
ext: ".onnx",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.viewer.circle",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
};

export const BASEMODEL_PB_ARTIFACT_ATTR: BaseModelArtifactAttr = {
ext: ".pb",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.viewer.circle",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
};

// CONFIG //
export const CONFIG_ONE_ARTIFACT_ATTR : ConfigArtifactAttr = {
ext: ".cfg",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.editor.cfg",
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
};

// PRODUCT //
export const PRODUCT_CIRCLE_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".circle",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.viewer.circle",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};

export const PRODUCT_TVN_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".tvn",
hidable: false,
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};

export const PRODUCT_MONDRIAN_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".tracealloc.json",
hidable: true,
icon: new vscode.ThemeIcon("graph"),
openViewType: "one.viewer.mondrian",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
export const PRODUCT_CHROME_TRACE_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".json",
hidable: true,
icon: new vscode.ThemeIcon("graph"),
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
export const PRODUCT_TV2M_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".tv2m",
hidable: true,
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
export const PRODUCT_TV2O_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".tv2o",
hidable: true,
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
export const PRODUCT_TV2W_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".tv2w",
hidable: true,
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
export const PRODUCT_CIRCLE_LOG_ARTIFACT_ATTR: ProductArtifactAttr = {
ext: ".circle.log",
hidable: true,
icon: vscode.ThemeIcon.File,
openViewType: "default",
collapsibleState: vscode.TreeItemCollapsibleState.None,
};
77 changes: 8 additions & 69 deletions src/OneExplorer/ArtifactLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,7 @@

import * as assert from "assert";
import * as path from "path";
import * as vscode from "vscode";

/**
* 'Artifact'
* The collective term is and inclusive, it includes two types of files:
* (1) Pre-existing files to run ONE config, a.k.a. base models (.tflite, .onnx, ...)
* (2) Result files after running ONE config, a.k.a. products (.circle, .log, ...)
*/
export interface Artifact {
/**
* An artifact's attribute
*/
attr: ArtifactAttr;

/**
* A full path in file system
*/
path: string;
}

export interface ArtifactAttr {
/**
* ABOUT EXTENDED EXTENSION (WITH MULTIPLE PERIODS, *.extended.ext)
*
* Generally, file name extensions are defined from the last period.
* Let's define 'extended file extension' with multiple periods.
*
* EXAMPLE
*
* (File name) model.opt.circle.log
* (Extension) .log
* (Extended Extension) .circle.log OR opt.circle.log (selective)
*/
ext: string;

/**
* An icon for the artifact
*
* If not set, it is set by OneExplorer Node.
*/
icon?: vscode.ThemeIcon;

/**
* A openViewType for the artifact
*
* It is used as an argument for 'vscode.openWith' command
* to open the file with specified editor.
*
* If not set, it is set by OneExplorer Node.
* If 'default'(string), open with text editor
*
* @reference vscode.openWith
*/
openViewType?: string;

/**
* Hidden from the default view.
* The status can be unhide by command
*/
canHide?: boolean;
}
import {ArtifactType} from "./Artifact";

/**
* 'Locator' is to grep matching paths inside Ini Object
Expand Down Expand Up @@ -210,7 +150,7 @@ export class Locator {

// TODO Move to backend side with some modification
export class LocatorRunner {
private artifactLocators: { artifactAttr: ArtifactAttr; locator: Locator }[] =
private artifactLocators: { type: ArtifactType, locator: Locator }[] =
[];

/**
Expand Down Expand Up @@ -266,7 +206,7 @@ export class LocatorRunner {
};

public register(artifactLocator: {
artifactAttr: ArtifactAttr;
type: ArtifactType;
locator: Locator;
}) {
this.artifactLocators.push(artifactLocator);
Expand All @@ -275,22 +215,21 @@ export class LocatorRunner {
/**
* @brief Run registered locators
*
* @returns Artifact[] with paths
* @returns {ArtifactType: type, path: string}[] with paths
*/
public run(iniObj: object, dir: string): Artifact[] {
public run(iniObj: object, dir: string): {type:ArtifactType, path:string}[] {
assert.strictEqual(
path.isAbsolute(dir),
true,
"FIX CALLER: dir argument must be an absolute path"
);

let artifacts: Artifact[] = [];
let artifacts: {type:ArtifactType, path:string}[] = [];

// Get Artifacts with {type, ext, path}
this.artifactLocators.forEach(({ artifactAttr, locator }) => {
this.artifactLocators.forEach(({ type, locator }) => {
let filePaths: string[] = locator.locate(iniObj, dir);
filePaths.forEach((filePath) => {
let artifact: Artifact = { attr: artifactAttr, path: filePath };
let artifact = { type: type, path: filePath };
artifacts.push(artifact);
});
});
Expand Down
Loading