Skip to content

Commit

Permalink
Futher clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Jul 17, 2024
1 parent b9a0660 commit 5d8f943
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
14 changes: 6 additions & 8 deletions gui/src/app/SamplerOutputView/SamplerOutputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@ const SamplerOutputView: FunctionComponent<SamplerOutputViewProps> = ({
height,
latestRun,
}) => {
const { draws, paramNames, computeTimeSec } = latestRun;
const numChains = latestRun.samplingOpts.num_chains;
const { draws, paramNames, computeTimeSec, samplingOpts } = latestRun;

if (!draws || !paramNames || !numChains) return <span />;
if (!draws || !paramNames || !samplingOpts) return <span />;
return (
<DrawsDisplay
width={width}
height={height}
draws={draws}
paramNames={paramNames}
numChains={numChains}
computeTimeSec={computeTimeSec}
samplingOpts={latestRun.samplingOpts}
samplingOpts={samplingOpts}
/>
);
};
Expand All @@ -42,10 +40,9 @@ type DrawsDisplayProps = {
width: number;
height: number;
draws: number[][];
numChains: number;
paramNames: string[];
computeTimeSec: number | undefined;
samplingOpts: SamplingOpts; // for including in exported zip
samplingOpts: SamplingOpts;
};

const tabs = [
Expand Down Expand Up @@ -80,12 +77,13 @@ const DrawsDisplay: FunctionComponent<DrawsDisplayProps> = ({
height,
draws,
paramNames,
numChains,
computeTimeSec,
samplingOpts,
}) => {
const [currentTabId, setCurrentTabId] = useState("summary");

const numChains = samplingOpts.num_chains;

const drawChainIds = useMemo(() => {
return [...new Array(draws[0].length).keys()].map(
(i) => 1 + Math.floor((i / draws[0].length) * numChains),
Expand Down
11 changes: 6 additions & 5 deletions gui/src/app/StanSampler/useStanSampler.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { defaultSamplingOpts, SamplingOpts } from "@SpCore/ProjectDataModel";
import { Progress } from "@SpStanSampler/StanModelWorker";
import StanSampler, { StanSamplerStatus } from "@SpStanSampler/StanSampler";
import { type SamplingOpts } from "@SpCore/ProjectDataModel";
import { type Progress } from "@SpStanSampler/StanModelWorker";
import StanSampler, {
type StanSamplerStatus,
} from "@SpStanSampler/StanSampler";
import { useEffect, useReducer, useState } from "react";

export type StanRun = {
status: StanSamplerStatus;
errorMessage: string;
progress?: Progress;
samplingOpts: SamplingOpts;
samplingOpts?: SamplingOpts;
draws?: number[][];
paramNames?: string[];
computeTimeSec?: number;
Expand All @@ -16,7 +18,6 @@ export type StanRun = {
const initialStanRun: StanRun = {
status: "",
errorMessage: "",
samplingOpts: defaultSamplingOpts,
};

export type StanRunAction =
Expand Down
4 changes: 2 additions & 2 deletions gui/test/app/StanSampler/useStanSampler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { act, renderHook, waitFor } from "@testing-library/react";
import "@vitest/web-worker";
import { afterEach, describe, expect, onTestFinished, test, vi } from "vitest";
import { afterEach, describe, expect, test, vi } from "vitest";
import mockedLoad, {
erroringCompiledMainJsUrl,
erroringSamplingOpts,
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("useStanSampler", () => {
expect(result.current.latestRun.draws).toBeUndefined();
expect(result.current.latestRun.paramNames).toBeUndefined();
expect(result.current.latestRun.computeTimeSec).toBeUndefined();
expect(result.current.latestRun.samplingOpts).toBe(defaultSamplingOpts);
expect(result.current.latestRun.samplingOpts).toBeUndefined();

const testingSamplingOpts = {
...defaultSamplingOpts,
Expand Down

0 comments on commit 5d8f943

Please sign in to comment.