Skip to content
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

Calling server side pcontext #219

Draft
wants to merge 1 commit into
base: zane-remove-cost-sample
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
2 changes: 2 additions & 0 deletions src/herbie/HerbieTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ export type expressionError = number
// LATER probably don't need ExpressionError in this
export class Sample {
constructor(
public readonly job: string,
public readonly points: [ordinalPoint, expressionError][],
public readonly specId: number,
public readonly inputRangesId: number,
public readonly id: number) {
this.job = job;
this.points = points;
this.specId = specId;
this.inputRangesId = inputRangesId;
Expand Down
8 changes: 5 additions & 3 deletions src/herbie/HerbieUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,11 @@ function HerbieUIInner() {
return // should never get here
}

const sample_points = (await herbiejs.getSample(fpCore, serverUrl)).points;
const sample_json = (await herbiejs.getSample(fpCore, serverUrl));
console.log(`SAMPLE:${sample_json['job']}`)
const sample_points = sample_json.points;
// always create a new sample with this spec and these input ranges
const sample = new Sample(sample_points, spec.id, inputRanges.id, nextId(samples))
const sample = new Sample(sample_json['job']!, sample_points, spec.id, inputRanges.id, nextId(samples))
setSamples([...samples, sample]);
console.debug(`Sampled spec ${spec.id} for input ranges ${inputRanges.id}:`, sample)
}
Expand Down Expand Up @@ -362,7 +364,7 @@ function HerbieUIInner() {
// HACK to make sampling work on Herbie side
const vars = fpcorejs.getVarnamesMathJS(expression.text)
const specVars = fpcorejs.getVarnamesMathJS(spec.expression)
const modSample = new Sample(sample.points.map(([x, y], _) => [x.filter((xi, i) => vars.includes(specVars[i])), y]), sample.specId, sample.inputRangesId, sample.id)
const modSample = new Sample(sample.job, sample.points.map(([x, y], _) => [x.filter((xi, i) => vars.includes(specVars[i])), y]), sample.specId, sample.inputRangesId, sample.id)
const localErrorTree = (await herbiejs.analyzeLocalError(fpcorejs.mathjsToFPCore(expression.text, /*fpcorejs.mathjsToFPCore(spec.expression)*/), modSample, serverUrl))
return new Types.AverageLocalErrorAnalysis(expression.id, sample.id, localErrorTree)
// updates.push(new Types.AverageLocalErrorAnalysis(expression.id, sample.id, localErrorTree))
Expand Down
4 changes: 2 additions & 2 deletions src/herbie/lib/herbiejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface HerbieResponse {
mathjs?: string;
points: any[];
tree?: types.LocalErrorTree;
job?: string;
}

const getHerbieApiAsync = async (
Expand Down Expand Up @@ -226,8 +227,7 @@ export const analyzeExpression = async (
};



const pointsAndErrors = ((await getHerbieApi(host, 'analyze', { formula: fpcore, sample: sample.points, seed: 5 }, true)) as AnalyzeResponse).points;
const pointsAndErrors = ((await getHerbieApi(host, 'analyze-hashed', { formula: fpcore, sample_hash: sample['job'], seed: 5 }, true)) as AnalyzeResponse).points;
const ordinalSample = pointsAndErrors.map(p => p[0].map((v: number) => ordinalsjs.floatToApproximateOrdinal(v)));

// console.log('first 10 pointsAndErrors', pointsAndErrors.map(([point, error]) => point).slice(0, 10));
Expand Down