autodiff-dev / frontends /react /src /flowTiming.ts
nhamid289's picture
Deploy autodiff ff35e9c
b9499ab verified
Raw History Blame Contribute Delete
1.52 kB
import type { Step } from "./types";
// Forward pass: copies of the numbers travel to the node, the operation is applied, the result settles above it
export const TRAVEL_MS = 900;
export const APPLY_MS = 750;
const RESULT_HOLD_MS = 350;
export const SETTLE_MS = 500;
export const RESULT_AT = TRAVEL_MS + APPLY_MS;
export const SETTLE_AT = RESULT_AT + RESULT_HOLD_MS;
export const FORWARD_MS = SETTLE_AT + SETTLE_MS;
// The backward pass starts with the seed moving from f to the output node
export const SEED_HOLD_MS = 300;
export const SEED_TRAVEL_MS = 700;
export const SEED_MS = SEED_HOLD_MS + SEED_TRAVEL_MS + SETTLE_MS;
// A derivative goes halfway along each edge, is multiplied by the edge's partial, carries on
// to the far end, and is added to what's there. These times count from when it sets off.
export const OUT_MS = 650;
const MULTIPLY_MS = 750;
const PRODUCT_MS = 350;
export const IN_MS = 650;
const LAND_MS = 500;
const SUM_MS = 200;
export const PRODUCT_AT = OUT_MS + MULTIPLY_MS;
export const IN_AT = PRODUCT_AT + PRODUCT_MS;
export const LAND_AT = IN_AT + IN_MS;
export const SUM_AT = LAND_AT + LAND_MS;
export const FADE_AT = SUM_AT + SUM_MS;
export const DERIVATIVE_MS = FADE_AT + SETTLE_MS;
export function flowDuration(step: Step): number {
if (step.phase === "forward") {
// Forward mode's tangents set off as the value settles
return step.derivative === undefined ? FORWARD_MS : SETTLE_AT + DERIVATIVE_MS;
}
return step.partials.length === 0 ? SEED_MS : DERIVATIVE_MS;
}