Skip to content

Commit

Permalink
Hotfix/revert to static temperature estimation (#25)
Browse files Browse the repository at this point in the history
* Removed upload button for temperature estimation data from csv file.

* Revert "Fix/temperature estimation implementation (#23)"

This reverts commit 827496c.

* Locked index's to current order.
  • Loading branch information
JohnCLee7 authored Nov 29, 2024
1 parent bdf6614 commit e75bcfa
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 177 deletions.
2 changes: 0 additions & 2 deletions app/calculate/sweep/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,6 @@ function useSweep(
const model = useCryogenicModel();
const fridge = useFridge();

model.loadTemperatureEstimation(fridge.temperatureEstimationData);

const [result1D, setResult1D] = useState<SweepResult>([null, "loading"]);
const [result2D, setResult2D] = useState<SweepResult2D>([null, "loading"]);

Expand Down
2 changes: 0 additions & 2 deletions app/fridge/graph/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ function FridgeGraphs() {
const model = useCryogenicModel();
const fridge = useFridge();

model.loadTemperatureEstimation(fridge.temperatureEstimationData);

const dimensions = useDimensions();

const numGraphs = 3;
Expand Down
2 changes: 1 addition & 1 deletion backend
61 changes: 25 additions & 36 deletions components/config/ConfigStage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { NumericInputColumn } from "@/components/inputs/numeric";
import { DeleteButtonColumn, FormGroup, FormSection, findNextId } from "@/components/config/common";
import { readCSVFile } from "@/components/config/ConfigCable";
import { useFeatureFlags } from "@/components/config/featureFlagContext";
import { UploadCSVButton } from "@/components/inputs/importCSVButton";
import { TempEstimationPoint } from "@/components/pyodide/types";
import styles from "@/components/config/Config.module.css";
import { UploadCSVButton } from "../inputs/importCSVButton";

function getNewStage(stages: StageConfig[], lines: LineConfig[]): [StageConfig, SegmentConfig[]] {
const nextIndex = stages.length > 0 ? Math.ceil(Math.max(...stages.map((item: StageConfig) => item.index))) + 1 : 0;
Expand Down Expand Up @@ -50,7 +48,7 @@ type StageConfigProps = {

// eslint-disable-next-line max-lines-per-function
export default function FridgeStages({ tooltips, setModal }: StageConfigProps): JSX.Element {
const { stages, setStages, lines, segments, setSegments, temperatureEstimationData, setTemperatureEstimationData } = useFridge();
const { stages, setStages, lines, segments, setSegments } = useFridge();
const updateStageId = (index: number, oldId: string, value: string) => {
setSegments(segments.map((item: SegmentConfig) => item.stageId !== oldId ? item : { ...item, stageId: value }));
updateStage(index, "id", value);
Expand Down Expand Up @@ -84,7 +82,7 @@ export default function FridgeStages({ tooltips, setModal }: StageConfigProps):
active: true,
data: dataString,
onSubmit: (dataStr: string) => {
setTemperatureEstimationData(fromStringToArray(dataStr));
console.log(fromStringToArray(dataStr));
}
})
} catch (err) {
Expand All @@ -100,55 +98,46 @@ export default function FridgeStages({ tooltips, setModal }: StageConfigProps):
return (
<FormSection>
<FormGroup title="Cryostat Stages" tooltip={tooltips.title} buttonLabel="Add Stage" buttonTooltip={tooltips.add_stage} onAddClicked={(featureFlags.staticStageCount) ? undefined : addStage} >
<NumericInputColumn<StageConfig> label="Index" tooltip={tooltips.index} data={stages} valueGetter={(item: StageConfig) => item.index} valueSetter={(index, item, value) => updateStage(index, "index", value)} />
<NumericInputColumn<StageConfig> label="Index" tooltip={tooltips.index} data={stages} valueGetter={(item: StageConfig) => item.index} valueSetter={(index, item, value) => updateStage(index, "index", value)} disabled={featureFlags.staticStageCount} />
<UniqueInputColumn<StageConfig> label="Stage Names" tooltip={tooltips.stage_names} data={stages} valueGetter={(item: StageConfig) => item.id} valueSetter={(index, item, value) => updateStageId(index, item.id, value)} isUnique={(value: string) => stages.every((item: StageConfig) => item.id !== value)} />
<NumericInputColumn<StageConfig> label="Temperatures (k)" tooltip={tooltips.tempertures} data={stages} valueGetter={(item: StageConfig) => item.temperature} valueSetter={(index, item, value) => updateStage(index, "temperature", value)} />
<NumericInputColumn<StageConfig> label="Cooling Budgets (W)" tooltip={tooltips.cooling_powers} data={stages} valueGetter={(item: StageConfig) => item.coolingPower} valueSetter={(index, item, value) => updateStage(index, "coolingPower", value)} />
{!featureFlags.staticStageCount && <DeleteButtonColumn<StageConfig> label="Stage" tooltip={tooltips.remove_stage} data={stages} onClick={removeStage} />}
</FormGroup>

<div className={'flex flex-row w-full justify-center items-center'}>
<UploadCSVButton
label={"Load Temperature Estimation Data"}
message={"Load Temperature Estimation Data CSV File"}
onClick={onFileSelected}
/>
<button
className={styles.BUTTON}
onClick={() => alert(temperatureEstimationData.map((t, i) => `${(i != 0) ? '\n' : ''}Point ${i + 1}\nApplied Powers: ${t.applied_power.toString()}\nMeasured Temperatures: ${t.measured_temperature.toString()}`))}
>View Temperature Estimation Data</button>
</div>

</FormSection>
);
}

type TempEstimationPoint = {
point_powers: number[],
temperatures: number[]
}

// eslint-disable-next-line max-lines-per-function
function interpretTempEstimatePoints(csvData: string[][]): TempEstimationPoint[] {
if (csvData.length < 3) throw new Error(`CSV data needs at least two points (rows).`);
if (csvData.length < 2) throw new Error(`CSV data needs at least two points (rows).`);

const data: TempEstimationPoint[] = [];

for (let i = 0; i < csvData.length; i++) {

// for now, limiting to 5 stages, therefore 5 values for each, totaling 10 values expected
if (csvData[i].length < 2) break;
if (csvData[i].length != 10) throw new Error(`CSV data does not have the correct number of columns to represent 5 stages at row ${i}.`);

const powers: number[] = [];
const point_powers: number[] = [];
const temperatures: number[] = [];

for (let j = 0; j < 5; j++) {
powers.push(parseFloat(csvData[i][j]));
point_powers.push(parseFloat(csvData[i][j]));
temperatures.push(parseFloat(csvData[i][j + 5]));
}

if (powers.every((p) => isNaN(p))) {
throw new Error(`Some of the Point Powers values: '${powers}' are not a number.`);
if (point_powers.every((p) => isNaN(p))) {
throw new Error(`Some of the Point Powers values: '${point_powers}' are not a number.`);
} else if (temperatures.every((t) => isNaN(t))) {
throw new Error(`Some of the Temperature values: '${temperatures}' are not a number.`);
} else {
const point: TempEstimationPoint = { applied_power: powers, measured_temperature: temperatures };
const point: TempEstimationPoint = { point_powers, temperatures };
data.push(point);
}
}
Expand All @@ -169,13 +158,13 @@ function dataToString(data: TempEstimationPoint[]): string {
function getPAndTValueString(dataPoint: TempEstimationPoint, end: boolean): string {
let pString: string = "";
let tString: string = "";
const length = (dataPoint.applied_power.length + dataPoint.measured_temperature.length) / 2;
const length = (dataPoint.point_powers.length + dataPoint.temperatures.length) / 2;
for (let j = 0; j < length - 1; j++) {
pString += dataPoint.applied_power[j] + ",";
tString += dataPoint.measured_temperature[j] + ",";
pString += dataPoint.point_powers[j] + ",";
tString += dataPoint.temperatures[j] + ",";
}
pString += dataPoint.applied_power[length - 1] + ",";
tString += dataPoint.measured_temperature[length - 1];
pString += dataPoint.point_powers[length - 1] + ",";
tString += dataPoint.temperatures[length - 1];
return "(" + pString + tString + ((end) ? ")" : "),")
}

Expand All @@ -191,25 +180,25 @@ function fromStringToArray(data: string): TempEstimationPoint[] {
const noBrackets = lines[i].replaceAll('(', '').replaceAll(')', '');
const values = noBrackets.split(',')

const powers: number[] = [];
const point_powers: number[] = [];
const temperatures: number[] = [];

const stageNum = values.length / 2;

for (let j = 0; j < stageNum; j++) {
powers.push(parseFloat(values[j]));
point_powers.push(parseFloat(values[j]));
temperatures.push(parseFloat(values[j + stageNum]));
}

if (powers.every((p) => isNaN(p))) {
throw new Error(`Some of the values ${powers} could not be interpreted as a number.`)
if (point_powers.every((p) => isNaN(p))) {
throw new Error(`Some of the values ${point_powers} could not be interpreted as a number.`)
} else if (temperatures.every((t) => isNaN(t))) {
throw new Error(`Some of the values ${temperatures} could not be interpreted as a number.`)
}

// TODO: more handeling for if the error is not in the first non whitespace charcter of f or a.

result.push({ applied_power: powers, measured_temperature: temperatures });
result.push({ point_powers, temperatures });
}

return result;
Expand Down
50 changes: 0 additions & 50 deletions components/config/GUIconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,56 +342,6 @@
"length": 0.14,
"attenuation": 0
}
],
"temperatureEstimationData": [
{
"applied_power": [
1e-10,
1e-10,
1e-2,
1e-10,
1e-10
],
"measured_temperature": [
4.20111000e+1,
3.41026571e+0,
1.20520821e+0,
1.63359036e-1,
1.64774143e-2
]
},
{
"applied_power": [
2.5,
0.5,
2.5e-2,
0.5e-3,
4e-4
],
"measured_temperature": [
4.20111000e+1,
3.41026571e+0,
1.20520821e+0,
1.63359036e-1,
1.64774143e-2
]
},
{
"applied_power": [
5,
1,
5e-2,
1e-3,
8e-4
],
"measured_temperature": [
4.20111000e+1,
3.41026571e+0,
1.20520821e+0,
1.63359036e-1,
1.64774143e-2
]
}
]
}
}
15 changes: 3 additions & 12 deletions components/config/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { FC, PropsWithChildren, createContext, useContext, useEffect, useMemo, u
import defaultFridge from "@/components/config/GUIconfig.json"
import { FridgeConfig, StageConfig, CableConfig, LineConfig, SegmentConfig } from "@/components/pyodide/fridge.d"
import { useFeatureFlags } from "./featureFlagContext"
import { TempEstimationPoint } from "@/components/pyodide/types"

export type FridgeContext = FridgeConfig & {
setStages: (stages: StageConfig[]) => void,
setCables: (cables: CableConfig[]) => void,
setLines: (lines: LineConfig[]) => void,
setSegments: (segments: SegmentConfig[]) => void,
setTemperatureEstimationData: (setTemperatureEstimationData: TempEstimationPoint[]) => void,
import: (fridge: FridgeConfig) => void,
export: () => FridgeConfig
reset: () => void,
Expand All @@ -24,12 +22,10 @@ const defaultFridgeContext: FridgeContext = {
cables: defaultFridge.FridgeUTS.cables as CableConfig[],
lines: defaultFridge.FridgeUTS.lines as LineConfig[],
segments: defaultFridge.FridgeUTS.segments as SegmentConfig[],
temperatureEstimationData: defaultFridge.FridgeUTS.temperatureEstimationData as TempEstimationPoint[],
setStages: () => { },
setCables: () => { },
setLines: () => { },
setSegments: () => { },
setTemperatureEstimationData: () => { },
import: () => { },
export: () => defaultFridge.FridgeUTS as FridgeConfig,
reset: () => { },
Expand All @@ -46,7 +42,6 @@ export const FridgeProvider: FC<PropsWithChildren> = ({ children }) => {
const [cables, setCables] = useState<CableConfig[]>([]);
const [lines, setLines] = useState<LineConfig[]>([]);
const [segments, setSegments] = useState<SegmentConfig[]>([]);
const [tempEstData, setTempEstData] = useState<TempEstimationPoint[]>([]);

const featureFlags = useFeatureFlags();

Expand All @@ -63,12 +58,10 @@ export const FridgeProvider: FC<PropsWithChildren> = ({ children }) => {
setCables(fridge.cables);
setLines(fridge.lines);
setSegments(fridge.segments);
setTempEstData(fridge.temperatureEstimationData);
}, [setStages, setCables, setLines, setSegments, setTempEstData]);

}, [setStages, setCables, setLines, setSegments]);
const exportConfig = useMemo(() => () => {
return { stages, cables, lines, segments, temperatureEstimationData: tempEstData };
}, [stages, cables, lines, segments, tempEstData]);
return { stages, cables, lines, segments };
}, [stages, cables, lines, segments]);

const reset = useMemo(() => () => {
importConfig(defaultFridge.FridgeUTS as FridgeConfig);
Expand Down Expand Up @@ -96,8 +89,6 @@ export const FridgeProvider: FC<PropsWithChildren> = ({ children }) => {
setLines: setLines,
segments: segments,
setSegments: setSegments,
temperatureEstimationData: tempEstData,
setTemperatureEstimationData: setTempEstData,
import: importConfig,
export: exportConfig,
reset: reset,
Expand Down
6 changes: 3 additions & 3 deletions components/inputs/importCSVButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export function UploadCSVButton({ label, tooltip, message, onClick, ...props }:
}

return (
<>
<div className={'flex flex-row w-full justify-center items-center'}>
<input
type="file"
ref={inputRef}
hidden={true}
onChange={onFileSelected}
/>
<button className={styles.BUTTON}
<button className={[styles.BUTTON].join(" ")}
onClick={() => inputRef?.current?.click()}
{...props}
>
{message}
</button>
</>
</div>
);
}
3 changes: 1 addition & 2 deletions components/pyodide/fridge.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Diameters, ThermalConductivityValue, BivariateCableData, TempEstimationPoint } from "./types";
import { Diameters, ThermalConductivityValue, BivariateCableData } from "./types";

export type FridgeConfig = {
stages: StageConfig[];
cables: CableConfig[];
lines: LineConfig[];
segments: SegmentConfig[];
temperatureEstimationData: TempEstimationPoint[];
};

export type StageId = string; // e.g. "50K", "MXC" or "Still"
Expand Down
9 changes: 3 additions & 6 deletions components/pyodide/fridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,7 @@ function createNewFridge(fridge: FridgeConfig, lineID: string, stages: string[],
stages: fridge.stages,
cables: fridge.cables,
lines: fridge.lines,
segments: newSegments,
temperatureEstimationData: fridge.temperatureEstimationData
segments: newSegments
};
}

Expand Down Expand Up @@ -543,8 +542,7 @@ function updateFridgeStagesTemps(fridge: FridgeConfig, sTemp: number[]): FridgeC
stages: newStages,
cables: fridge.cables,
lines: fridge.lines,
segments: fridge.segments,
temperatureEstimationData: fridge.temperatureEstimationData
segments: fridge.segments
};
}

Expand Down Expand Up @@ -599,8 +597,7 @@ export function sweepModel2D(model: CryoModelInterface, fridge: FridgeConfig, li
})
var newFridge = createNewFridge(fridge, lineID, stages, configs);
// initial temperature estimates (should instead update configuration file)
// var t_est = [4.20111000e+1, 3.41026571e+0, 1.20520821e+0, 1.63359036e-1, 1.64774143e-2];
var t_est = fridge.stages.map((stage) => stage.temperature);
var t_est = [4.20111000e+1, 3.41026571e+0, 1.20520821e+0, 1.63359036e-1, 1.64774143e-2];//fridge.stages.map((stage) => stage.temperature);
var load_matrix_0: number[][] = lineCount.map(() => stages.map(() => 0));
var delta_load_matrix: number[][] = lineCount.map(() => stages.map(() => 1));
const threshold: number = 0.0005;
Expand Down
Loading

0 comments on commit e75bcfa

Please sign in to comment.