Skip to content

Commit

Permalink
Merge pull request #184 from herbie-fp/zane-sc-concrete-values
Browse files Browse the repository at this point in the history
Touch up for SC
  • Loading branch information
elmisback authored Nov 13, 2024
2 parents 9e2253c + 73821e0 commit 5d29f01
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/herbie/HerbieContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const AnalysesContext = makeGlobal([] as types.ErrorAnalysis[])
export const CostContext = makeGlobal([] as types.CostAnalysis[])
export const SpecContext = makeGlobal(new types.Spec('', 0) as types.Spec)
//@ts-ignore
export const ServerContext = makeGlobal('https://herbie.uwplse.org/demo')//window.acquireVsCodeApi ? 'http://127.0.0.1:8000' : 'https://herbie.uwplse.org/demo')
export const ServerContext = makeGlobal('https://herbie.uwplse.org/demo')//makeGlobal('http://127.0.0.1:8000')//window.acquireVsCodeApi ? '' : 'https://herbie.uwplse.org/demo')
//@ts-ignore
export const FPTaylorServerContext = makeGlobal(window.acquireVsCodeApi ? 'http://localhost:8888/fptaylor' : 'https://herbie.uwplse.org/fptaylor')
//@ts-ignore
Expand Down
3 changes: 2 additions & 1 deletion src/herbie/HerbieTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export interface LocalErrorTree {
'avg-error': string
'exact-value': string
'actual-value': string
'absolute-error': string
'abs-error-difference': string
'percent-accuracy': string
}

export class AverageLocalErrorAnalysis {
Expand Down
51 changes: 38 additions & 13 deletions src/herbie/LocalError/LocalError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,39 @@ function localErrorTreeAsMermaidGraph(tree: types.LocalErrorTree, bits: number,
let colors = {} as Record<string, string>
let counter = 0


const isLeaf = (n: types.LocalErrorTree ) => n['children'].length === 0

function formatName(id: string, name: string, exact_err: string, approx_value: string, true_error: string, ulps_error: string) {
const tooltipContent = `'Correct R : ${herbiejs.displayNumber(Number(exact_err))} <br /> Approx F : ${herbiejs.displayNumber(Number(approx_value))} <br /> Error R - F : ${herbiejs.displayNumber(Number(true_error))} <br /> ULPs Error : ${herbiejs.displayNumber(Number(ulps_error))}'`;
function makeNodeInfo(id: string, name: string,
exact_err: string, approx_value: string,
abs_error_difference: string, percent: string,
_explanation?: string) {
var explanation_str = ""
if (typeof _explanation !== 'undefined') {
explanation_str = ` <br /> Error Code : ${_explanation}`
}
var difference_str = ` <br /> Error R - F : ${displayError(abs_error_difference)}`
if (abs_error_difference === "invalid"
|| abs_error_difference === "unsamplable"
|| abs_error_difference === "equal") {
console.debug(`abs_error was 'equal, 'invalid, or 'unsamplable: ${difference_str}`)
difference_str = ""
}
var accuracy_str = ""
if (!(abs_error_difference === "equal")) {
accuracy_str = ` <br /> Percent Accuracy : ${herbiejs.displayNumber(Number(percent))}%${explanation_str}`
}
const tooltipContent = `'Correct R : ${displayError(exact_err)} <br /> Approx F : ${displayError(approx_value)}${difference_str}${accuracy_str}'`;
return id + '[<span class=nodeLocalError data-tooltip-id=node-tooltip data-tooltip-html=' + tooltipContent + '>' + name + '</span>]'
}
function errorFormat(id: string, name: string, exact_err: string, approx_value: string, true_error: string, ulps_error: string) {
const tooltipContent = `'Correct R : ${herbiejs.displayNumber(Number(exact_err))} <br /> Approx F : ${herbiejs.displayNumber(Number(approx_value))} <br /> Error R - F : ${herbiejs.displayNumber(Number(true_error))} <br /> ULPs Error : ${herbiejs.displayNumber(Number(ulps_error))} <br /> Explanation : ${explanation}'`;
return id + '[<span class=nodeLocalError data-tooltip-id=node-tooltip data-tooltip-html=' + tooltipContent + '>' + name + '</span>]'

function displayError(abs_error: string) {
if (abs_error === "invalid" || abs_error === "unsamplable"
|| abs_error === "+inf.0" || abs_error === "-inf.0"
|| abs_error === "true" || abs_error === "false") {
return abs_error
} else {
return herbiejs.displayNumber(Number(abs_error))
}
}

const locationsMatch = (loc1: Array<number>, loc2: Array<number>) =>
Expand All @@ -36,17 +59,18 @@ function localErrorTreeAsMermaidGraph(tree: types.LocalErrorTree, bits: number,
const avg_error = n['avg-error']
const exact_value = n['exact-value']
const approx_value = n['actual-value']
const true_error = n['absolute-error']
const ulps = n['ulps-error']
const true_error = n['abs-error-difference']
const ulps = n['ulps-error'] // unused maybe log to debug?
const percent = n['percent-accuracy']

// node name
const id = 'N' + counter++
let nodeName = "";
// Check if the current location matches the target location
if (locationsMatch(currentLoc, targetLocation)) {
nodeName = errorFormat(id, name, exact_value,approx_value, true_error, ulps)
nodeName = makeNodeInfo(id, name, exact_value, approx_value, true_error, percent, explanation)
}else{
nodeName = formatName(id, name, exact_value,approx_value, true_error, ulps)
nodeName = makeNodeInfo(id, name, exact_value, approx_value, true_error, percent)
}
// descend through AST
for (const [index, child] of children.entries()) {
Expand All @@ -70,10 +94,11 @@ function localErrorTreeAsMermaidGraph(tree: types.LocalErrorTree, bits: number,
const name = tree['e']
const exact_value = tree['exact-value']
const approx_value = tree['actual-value']
const true_error = tree['absolute-error']
const true_error = tree['abs-error-difference']
const ulps = tree['ulps-error']
const percent = tree['percent-accuracy']

edges.push(formatName('N0', name, exact_value,approx_value, true_error, ulps))
edges.push(makeNodeInfo('N0', name, exact_value, approx_value, true_error, percent))
}

// List colors
Expand Down Expand Up @@ -112,7 +137,7 @@ function LocalError({ expressionId }: { expressionId: number }) {
// Add a delay before running the effect's logic
const timer = setTimeout(() => {
const labels = document.querySelectorAll('.node[class*="flowchart-label"]');
console.log("in")
console.debug("in")
labels.forEach(label => {
const labelGroup = label.querySelector('.label');
if (labelGroup) {
Expand Down
2 changes: 1 addition & 1 deletion src/herbie/lib/herbiejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const getHerbieApi = async (
"cost"
]
// If async API available use that instead.
if (asyncEndpoints.includes(endpoint)) {
if (false && asyncEndpoints.includes(endpoint)) {
return getHerbieApiAsync(host, endpoint, data, retry);
}

Expand Down

0 comments on commit 5d29f01

Please sign in to comment.