Repository Public
1/**2 * The `config` options of each simulation kind, as form fields. Mirrors src/sim/README.md; the unit tests check3 * every key against the registry (`configKeys`) so the two cannot drift apart silently.4 */5import type { Locale, SimKind } from "@/schema";6import { paramDefs } from "@/sim/registry";78type L = Record<Locale, string>;9const l = (fr: string, en: string): L => ({ fr, en });1011interface FieldBase { key: string; label: L; hint?: L }12export type ConfigField =13 | (FieldBase & { kind: "select"; options: readonly { value: string | number; label: L }[] })14 | (FieldBase & { kind: "text"; maxLength: number; mono?: boolean; required?: boolean; placeholder?: string })15 | (FieldBase & { kind: "number"; min?: number; max?: number; integer?: boolean; placeholder?: string })16 | (FieldBase & { kind: "boolean" });1718const expr = (key: string, n: number, required = false): ConfigField => ({19 key, kind: "text", maxLength: 300, mono: true, required, placeholder: n === 1 ? "a * sin(x)" : undefined,20 label: l(n === 1 ? "Expression f(x)" : `Expression ${n}`, n === 1 ? "Expression f(x)" : `Expression ${n}`),21 hint: n === 1 ? l("Nombres, x, noms de paramètres, + − * / ^, parenthèses, pi, e, exp log sqrt abs sin cos tan tanh sigmoid relu max min pow floor. Chaque nom autre que x devient un curseur (5 au plus).", "Numbers, x, parameter names, + − * / ^, parentheses, pi, e, exp log sqrt abs sin cos tan tanh sigmoid relu max min pow floor. Every name other than x becomes a slider (at most 5).") : undefined,22});23const curveLabel = (key: string, n: number): ConfigField => ({ key, kind: "text", maxLength: 80, label: l(`Légende de la courbe ${n}`, `Legend of curve ${n}`) });24const bound = (key: string, fr: string, en: string, placeholder?: string): ConfigField => ({ key, kind: "number", label: l(fr, en), placeholder });2526export const SIM_CONFIG: Record<SimKind, ConfigField[]> = {27 "moe-routing": [],28 "neural-forward": [{ key: "activation", kind: "select", label: l("Fonction d’activation", "Activation function"), options: [{ value: "tanh", label: l("tanh", "tanh") }, { value: "relu", label: l("ReLU", "ReLU") }, { value: "sigmoid", label: l("Sigmoïde", "Sigmoid") }] }],29 "kv-cache": [],30 attention: [31 { key: "tokens", kind: "text", maxLength: 300, label: l("Mots (séparés par des virgules)", "Tokens (comma-separated)"), hint: l("De 2 à 10 mots. Vide : la phrase d’exemple.", "2 to 10 tokens. Empty: the example sentence."), placeholder: "le,chat,dort,sur,le,tapis" },32 { key: "causal", kind: "boolean", label: l("Masque causal (chaque mot ne voit que les précédents)", "Causal mask (each token only sees the previous ones)") },33 ],34 distribution: [{ key: "family", kind: "select", label: l("Loi", "Family"), hint: l("Les curseurs dépendent de la loi choisie.", "The sliders depend on the family."), options: [35 { value: "normal", label: l("Normale", "Normal") }, { value: "student", label: l("Student", "Student t") }, { value: "lognormal", label: l("Log-normale", "Log-normal") },36 { value: "exponential", label: l("Exponentielle", "Exponential") }, { value: "uniform", label: l("Uniforme", "Uniform") },37 ] }],38 "confidence-interval": [],39 regression: [],40 correlation: [],41 garch: [],42 "random-walk": [43 { key: "process", kind: "select", label: l("Processus", "Process"), hint: l("Les curseurs dépendent du processus choisi.", "The sliders depend on the process."), options: [44 { value: "brownian", label: l("Mouvement brownien", "Brownian motion") }, { value: "gbm", label: l("Brownien géométrique", "Geometric Brownian motion") }, { value: "ou", label: l("Ornstein–Uhlenbeck", "Ornstein–Uhlenbeck") },45 ] },46 { key: "x0", kind: "number", label: l("Valeur de départ x₀", "Starting value x₀"), hint: l("Vide : 0 (brownien), 100 (géométrique, doit être positif), 2 (Ornstein–Uhlenbeck).", "Empty: 0 (Brownian), 100 (geometric, must be positive), 2 (Ornstein–Uhlenbeck).") },47 ],48 "impulse-response": [{ key: "shock", kind: "select", label: l("Variable qui reçoit le choc", "Variable that receives the shock"), options: [{ value: 1, label: l("y₁", "y₁") }, { value: 2, label: l("y₂", "y₂") }] }],49 "event-study": [{ key: "window", kind: "number", min: 3, max: 20, integer: true, placeholder: "10", label: l("Fenêtre (jours de chaque côté de l’événement)", "Window (days on each side of the event)"), hint: l("Entier de 3 à 20. Vide : 10.", "Integer from 3 to 20. Empty: 10.") }],50 "function-plot": [51 expr("expr", 1, true), curveLabel("label", 1),52 expr("expr2", 2), curveLabel("label2", 2), expr("expr3", 3), curveLabel("label3", 3), expr("expr4", 4), curveLabel("label4", 4),53 bound("xMin", "x minimum", "x minimum", "-5"), bound("xMax", "x maximum", "x maximum", "5"),54 bound("yMin", "y minimum (vide : automatique)", "y minimum (empty: automatic)"), bound("yMax", "y maximum (vide : automatique)", "y maximum (empty: automatic)"),55 { key: "xLabel", kind: "text", maxLength: 80, label: l("Titre de l’axe horizontal", "Horizontal axis title") },56 { key: "yLabel", kind: "text", maxLength: 80, label: l("Titre de l’axe vertical", "Vertical axis title") },57 ],58};5960/** function-plot: bounds and step of the slider of each parameter found in the expressions. */61export function sliderBoundFields(kind: SimKind, config: Readonly<Record<string, string | number | boolean>>): ConfigField[] {62 if (kind !== "function-plot") return [];63 return paramDefs(kind, config).flatMap((d) => [64 bound(`${d.key}Min`, `${d.key} : minimum du curseur`, `${d.key}: slider minimum`, "-5"),65 bound(`${d.key}Max`, `${d.key} : maximum du curseur`, `${d.key}: slider maximum`, "5"),66 bound(`${d.key}Step`, `${d.key} : pas du curseur`, `${d.key}: slider step`),67 ]);68}69