-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metric Comparison + API Updates (#274)
* `openlane.common` * Created new function `get_latest_file`, that finds the latest file with a certain filename in a specific folder * Created new `Filter` object aggregating the functionality of wildcards * Created new module `openlane.common.metrics` to aggregate functions dealing with metrics, replacing previous file * `__main__` file of this module has three commands, `compare`, `compare-multiple`, `compare-main`: * `compare`: Compares two metrics files and generates an output summary * `compare-multiple`: Compares two folders of metrics files and generates an output summary * `compare-main`: Compares a folder of metric files with metrics fetched from `efabless/openlane-metrics` and generates an output summary * New `Metric` object created, encapsulating the metric name, its aggregator, and some other functionality related to evaluating changes in metrics * Also allowed some metrics to exclude some groups from aggregation, e.g. `iter` for routing metrics * Created "library" of `Metrics` of the various metrics we aggregated so far * `aggregate_metrics` now uses the metric library for aggregators as a default value * Updated parsing of metrics to more closely match https://github.com/ieee-ceda-datc/datc-rdf-Metrics4ML: the format for modifiers was wrong * `openlane.state` * Created `__main__` file that returns the latest state for a run directory (using `get_latest_file`, with an options to extract the metrics thereof for a file (useful for scripts) * `openlane.config.Config`: * Updated `refg::` to return the glob string verbatim if the glob returns no results * `openlane.config.Macro`: * Created new method `from_state` that automatically creates a `Macro` object from a `State` object * Created new object, `ScopedFile`, which is a file that's deleted as soon as it's deconstructed * `KLayout.*`: * Unified generation of commandline arguments using `.get_cli_args()` * Updated scripts to use `%OL_METRIC_I` instead of having to use other communication channels * Made sure all paths passed to KLayout commands are absolute because KLayout loves to not use CWD for relative paths * `Magic.*`: * Fixed bug when `MAGICRC` is a relative path * `Netgen.LVS`, `Checker.LVS`: * Updated metric names for grammatical consistency * Added `httpx` to replace `requests` as the dependency for HTTP functions ## CI and Testing * Added function in CI to test every PR against the current `main` function * Added `pytest-xdist` to dev dependencies, so multiple tests can be run in parallel --------- Co-authored-by: Kareem Farid <kareefardi@users.noreply.github.com>
- Loading branch information
1 parent
85b2aa0
commit 20b06be
Showing
52 changed files
with
2,176 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.v linguist-detectable=false | ||
openlane/smoke_test_design/* linguist-detectable=false | ||
.github/* linguist-detectable=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env node | ||
// Copyright 2023 Efabless Corporation | ||
// | ||
// 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. | ||
/** | ||
* @param {string} verbosity | ||
* @param {string} token | ||
* @returns {string} | ||
*/ | ||
function get(verbosity, table_out = null, token = "") { | ||
const { spawnSync } = require("child_process"); | ||
|
||
let tableOutOpts = table_out ? ["--table-out", table_out] : []; | ||
|
||
let child = spawnSync("python3", ["-m", "openlane.common.metrics", "compare-main", "current", "--table-verbosity", verbosity, "--token", token].concat(tableOutOpts), { encoding: "utf8" }); | ||
|
||
let result = ""; | ||
if (child.status != 0) { | ||
throw new Error("Failed to create report: \n\n```\n" + child.stderr + "\n```"); | ||
} else { | ||
result += "Metric comparisons are in beta. Please report bugs under the issues tab.\n---\n"; | ||
result += "> To create this report yourself, grab the metrics artifact from the CI run, extract them, and invoke `python3 -m openlane.common.metrics compare-main <path to directory>`.\n\n" + child.stdout; | ||
} | ||
|
||
return result.trim(); | ||
}; | ||
|
||
module.exports = get; | ||
|
||
if (require.main === module) { | ||
console.log(get("ALL", "table.md", process.argv[2])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env node | ||
// Copyright 2023 Efabless Corporation | ||
// | ||
// 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. | ||
|
||
const compareMain = require("./compare_main.js"); | ||
|
||
/** | ||
* | ||
* @param {Octokit} github | ||
* @param {object} context | ||
* @param {string} botUsername | ||
* @param {string} body | ||
*/ | ||
async function postOrUpdateComment(github, context, botUsername, body) { | ||
const METRIC_REPORT_MARK = "<!-- MARK: METRICS REPORT -->"; | ||
|
||
let page = 1; | ||
let allComments = []; | ||
let comments = []; | ||
do { | ||
let response = await github.request("GET /repos/{owner}/{repo}/issues/{issue_number}/comments?page={page}&per_page=100", { | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
page, | ||
}); | ||
comments = response.data; | ||
allComments = allComments.concat(comments); | ||
page += 1; | ||
} while (comments.length != 0); | ||
|
||
let found = null; | ||
for (let comment of allComments) { | ||
if (comment.body.includes(METRIC_REPORT_MARK) && comment.user.login == botUsername) { | ||
found = comment; | ||
break; | ||
} | ||
} | ||
|
||
let fn = github.rest.issues.createComment; | ||
let request = { | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `${METRIC_REPORT_MARK}\n\n${body}` | ||
}; | ||
|
||
if (found) { | ||
request.comment_id = found.id; | ||
fn = github.rest.issues.updateComment; | ||
} | ||
|
||
await fn(request); | ||
} | ||
|
||
/** | ||
* | ||
* @param {Octokit} github | ||
* @param {object} context | ||
* @param {string} botUsername | ||
* @param {string} botToken | ||
*/ | ||
async function main(github, context, botUsername, botToken) { | ||
const fs = require("fs"); | ||
|
||
let body; | ||
try { | ||
body = compareMain("ALL", "./tables_all.md", botToken); | ||
let tables = fs.readFileSync("./tables_all.md", { encoding: "utf8" }); | ||
|
||
let gistResponse = await github.rest.gists.create({ | ||
public: true, | ||
description: `Results for ${context.repo.owner} / ${context.repo.repo}#${context.issue.number} (Run ${context.runId})`, | ||
files: { | ||
"10-ALL.md": { | ||
content: tables | ||
} | ||
} | ||
}); | ||
|
||
body += `\n\nFull tables ► ${gistResponse.data.html_url}\n`; | ||
} catch (e) { | ||
body = e.message; | ||
console.error(e.message) | ||
} | ||
|
||
await postOrUpdateComment(github, context, botUsername, body) | ||
} | ||
|
||
module.exports = main; | ||
|
||
if (require.main === module) { | ||
// Test | ||
try { | ||
require("@octokit/rest"); | ||
} catch (error) { | ||
console.error("Run 'yarn add @octokit/rest @octokit/plugin-paginate-rest'") | ||
process.exit(-1); | ||
} | ||
const { Octokit } = require("@octokit/rest"); | ||
|
||
const context = { | ||
repo: { | ||
owner: "efabless", | ||
repo: "openlane2" | ||
}, | ||
issue: { | ||
number: process.argv[3] | ||
}, | ||
runId: "api_test" | ||
}; | ||
|
||
let octokit = new Octokit({ | ||
auth: process.argv[2], | ||
}); | ||
|
||
main(octokit, context, "openlane-bot", process.argv[2]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ with pkgs; let | |
openlane | ||
pyfakefs | ||
pytest | ||
pytest-xdist | ||
pillow | ||
mdformat | ||
] | ||
|
Oops, something went wrong.