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

import type { FunctionValues, RunSettings, State } from "./types";

// The methods of backend/src/manager.py's Manager
export type OptimisationApi = {
  // variables is 1 or 2; clears the runs
  handle_set_function: { args: { variables: number; expression: string }; result: null };
  // null when no function is set
  handle_function_values: { args: { x_range: number[]; y_range: number[] }; result: FunctionValues | null };
  handle_set_runs: { args: { runs: RunSettings[] }; result: null };
  // null once every run has stopped (or there are none)
  handle_state: { args: { iteration: number }; result: State | null };
};

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