universal-physics-tensor 0.24.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -9
- package/bin/upt.mjs +843 -685
- package/dist/canonical/entries/atomic.d.ts +17 -0
- package/dist/canonical/entries/atomic.d.ts.map +1 -0
- package/dist/canonical/entries/atomic.js +71 -0
- package/dist/canonical/entries/atomic.js.map +1 -0
- package/dist/canonical/entries/electromagnetism.d.ts +18 -0
- package/dist/canonical/entries/electromagnetism.d.ts.map +1 -0
- package/dist/canonical/entries/electromagnetism.js +212 -0
- package/dist/canonical/entries/electromagnetism.js.map +1 -0
- package/dist/canonical/entries/fluids-waves.d.ts +18 -0
- package/dist/canonical/entries/fluids-waves.d.ts.map +1 -0
- package/dist/canonical/entries/fluids-waves.js +130 -0
- package/dist/canonical/entries/fluids-waves.js.map +1 -0
- package/dist/canonical/entries/mechanics.d.ts +18 -0
- package/dist/canonical/entries/mechanics.d.ts.map +1 -0
- package/dist/canonical/entries/mechanics.js +275 -0
- package/dist/canonical/entries/mechanics.js.map +1 -0
- package/dist/canonical/entries/thermo-nuclear-cosmo.d.ts +18 -0
- package/dist/canonical/entries/thermo-nuclear-cosmo.d.ts.map +1 -0
- package/dist/canonical/entries/thermo-nuclear-cosmo.js +56 -0
- package/dist/canonical/entries/thermo-nuclear-cosmo.js.map +1 -0
- package/dist/canonical/registry.d.ts.map +1 -1
- package/dist/canonical/registry.js +10 -0
- package/dist/canonical/registry.js.map +1 -1
- package/dist/composition/compose.d.ts.map +1 -1
- package/dist/composition/compose.js +14 -0
- package/dist/composition/compose.js.map +1 -1
- package/dist/composition/dimension-adjacency.d.ts +39 -0
- package/dist/composition/dimension-adjacency.d.ts.map +1 -0
- package/dist/composition/dimension-adjacency.js +44 -0
- package/dist/composition/dimension-adjacency.js.map +1 -0
- package/dist/composition/graph-viz-svg.d.ts +31 -0
- package/dist/composition/graph-viz-svg.d.ts.map +1 -0
- package/dist/composition/graph-viz-svg.js +45 -0
- package/dist/composition/graph-viz-svg.js.map +1 -0
- package/dist/composition/graph-viz.d.ts +100 -0
- package/dist/composition/graph-viz.d.ts.map +1 -0
- package/dist/composition/graph-viz.js +256 -0
- package/dist/composition/graph-viz.js.map +1 -0
- package/dist/composition/index.d.ts +8 -0
- package/dist/composition/index.d.ts.map +1 -1
- package/dist/composition/index.js +4 -0
- package/dist/composition/index.js.map +1 -1
- package/dist/composition/user-equation.d.ts +136 -0
- package/dist/composition/user-equation.d.ts.map +1 -0
- package/dist/composition/user-equation.js +247 -0
- package/dist/composition/user-equation.js.map +1 -0
- package/dist/dimensional/dimension-inference.d.ts +37 -0
- package/dist/dimensional/dimension-inference.d.ts.map +1 -0
- package/dist/dimensional/dimension-inference.js +79 -0
- package/dist/dimensional/dimension-inference.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -1
- package/dist/numerical/formula-dimension.d.ts +16 -1
- package/dist/numerical/formula-dimension.d.ts.map +1 -1
- package/dist/numerical/formula-dimension.js +116 -84
- package/dist/numerical/formula-dimension.js.map +1 -1
- package/dist/numerical/formula-registry.d.ts +11 -1
- package/dist/numerical/formula-registry.d.ts.map +1 -1
- package/dist/numerical/formula-registry.js +12 -0
- package/dist/numerical/formula-registry.js.map +1 -1
- package/package.json +92 -91
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SVG rendering for the physics map — render Graphviz DOT source to an SVG
|
|
3
|
+
* string via the optional **`@viz-js/viz`** peer (the real Graphviz compiled to
|
|
4
|
+
* WebAssembly: same `dot` output, in-process, no native binary, no subprocess).
|
|
5
|
+
*
|
|
6
|
+
* Kept separate from `graph-viz.ts` so that module stays pure, synchronous, and
|
|
7
|
+
* dependency-free (text only). The optional-renderer concern — a lazy dynamic
|
|
8
|
+
* import with graceful fallback, mirroring `numerical/formula-registry.ts`'s
|
|
9
|
+
* MathTS-peer pattern — lives here.
|
|
10
|
+
*
|
|
11
|
+
* @module composition/graph-viz-svg
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Thrown by {@link renderDotToSvg} when the optional `@viz-js/viz` peer is not
|
|
15
|
+
* installed. The message names the install command and the no-install
|
|
16
|
+
* alternative.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export class SvgRendererUnavailableError extends Error {
|
|
21
|
+
constructor(message = 'SVG rendering needs the optional renderer: npm i @viz-js/viz ' +
|
|
22
|
+
'(or use --format=dot | dot -Tsvg)') {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'SvgRendererUnavailableError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Render Graphviz DOT source (e.g. {@link buildVizModel}'s `toDot()`) to an SVG
|
|
29
|
+
* document string. Lazy-loads the optional `@viz-js/viz` peer.
|
|
30
|
+
*
|
|
31
|
+
* @throws {SvgRendererUnavailableError} if the peer is not installed.
|
|
32
|
+
* @public
|
|
33
|
+
*/
|
|
34
|
+
export async function renderDotToSvg(dot) {
|
|
35
|
+
let viz;
|
|
36
|
+
try {
|
|
37
|
+
viz = (await import('@viz-js/viz'));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
throw new SvgRendererUnavailableError();
|
|
41
|
+
}
|
|
42
|
+
const renderer = await viz.instance();
|
|
43
|
+
return renderer.renderString(dot, { format: 'svg' });
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=graph-viz-svg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-viz-svg.js","sourceRoot":"","sources":["../../src/composition/graph-viz-svg.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IACpD,YACE,OAAO,GAAG,+DAA+D;QACvE,mCAAmC;QAErC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;IAC5C,CAAC;CACF;AASD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAW;IAC9C,IAAI,GAAc,CAAC;IACnB,IAAI,CAAC;QACH,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,CAAyB,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,2BAA2B,EAAE,CAAC;IAC1C,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC;IACtC,OAAO,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Physics-map visualization — turn the composition hypergraph into Mermaid and
|
|
3
|
+
* Graphviz-DOT **source text**.
|
|
4
|
+
*
|
|
5
|
+
* The graph is bipartite in the drawing: round nodes are *quantities*
|
|
6
|
+
* (`mass`, `temperature`, …) and box nodes are *equations* — laws, bridges, or
|
|
7
|
+
* proposed relations — each an n-ary junction (its source quantities point in,
|
|
8
|
+
* its target points out). This makes "equations as junctions" literal and draws
|
|
9
|
+
* n-ary edges faithfully (a single Mermaid/DOT edge can only connect two nodes).
|
|
10
|
+
*
|
|
11
|
+
* The model computes its own connected components over the junctions — so a
|
|
12
|
+
* `--proposed` overlay participates in the clustering — and groups each component
|
|
13
|
+
* into its own subgraph so the genuinely disjointed map stays legible. For the
|
|
14
|
+
* pure-`BridgeEdge` case the component count matches the authoritative
|
|
15
|
+
* {@link linkageMap} (pinned by a drift-guard test).
|
|
16
|
+
*
|
|
17
|
+
* Pure string production: no file I/O (the CLI is the only file-touching layer).
|
|
18
|
+
*
|
|
19
|
+
* @module composition/graph-viz
|
|
20
|
+
*/
|
|
21
|
+
import type { BridgeEdge } from './edge.js';
|
|
22
|
+
/**
|
|
23
|
+
* Epistemic status of a junction — drives node colour/shape. Bridges carry
|
|
24
|
+
* their catalog confidence; `law` is a diagonal/established-physics edge;
|
|
25
|
+
* `proposed` is a machine-derived, unadjudicated relation (rendered quarantined).
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export type VizStatus = 'law' | 'established' | 'speculative' | 'highly-speculative' | 'proposed' | 'user';
|
|
30
|
+
/**
|
|
31
|
+
* A normalized equation junction: n source quantities → 1 target. The render
|
|
32
|
+
* model's unit of "equation", decoupled from both `BridgeEdge` and the internal
|
|
33
|
+
* `ProposedBridge` type (the CLI converts each into this shape).
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
export interface VizJunction {
|
|
38
|
+
/** Graph id, e.g. `'be-42'` or `'IC-…'`. */
|
|
39
|
+
readonly id: string;
|
|
40
|
+
/** Short human label. */
|
|
41
|
+
readonly label: string;
|
|
42
|
+
readonly status: VizStatus;
|
|
43
|
+
/** Source quantity names. */
|
|
44
|
+
readonly sources: readonly string[];
|
|
45
|
+
/** Target quantity name. */
|
|
46
|
+
readonly target: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* One connected component of the bipartite graph.
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export interface VizCluster {
|
|
54
|
+
/** Junction ids in this component. */
|
|
55
|
+
readonly junctionIds: readonly string[];
|
|
56
|
+
/** Distinct (canonical) quantity names touched by this component. */
|
|
57
|
+
readonly quantities: readonly string[];
|
|
58
|
+
/** Number of junctions (the cluster "size", matching `linkageMap`). */
|
|
59
|
+
readonly size: number;
|
|
60
|
+
/** Contains a `law`/`established` junction (anchored to known physics). */
|
|
61
|
+
readonly anchored: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Options for {@link buildVizModel}.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export interface VizOptions {
|
|
69
|
+
/** Diagram title (used as the graph label). */
|
|
70
|
+
readonly title?: string;
|
|
71
|
+
/** Already-normalized extra junctions to overlay (e.g. proposed relations). */
|
|
72
|
+
readonly extraJunctions?: readonly VizJunction[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The render model: normalized junctions, their connected components, and the
|
|
76
|
+
* two serializers.
|
|
77
|
+
*
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export interface VizModel {
|
|
81
|
+
readonly junctions: readonly VizJunction[];
|
|
82
|
+
readonly clusters: readonly VizCluster[];
|
|
83
|
+
toMermaid(): string;
|
|
84
|
+
toDot(): string;
|
|
85
|
+
}
|
|
86
|
+
/** Map a `BridgeEdge` to a `VizJunction` (raw quantity names).
|
|
87
|
+
*
|
|
88
|
+
* The display label is the compact catalog id (`BE-<n>`) when the edge is
|
|
89
|
+
* catalog-backed, else the edge's own label — a *map* reads better with short
|
|
90
|
+
* junction names; the full formula stays in the catalog. */
|
|
91
|
+
export declare function edgeToJunction(edge: BridgeEdge): VizJunction;
|
|
92
|
+
/**
|
|
93
|
+
* Build the bipartite, clustered render model from a graph (+ optional overlay).
|
|
94
|
+
* Quantity names are canonicalized via `QUANTITY_IDENTIFICATIONS` so the
|
|
95
|
+
* clustering matches the authoritative {@link linkageMap}.
|
|
96
|
+
*
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
export declare function buildVizModel(edges: readonly BridgeEdge[], opts?: VizOptions): VizModel;
|
|
100
|
+
//# sourceMappingURL=graph-viz.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-viz.d.ts","sourceRoot":"","sources":["../../src/composition/graph-viz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C;;;;;;GAMG;AACH,M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;GAMG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,IAAI,GAAE,UAAe,GACpB,QAAQ,CA6BV"}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Physics-map visualization — turn the composition hypergraph into Mermaid and
|
|
3
|
+
* Graphviz-DOT **source text**.
|
|
4
|
+
*
|
|
5
|
+
* The graph is bipartite in the drawing: round nodes are *quantities*
|
|
6
|
+
* (`mass`, `temperature`, …) and box nodes are *equations* — laws, bridges, or
|
|
7
|
+
* proposed relations — each an n-ary junction (its source quantities point in,
|
|
8
|
+
* its target points out). This makes "equations as junctions" literal and draws
|
|
9
|
+
* n-ary edges faithfully (a single Mermaid/DOT edge can only connect two nodes).
|
|
10
|
+
*
|
|
11
|
+
* The model computes its own connected components over the junctions — so a
|
|
12
|
+
* `--proposed` overlay participates in the clustering — and groups each component
|
|
13
|
+
* into its own subgraph so the genuinely disjointed map stays legible. For the
|
|
14
|
+
* pure-`BridgeEdge` case the component count matches the authoritative
|
|
15
|
+
* {@link linkageMap} (pinned by a drift-guard test).
|
|
16
|
+
*
|
|
17
|
+
* Pure string production: no file I/O (the CLI is the only file-touching layer).
|
|
18
|
+
*
|
|
19
|
+
* @module composition/graph-viz
|
|
20
|
+
*/
|
|
21
|
+
import { QUANTITY_IDENTIFICATIONS } from './compose.js';
|
|
22
|
+
/** Fill colour + dashed flag per status. Tweak here to restyle the whole map. */
|
|
23
|
+
const STATUS_STYLE = {
|
|
24
|
+
law: { fill: '#cfe3f7', stroke: '#3a6ea5', dashed: false }, // textbook law — blue
|
|
25
|
+
established: { fill: '#cde7d3', stroke: '#3f8f5b', dashed: false }, // solid bridge — green
|
|
26
|
+
speculative: { fill: '#fdebc8', stroke: '#c9881b', dashed: false }, // amber
|
|
27
|
+
'highly-speculative': { fill: '#f5c6c6', stroke: '#c0392b', dashed: false }, // red
|
|
28
|
+
proposed: { fill: '#e6e6e6', stroke: '#888888', dashed: true }, // unadjudicated — grey dashed
|
|
29
|
+
user: { fill: '#e9d8fd', stroke: '#6b46c1', dashed: false }, // user-supplied — violet
|
|
30
|
+
};
|
|
31
|
+
/** Map a `BridgeEdge` to a `VizJunction` (raw quantity names).
|
|
32
|
+
*
|
|
33
|
+
* The display label is the compact catalog id (`BE-<n>`) when the edge is
|
|
34
|
+
* catalog-backed, else the edge's own label — a *map* reads better with short
|
|
35
|
+
* junction names; the full formula stays in the catalog. */
|
|
36
|
+
export function edgeToJunction(edge) {
|
|
37
|
+
const status = edge.kind === 'law' ? 'law' : edge.confidence;
|
|
38
|
+
return {
|
|
39
|
+
id: edge.id,
|
|
40
|
+
label: edge.beId != null ? `BE-${edge.beId}` : edge.label,
|
|
41
|
+
status,
|
|
42
|
+
sources: edge.sources.map((s) => s.name),
|
|
43
|
+
target: edge.target.name,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Quantity-name canonicalizer from `QUANTITY_IDENTIFICATIONS` (matches `linkageMap`). */
|
|
47
|
+
function makeCanon() {
|
|
48
|
+
const alias = new Map(QUANTITY_IDENTIFICATIONS.map((id) => [id.from, id.to]));
|
|
49
|
+
return (n) => alias.get(n) ?? n;
|
|
50
|
+
}
|
|
51
|
+
/** Distinct canonical quantity names of a junction (sources ∪ target). */
|
|
52
|
+
function quantitiesOf(j) {
|
|
53
|
+
return [...new Set([...j.sources, j.target])];
|
|
54
|
+
}
|
|
55
|
+
/** Union-find component grouping of junctions sharing a (canonical) quantity. */
|
|
56
|
+
function componentsOf(junctions) {
|
|
57
|
+
const parent = junctions.map((_, i) => i);
|
|
58
|
+
const find = (x) => parent[x] === x ? x : (parent[x] = find(parent[x]));
|
|
59
|
+
const union = (a, b) => {
|
|
60
|
+
parent[find(a)] = find(b);
|
|
61
|
+
};
|
|
62
|
+
const qToJunctions = new Map();
|
|
63
|
+
junctions.forEach((j, i) => {
|
|
64
|
+
for (const qty of quantitiesOf(j)) {
|
|
65
|
+
const arr = qToJunctions.get(qty) ?? [];
|
|
66
|
+
arr.push(i);
|
|
67
|
+
qToJunctions.set(qty, arr);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
for (const idxs of qToJunctions.values()) {
|
|
71
|
+
for (let k = 1; k < idxs.length; k++)
|
|
72
|
+
union(idxs[0], idxs[k]);
|
|
73
|
+
}
|
|
74
|
+
const groups = new Map();
|
|
75
|
+
junctions.forEach((_, i) => {
|
|
76
|
+
const r = find(i);
|
|
77
|
+
const arr = groups.get(r) ?? [];
|
|
78
|
+
arr.push(i);
|
|
79
|
+
groups.set(r, arr);
|
|
80
|
+
});
|
|
81
|
+
const clusters = [...groups.values()].map((idxs) => {
|
|
82
|
+
const js = idxs.map((i) => junctions[i]);
|
|
83
|
+
const quantities = [...new Set(js.flatMap(quantitiesOf))].sort();
|
|
84
|
+
return {
|
|
85
|
+
junctionIds: js.map((j) => j.id),
|
|
86
|
+
quantities,
|
|
87
|
+
size: js.length,
|
|
88
|
+
anchored: js.some((j) => j.status === 'law' || j.status === 'established'),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
// Deterministic: largest first, then by first junction id.
|
|
92
|
+
clusters.sort((a, b) => b.size - a.size || a.junctionIds[0].localeCompare(b.junctionIds[0]));
|
|
93
|
+
return clusters;
|
|
94
|
+
}
|
|
95
|
+
/** A stable, collision-free id factory mapping arbitrary keys to safe ids. */
|
|
96
|
+
function idFactory(prefix) {
|
|
97
|
+
const seen = new Map();
|
|
98
|
+
const used = new Set();
|
|
99
|
+
return (key) => {
|
|
100
|
+
const cached = seen.get(key);
|
|
101
|
+
if (cached)
|
|
102
|
+
return cached;
|
|
103
|
+
const base = `${prefix}_${key.replace(/[^A-Za-z0-9]/g, '_')}`;
|
|
104
|
+
let id = base;
|
|
105
|
+
let n = 1;
|
|
106
|
+
while (used.has(id))
|
|
107
|
+
id = `${base}_${n++}`;
|
|
108
|
+
used.add(id);
|
|
109
|
+
seen.set(key, id);
|
|
110
|
+
return id;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Escape a label for Mermaid `["…"]` — XML-entity-encode the characters that
|
|
114
|
+
* break the quoted form or are read as entities (`&`, `"`, `<`, `>`). */
|
|
115
|
+
const mmLabel = (s) => s
|
|
116
|
+
.replace(/&/g, '&')
|
|
117
|
+
.replace(/"/g, '"')
|
|
118
|
+
.replace(/</g, '<')
|
|
119
|
+
.replace(/>/g, '>');
|
|
120
|
+
/** Escape a label for a DOT double-quoted string. */
|
|
121
|
+
const dotLabel = (s) => s.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
122
|
+
const STATUSES_IN_ORDER = [
|
|
123
|
+
'law',
|
|
124
|
+
'established',
|
|
125
|
+
'speculative',
|
|
126
|
+
'highly-speculative',
|
|
127
|
+
'proposed',
|
|
128
|
+
'user',
|
|
129
|
+
];
|
|
130
|
+
/**
|
|
131
|
+
* Drive a format-specific cluster renderer over the standard layout, identical
|
|
132
|
+
* for both emitters: multi-junction components first (each its own subgraph,
|
|
133
|
+
* keyed `0`,`1`,…, labelled `anchored cluster (n)` / `cluster (n)`), then a
|
|
134
|
+
* single `iso` subgraph collecting all singletons. The callback owns all
|
|
135
|
+
* per-format string production; this owns only the traversal and labelling.
|
|
136
|
+
*/
|
|
137
|
+
function forEachClusterGroup(clusters, renderCluster) {
|
|
138
|
+
const multi = clusters.filter((c) => c.size > 1);
|
|
139
|
+
const singletons = clusters.filter((c) => c.size === 1);
|
|
140
|
+
multi.forEach((c, i) => renderCluster(`${c.anchored ? 'anchored ' : ''}cluster (${c.size})`, c.junctionIds, String(i)));
|
|
141
|
+
if (singletons.length) {
|
|
142
|
+
renderCluster(`isolated (${singletons.length})`, singletons.flatMap((c) => c.junctionIds), 'iso');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function emitMermaid(clusters, byId, title) {
|
|
146
|
+
const qid = idFactory('q');
|
|
147
|
+
const jid = idFactory('j');
|
|
148
|
+
const usedStatuses = new Set();
|
|
149
|
+
const out = [`flowchart LR`, `%% ${title}`];
|
|
150
|
+
const renderCluster = (label, junctionIds, key) => {
|
|
151
|
+
out.push(` subgraph cl_${key}["${mmLabel(label)}"]`);
|
|
152
|
+
out.push(` direction LR`);
|
|
153
|
+
const declared = new Set();
|
|
154
|
+
const declareQ = (name) => {
|
|
155
|
+
const id = qid(name);
|
|
156
|
+
if (!declared.has(id)) {
|
|
157
|
+
out.push(` ${id}(["${mmLabel(name)}"]):::qty`);
|
|
158
|
+
declared.add(id);
|
|
159
|
+
}
|
|
160
|
+
return id;
|
|
161
|
+
};
|
|
162
|
+
for (const id of junctionIds) {
|
|
163
|
+
const j = byId.get(id);
|
|
164
|
+
usedStatuses.add(j.status);
|
|
165
|
+
const jId = jid(j.id);
|
|
166
|
+
out.push(` ${jId}["${mmLabel(j.label)}"]:::${j.status}`);
|
|
167
|
+
for (const s of j.sources)
|
|
168
|
+
out.push(` ${declareQ(s)} --> ${jId}`);
|
|
169
|
+
out.push(` ${jId} --> ${declareQ(j.target)}`);
|
|
170
|
+
}
|
|
171
|
+
out.push(` end`);
|
|
172
|
+
};
|
|
173
|
+
forEachClusterGroup(clusters, renderCluster);
|
|
174
|
+
for (const st of STATUSES_IN_ORDER) {
|
|
175
|
+
if (!usedStatuses.has(st))
|
|
176
|
+
continue;
|
|
177
|
+
const { fill, stroke, dashed } = STATUS_STYLE[st];
|
|
178
|
+
out.push(` classDef ${st} fill:${fill},stroke:${stroke}${dashed ? ',stroke-dasharray:4 3' : ''}`);
|
|
179
|
+
}
|
|
180
|
+
out.push(` classDef qty fill:#ffffff,stroke:#999999`);
|
|
181
|
+
return out.join('\n') + '\n';
|
|
182
|
+
}
|
|
183
|
+
function emitDot(clusters, byId, title) {
|
|
184
|
+
const qid = idFactory('q');
|
|
185
|
+
const jid = idFactory('j');
|
|
186
|
+
const out = [
|
|
187
|
+
`digraph PhysicsMap {`,
|
|
188
|
+
` label="${dotLabel(title)}";`,
|
|
189
|
+
` rankdir=LR;`,
|
|
190
|
+
` node [fontname="Helvetica"];`,
|
|
191
|
+
];
|
|
192
|
+
const renderCluster = (label, junctionIds, key) => {
|
|
193
|
+
out.push(` subgraph cluster_${key} {`);
|
|
194
|
+
out.push(` label="${dotLabel(label)}";`);
|
|
195
|
+
const declared = new Set();
|
|
196
|
+
const declareQ = (name) => {
|
|
197
|
+
const id = qid(name);
|
|
198
|
+
if (!declared.has(id)) {
|
|
199
|
+
out.push(` ${id} [shape=ellipse,label="${dotLabel(name)}"];`);
|
|
200
|
+
declared.add(id);
|
|
201
|
+
}
|
|
202
|
+
return id;
|
|
203
|
+
};
|
|
204
|
+
for (const id of junctionIds) {
|
|
205
|
+
const j = byId.get(id);
|
|
206
|
+
const jId = jid(j.id);
|
|
207
|
+
const { fill, stroke, dashed } = STATUS_STYLE[j.status];
|
|
208
|
+
const style = dashed ? 'filled,dashed' : 'filled';
|
|
209
|
+
out.push(` ${jId} [shape=box,style="${style}",fillcolor="${fill}",color="${stroke}",label="${dotLabel(j.label)}"];`);
|
|
210
|
+
for (const s of j.sources)
|
|
211
|
+
out.push(` ${declareQ(s)} -> ${jId};`);
|
|
212
|
+
out.push(` ${jId} -> ${declareQ(j.target)};`);
|
|
213
|
+
}
|
|
214
|
+
out.push(` }`);
|
|
215
|
+
};
|
|
216
|
+
forEachClusterGroup(clusters, renderCluster);
|
|
217
|
+
out.push(`}`);
|
|
218
|
+
return out.join('\n') + '\n';
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Build the bipartite, clustered render model from a graph (+ optional overlay).
|
|
222
|
+
* Quantity names are canonicalized via `QUANTITY_IDENTIFICATIONS` so the
|
|
223
|
+
* clustering matches the authoritative {@link linkageMap}.
|
|
224
|
+
*
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
export function buildVizModel(edges, opts = {}) {
|
|
228
|
+
const canon = makeCanon();
|
|
229
|
+
const normalize = (j) => ({
|
|
230
|
+
...j,
|
|
231
|
+
sources: j.sources.map(canon),
|
|
232
|
+
target: canon(j.target),
|
|
233
|
+
});
|
|
234
|
+
const junctions = [
|
|
235
|
+
...edges.map((e) => normalize(edgeToJunction(e))),
|
|
236
|
+
...(opts.extraJunctions ?? []).map(normalize),
|
|
237
|
+
];
|
|
238
|
+
// A duplicate junction id (e.g. a proposed overlay colliding with an edge id)
|
|
239
|
+
// would silently drop one from the rendered output — make it a loud error.
|
|
240
|
+
const byId = new Map();
|
|
241
|
+
for (const j of junctions) {
|
|
242
|
+
if (byId.has(j.id)) {
|
|
243
|
+
throw new Error(`buildVizModel: duplicate junction id '${j.id}'`);
|
|
244
|
+
}
|
|
245
|
+
byId.set(j.id, j);
|
|
246
|
+
}
|
|
247
|
+
const clusters = componentsOf(junctions);
|
|
248
|
+
const title = opts.title ?? 'UPT physics map';
|
|
249
|
+
return {
|
|
250
|
+
junctions,
|
|
251
|
+
clusters,
|
|
252
|
+
toMermaid: () => emitMermaid(clusters, byId, title),
|
|
253
|
+
toDot: () => emitDot(clusters, byId, title),
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=graph-viz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-viz.js","sourceRoot":"","sources":["../../src/composition/graph-viz.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AA6ExD,iFAAiF;AACjF,MAAM,YAAY,GAEd;IACF,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,sBAAsB;IAClF,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,uBAAuB;IAC3F,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,EA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ACzC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,iBAAiB,CAAC;IAE9C,OAAO;QACL,SAAS;QACT,QAAQ;QACR,SAAS,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC;QACnD,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -35,4 +35,12 @@ export { explainQuantity } from './explain.js';
|
|
|
35
35
|
export type { Observable, ComposeSymbolicOptions } from './compose-symbolic.js';
|
|
36
36
|
export { composeSymbolic, SymbolicCompositionError } from './compose-symbolic.js';
|
|
37
37
|
export { SymbolicEvalError } from './expr-eval.js';
|
|
38
|
+
export type { VizStatus, VizJunction, VizCluster, VizOptions, VizModel, } from './graph-viz.js';
|
|
39
|
+
export { buildVizModel, edgeToJunction } from './graph-viz.js';
|
|
40
|
+
export { renderDotToSvg, SvgRendererUnavailableError } from './graph-viz-svg.js';
|
|
41
|
+
export type { DimensionAdjacency } from './dimension-adjacency.js';
|
|
42
|
+
export { dimensionAdjacency } from './dimension-adjacency.js';
|
|
43
|
+
export type { UserEquation, EquationLanding } from './user-equation.js';
|
|
44
|
+
export type { EquationAnalysis, EquationHint } from './user-equation.js';
|
|
45
|
+
export { parseUserEquation, resolveToCatalogName, suggestQuantities, suggestByDimension, equationLanding, analyzeUserEquation, UserEquationError, } from './user-equation.js';
|
|
38
46
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,YAAY,EAAE,UAAU,EAAE,cAA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
|
|
@@ -25,4 +25,8 @@ export { retrodict, retrodictNode } from './retrodiction.js';
|
|
|
25
25
|
export { explainQuantity } from './explain.js';
|
|
26
26
|
export { composeSymbolic, SymbolicCompositionError } from './compose-symbolic.js';
|
|
27
27
|
export { SymbolicEvalError } from './expr-eval.js';
|
|
28
|
+
export { buildVizModel, edgeToJunction } from './graph-viz.js';
|
|
29
|
+
export { renderDotToSvg, SvgRendererUnavailableError } from './graph-viz-svg.js';
|
|
30
|
+
export { dimensionAdjacency } from './dimension-adjacency.js';
|
|
31
|
+
export { parseUserEquation, resolveToCatalogName, suggestQuantities, suggestByDimension, equationLanding, analyzeUserEquation, UserEquationError, } from './user-equation.js';
|
|
28
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/composition/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EACL,qBAAqB,EACrB,yBAAyB,EACzB,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,GACb,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EACL,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,sBAAsB,EACtB,QAAQ,GACT,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,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MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAG9D,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-equation injection — turn a free-form `TARGET = EXPR` string into a graph
|
|
3
|
+
* junction (a target quantity + its source quantities), resolve the user's
|
|
4
|
+
* symbols onto the catalog vocabulary, suggest near-misses, and report where the
|
|
5
|
+
* injected junction lands in a built {@link VizModel}.
|
|
6
|
+
*
|
|
7
|
+
* Free-form means no dimensions: source quantities are the RHS's free variables
|
|
8
|
+
* — extracted by the active formula parser via {@link getFormulaParser} (the
|
|
9
|
+
* MathTS expression parser when the optional peer is installed, else the built-in
|
|
10
|
+
* one; both already drop constants like `pi`/`tau`, numbers, and functions) —
|
|
11
|
+
* minus the physics {@link CONSTANTS}. Multi-word quantities are typed with
|
|
12
|
+
* underscores; resolution tries the literal form first, then the `_`↔`-` swap, so
|
|
13
|
+
* both the catalog's hyphenated (`photon-energy`) and underscored
|
|
14
|
+
* (`impact_parameter`) names connect.
|
|
15
|
+
*
|
|
16
|
+
* Pure: no file I/O. The injected junction is rendered as an `extraJunction`
|
|
17
|
+
* (status `'user'`) and is never written into the catalog.
|
|
18
|
+
*
|
|
19
|
+
* @module composition/user-equation
|
|
20
|
+
*/
|
|
21
|
+
import type { VizModel, VizJunction } from './graph-viz.js';
|
|
22
|
+
import type { Dimension } from '../dimensional/types.js';
|
|
23
|
+
/** Thrown when a user equation cannot be parsed into a target + sources. @public */
|
|
24
|
+
export declare class UserEquationError extends Error {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A parsed user equation: the target quantity and its source quantities, as
|
|
29
|
+
* written (underscores preserved; constants/numbers/functions removed).
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export interface UserEquation {
|
|
34
|
+
readonly target: string;
|
|
35
|
+
readonly sources: readonly string[];
|
|
36
|
+
/** The original `TARGET = EXPR` text, for the junction label. */
|
|
37
|
+
readonly text: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parse `TARGET = EXPR` into `{ target, sources }`. The target is the text left
|
|
41
|
+
* of the first `=`; the sources are the RHS's free variables minus the physics
|
|
42
|
+
* constants.
|
|
43
|
+
*
|
|
44
|
+
* Uses the active formula parser (MathTS when installed, built-in otherwise) to
|
|
45
|
+
* extract the RHS's free variables.
|
|
46
|
+
*
|
|
47
|
+
* @throws {UserEquationError} on a missing `=`, an empty target, an unparseable
|
|
48
|
+
* RHS, or an RHS with no source quantities.
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export declare function parseUserEquation(equation: string): Promise<UserEquation>;
|
|
52
|
+
/**
|
|
53
|
+
* Resolve a user symbol to a catalog quantity name: the literal name first, then
|
|
54
|
+
* the `_`→`-` and `-`→`_` swaps, against `catalogNames`. Returns `null` if none
|
|
55
|
+
* match.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveToCatalogName(name: string, catalogNames: ReadonlySet<string>): string | null;
|
|
60
|
+
/**
|
|
61
|
+
* Up to `k` catalog names most similar to `name` — the "did you mean?" set for an
|
|
62
|
+
* unmatched user symbol. Names where one string contains the other rank first,
|
|
63
|
+
* then by edit distance, then by length.
|
|
64
|
+
*
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export declare function suggestQuantities(name: string, catalogNames: Iterable<string>, k?: number): string[];
|
|
68
|
+
/**
|
|
69
|
+
* Catalog quantity names whose dimension equals `dim` (sorted, capped at `k`) —
|
|
70
|
+
* the dimension-based "did you mean?" set once an unknown symbol's dimension has
|
|
71
|
+
* been inferred.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
export declare function suggestByDimension(dim: Dimension, catalogDims: ReadonlyMap<string, Dimension>, k?: number): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Where the injected user junction landed, computed from a built `VizModel`.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export interface EquationLanding {
|
|
82
|
+
readonly isolated: boolean;
|
|
83
|
+
/** Junctions in the user equation's connected component (including itself). */
|
|
84
|
+
readonly clusterSize: number;
|
|
85
|
+
/** The component holds a law/established junction (anchored to known physics). */
|
|
86
|
+
readonly anchored: boolean;
|
|
87
|
+
/** User-equation quantities that also appear in a neighbouring junction. */
|
|
88
|
+
readonly sharedQuantities: readonly string[];
|
|
89
|
+
/** Other junction ids in the user equation's component. */
|
|
90
|
+
readonly connectedJunctionIds: readonly string[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Describe where `userJunctionId` sits in `model`: its component, the junctions it
|
|
94
|
+
* connects to, and the quantities that link it to them.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare function equationLanding(model: VizModel, userJunctionId: string): EquationLanding;
|
|
99
|
+
/** A "did you mean?" suggestion for an unmatched symbol. */
|
|
100
|
+
export interface EquationHint {
|
|
101
|
+
readonly name: string;
|
|
102
|
+
readonly suggestions: readonly string[];
|
|
103
|
+
/** True when the suggestions come from the symbol's INFERRED dimension. */
|
|
104
|
+
readonly byDimension: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Full analysis of a user equation against a catalog name→dimension map: the
|
|
108
|
+
* `user` junction (for the graph), the dimensional verdict (RHS dimension vs the
|
|
109
|
+
* target's catalog dimension), and "did you mean?" hints (dimension-based when a
|
|
110
|
+
* single unknown's dimension can be inferred, else name-similarity).
|
|
111
|
+
*
|
|
112
|
+
* Physics constants (`hbar`, `c`, `k_B`, …) are supplied to the parser with
|
|
113
|
+
* their real dimensions (from `CONSTANTS`) so the dimensional check is correct.
|
|
114
|
+
*
|
|
115
|
+
* @public
|
|
116
|
+
*/
|
|
117
|
+
export interface EquationAnalysis {
|
|
118
|
+
readonly junction: VizJunction;
|
|
119
|
+
/** Set when the RHS is not dimensionally well-formed (then dims are null). */
|
|
120
|
+
readonly parseError: string | null;
|
|
121
|
+
readonly rhsDimension: Dimension | null;
|
|
122
|
+
readonly targetDimension: Dimension | null;
|
|
123
|
+
/** rhsDimension === targetDimension; null when unknowable or parse failed. */
|
|
124
|
+
readonly consistent: boolean | null;
|
|
125
|
+
readonly hints: readonly EquationHint[];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse + dimensionally analyze a user `TARGET = EXPR` against `catalogDims`
|
|
129
|
+
* (catalog quantity name → dimension). Throws {@link UserEquationError} on a
|
|
130
|
+
* structurally malformed equation; reports a dimensional malformation via
|
|
131
|
+
* `parseError`.
|
|
132
|
+
*
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export declare function analyzeUserEquation(equation: string, catalogDims: ReadonlyMap<string, Dimension>): Promise<EquationAnalysis>;
|
|
136
|
+
//# sourceMappingURL=user-equation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-equation.d.ts","sourceRoot":"","sources":["../../src/composition/user-equation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAKzD,oFAAoF;AACpF,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,E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