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
25 changes: 25 additions & 0 deletions packages/ui/src/amicode/amicode.css
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,31 @@
[data-component="amicode-system-view"] .amc-c-lvl { color: var(--v2-text-text-muted); font-size: 0.8rem; }
[data-component="amicode-system-view"] .amc-c-params { color: var(--v2-text-text-base); font-size: 0.8rem; }
[data-component="amicode-system-view"] .amc-ev-formula { margin-top: 4px; }
/* Provenance on a section header. A RECORDED Hamiltonian is shown bare; an
inferred one — the canonical form for the platform, which nobody stated —
has to say so, or the card is asserting physics it guessed. Sits before the
::after rule so the hairline still fills the remaining width. */
[data-component="amicode-entity-view"] .amc-ev-sec-note {
font-size: 9px;
letter-spacing: 0.04em;
text-transform: none;
color: var(--v2-text-text-faint);
font-style: italic;
}
/* The "no model recorded" placeholder reads as a prompt, not as an equation. */
[data-component="amicode-system-view"] .amc-ev-formula.is-empty {
color: var(--v2-text-text-faint);
font-size: 0.82rem;
font-style: italic;
background: transparent;
border-style: dashed;
}
/* Conventions the recorded terms assume (frame, units, basis ordering). */
[data-component="amicode-system-view"] .amc-ev-formula-note {
margin: -2px 4px 4px;
font-size: 0.72rem;
color: var(--v2-text-text-faint);
}

/* ---- Formulation hero (spec §6.2): mode badges + objective + constraints ---- */
[data-component="amicode-formulation-view"] { display: flex; flex-direction: column; gap: 8px; }
Expand Down
30 changes: 30 additions & 0 deletions packages/ui/src/amicode/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,22 @@ export interface SystemProjection {
topology?: string
components: { id: string; role: string; levels?: number; params: Record<string, number> }[]
couplings: { between: string[]; kind: string; params: Record<string, number> }[]
/** The model the researcher CONFIRMED, term by term (amicode_set_model's
* `hamiltonian`). Present → the card renders exactly this; absent → it falls
* back to a canonical form for the platform and labels it as inferred. */
hamiltonian?: { terms: HamiltonianTermProjection[]; notes?: string }
notes?: string
/** false = a legacy FLAT entity read-collapsed to N=1 (no couplings). */
isComposite: boolean
}

export interface HamiltonianTermProjection {
kind: string
latex: string
acts_on?: string[]
label?: string
}

const asNumberRecord = (v: unknown): Record<string, number> => {
const out: Record<string, number> = {}
if (typeof v === "object" && v !== null) {
Expand All @@ -526,6 +537,24 @@ const asNumberRecord = (v: unknown): Record<string, number> => {
return out
}

/** Recorded Hamiltonian, tolerant of raw JSON: a term without usable `latex` is
* dropped rather than rendered as a hole, and an empty result reads as "nothing
* recorded" so the card falls back to inference instead of showing `Ĥ/ℏ = `. */
const asHamiltonian = (v: unknown): SystemProjection["hamiltonian"] => {
if (typeof v !== "object" || v === null) return undefined
const raw = v as Record<string, unknown>
if (!Array.isArray(raw.terms)) return undefined
const terms = (raw.terms as Record<string, unknown>[])
.filter((t) => t && typeof t.latex === "string" && t.latex.trim() !== "")
.map((t) => ({
kind: typeof t.kind === "string" ? t.kind : "drift",
latex: t.latex as string,
...(Array.isArray(t.acts_on) ? { acts_on: (t.acts_on as unknown[]).map(String) } : {}),
...(typeof t.label === "string" ? { label: t.label } : {}),
}))
return terms.length === 0 ? undefined : { terms, ...(typeof raw.notes === "string" ? { notes: raw.notes } : {}) }
}

/** Structured projection for the entity view (spec §3 point 3). Composite → read
* through; legacy flat → collapse to N=1 in place (role from platform: rydberg→atom
* else qubit — mirrors normalizeSystem without importing it). Never throws. */
Expand All @@ -550,6 +579,7 @@ export function systemProjection(input: Record<string, unknown>): SystemProjecti
kind: str(cp.kind) ?? "?",
params: asNumberRecord(cp.params),
})),
...(asHamiltonian(entity.hamiltonian) ? { hamiltonian: asHamiltonian(entity.hamiltonian) } : {}),
...(typeof entity.notes === "string" ? { notes: entity.notes } : {}),
isComposite: true,
}
Expand Down
Loading
Loading