From 8e4bb241309f3e454d096391a8405a876ee90c21 Mon Sep 17 00:00:00 2001 From: Evan Patterson Date: Fri, 6 Dec 2024 15:18:22 -0700 Subject: [PATCH] REFACTOR: Dedicated helper to create a Julia kernel. --- .../frontend/src/stdlib/analyses/decapodes.tsx | 15 +++++---------- packages/frontend/src/stdlib/analyses/jupyter.ts | 13 +++++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/frontend/src/stdlib/analyses/decapodes.tsx b/packages/frontend/src/stdlib/analyses/decapodes.tsx index 0feb735d..4afde9ff 100644 --- a/packages/frontend/src/stdlib/analyses/decapodes.tsx +++ b/packages/frontend/src/stdlib/analyses/decapodes.tsx @@ -21,7 +21,7 @@ import type { ModelJudgment, MorphismDecl } from "../../model"; import type { DiagramAnalysisMeta } from "../../theory"; import { uniqueIndexArray } from "../../util/indexing"; import { PDEPlot2D, type PDEPlotData2D } from "../../visualization"; -import { createKernel, executeAndRetrieve } from "./jupyter"; +import { createJuliaKernel, executeAndRetrieve } from "./jupyter"; import Loader from "lucide-solid/icons/loader"; import RotateCcw from "lucide-solid/icons/rotate-ccw"; @@ -68,15 +68,10 @@ export function configureDecapodes(options: { */ export function Decapodes(props: DiagramAnalysisProps) { // Step 1: Start the Julia kernel. - const [kernel, restartKernel] = createKernel( - { - baseUrl: "http://127.0.0.1:8888", - token: "", - }, - { - name: "julia-1.11", - }, - ); + const [kernel, restartKernel] = createJuliaKernel({ + baseUrl: "http://127.0.0.1:8888", + token: "", + }); // Step 2: Run initialization code in the kernel. const startedKernel = () => (kernel.error ? undefined : kernel()); diff --git a/packages/frontend/src/stdlib/analyses/jupyter.ts b/packages/frontend/src/stdlib/analyses/jupyter.ts index 86e06cb2..b085b1ed 100644 --- a/packages/frontend/src/stdlib/analyses/jupyter.ts +++ b/packages/frontend/src/stdlib/analyses/jupyter.ts @@ -37,10 +37,19 @@ export function createKernel( return [kernel, restartKernel]; } +/** Create a Julia kernel in a reactive context. */ +export function createJuliaKernel(serverOptions: ServerSettings) { + return createKernel(serverOptions, { + // XXX: Do I have to specify the Julia version? + name: "julia-1.11", + }); +} + /** Execute code in a Jupyter kernel and retrieve JSON data reactively. -Returns the post-processed data as a Solid.js resource and a callback to rerun -the computation. +Assumes that the computation will return JSON data using the "application/json" +MIME type in Jupyter. Returns the post-processed data as a Solid.js resource and +a callback to rerun the computation. The resource depends reactively on the kernel: if the kernel changes, the code will be automatically re-executed. It does *not* depend reactively on the code.