Skip to content

Commit

Permalink
REFACTOR: Dedicated helper to create a Julia kernel.
Browse files Browse the repository at this point in the history
  • Loading branch information
epatters committed Dec 6, 2024
1 parent f2a80ff commit 8e4bb24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
15 changes: 5 additions & 10 deletions packages/frontend/src/stdlib/analyses/decapodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -68,15 +68,10 @@ export function configureDecapodes(options: {
*/
export function Decapodes(props: DiagramAnalysisProps<DecapodesContent>) {
// 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());
Expand Down
13 changes: 11 additions & 2 deletions packages/frontend/src/stdlib/analyses/jupyter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8e4bb24

Please sign in to comment.