From 5d8f943d0a624b8a30c74ffd29692fae4c14a599 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Wed, 17 Jul 2024 19:51:04 +0000 Subject: [PATCH] Futher clean-up --- .../app/SamplerOutputView/SamplerOutputView.tsx | 14 ++++++-------- gui/src/app/StanSampler/useStanSampler.ts | 11 ++++++----- gui/test/app/StanSampler/useStanSampler.test.ts | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/gui/src/app/SamplerOutputView/SamplerOutputView.tsx b/gui/src/app/SamplerOutputView/SamplerOutputView.tsx index 071d3639..689d5df1 100644 --- a/gui/src/app/SamplerOutputView/SamplerOutputView.tsx +++ b/gui/src/app/SamplerOutputView/SamplerOutputView.tsx @@ -21,19 +21,17 @@ const SamplerOutputView: FunctionComponent = ({ height, latestRun, }) => { - const { draws, paramNames, computeTimeSec } = latestRun; - const numChains = latestRun.samplingOpts.num_chains; + const { draws, paramNames, computeTimeSec, samplingOpts } = latestRun; - if (!draws || !paramNames || !numChains) return ; + if (!draws || !paramNames || !samplingOpts) return ; return ( ); }; @@ -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 = [ @@ -80,12 +77,13 @@ const DrawsDisplay: FunctionComponent = ({ 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), diff --git a/gui/src/app/StanSampler/useStanSampler.ts b/gui/src/app/StanSampler/useStanSampler.ts index 7fccde04..412eb1a6 100644 --- a/gui/src/app/StanSampler/useStanSampler.ts +++ b/gui/src/app/StanSampler/useStanSampler.ts @@ -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; @@ -16,7 +18,6 @@ export type StanRun = { const initialStanRun: StanRun = { status: "", errorMessage: "", - samplingOpts: defaultSamplingOpts, }; export type StanRunAction = diff --git a/gui/test/app/StanSampler/useStanSampler.test.ts b/gui/test/app/StanSampler/useStanSampler.test.ts index b5b22f8a..5ddd94be 100644 --- a/gui/test/app/StanSampler/useStanSampler.test.ts +++ b/gui/test/app/StanSampler/useStanSampler.test.ts @@ -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, @@ -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,