File size: 644 Bytes
b9499ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { createPython } from "@elvis/pyodide";

import type { Graph, Mode, State } from "./types";

// The methods of backend/src/manager.py's Manager
export type AutodiffApi = {
  handle_set_function: { args: { expression: string }; result: Graph };
  // seed is needed in forward mode
  handle_set_run: { args: { mode: Mode; inputs: Record<string, number>; seed?: string }; result: { steps: number } };
  // null past the last step
  handle_state: { args: { iteration: number }; result: State | null };
};

export const python = createPython<AutodiffApi>(
  new Worker(new URL("./pyodide.worker.ts", import.meta.url), { type: "module" }),
);