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
14 changes: 14 additions & 0 deletions packages/ui/src/amicode/problem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ describe("runChipText", () => {
test("solving f outside [0,1] renders no F readout (objective ≠ fidelity)", () => {
expect(runChipText([{ runId: "r", status: "solving", fidelity: 79.3, iteration: 0 }])).toBe("solving…")
})
test("near-unity fidelity never rounds to a bare 1 — precision extends until the gap shows", () => {
expect(runChipText([{ runId: "r", status: "finished", fidelity: 0.99997, iteration: 60 }])).toBe(
"F=0.99997 · 60 iter",
)
expect(runChipText([{ runId: "r", status: "finished", fidelity: 0.99999997, iteration: 60 }])).toBe(
"F=0.99999997 · 60 iter",
)
// solving mirror: a tiny live objective is a near-unity F
expect(runChipText([{ runId: "r", status: "solving", fidelity: 0.00003, iteration: 12 }])).toBe(
"solving… F=0.99997",
)
// a true 1 (and only a true 1) still renders bare
expect(runChipText([{ runId: "r", status: "finished", fidelity: 1, iteration: 60 }])).toBe("F=1 · 60 iter")
})
})

describe("railState", () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/ui/src/amicode/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,17 @@ export function mergeChips(entities: Record<string, Record<string, unknown>>, sc
// --- run chip ----------------------------------------------------------------

function formatFidelity(value: number): string {
// up to 4 significant decimals, trailing zeros trimmed
return String(Number(value.toFixed(4)))
// 4 decimals for ordinary values (trailing zeros trimmed) — but NEVER let
// rounding collapse a near-unity or near-zero fidelity into exactly "1"/"0":
// the gap from perfect IS the result (Kate 2026-07-28, a 0.99997 run showed
// "F = 1"). Precision extends one digit at a time until the gap survives,
// capped at 10; only a true 1 or 0 renders bare.
if (value === 1 || value === 0) return String(value)
for (let digits = 4; digits <= 10; digits++) {
const rounded = Number(value.toFixed(digits))
if (rounded !== 1 && rounded !== 0) return String(rounded)
}
return String(value)
}

export function runChipText(statuses: RunStatusView[]): string | undefined {
Expand Down
Loading