Skip to content

Commit

Permalink
Merge branch 'backend-configuration' into backend-configuration-uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored Jun 4, 2024
2 parents dde939b + 336e040 commit 8060c4d
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 55 deletions.
23 changes: 1 addition & 22 deletions src/electron/frontend/core/components/ProgressBar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@


import { LitElement, html, css, unsafeCSS } from 'lit';
import { humanReadableBytes } from './utils/size';

export type ProgressProps = {
size?: string,
Expand All @@ -14,28 +15,6 @@ export type ProgressProps = {
}
}

export function humanReadableBytes(size: number | string) {

// Define the units
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

// Initialize the index to 0
let index = 0;

// Convert the size to a floating point number
size = parseFloat(size);

// Loop until the size is less than 1024 and increment the unit
while (size >= 1000 && index < units.length - 1) {
size /= 1000;
index += 1;
}

// Return the size formatted with 2 decimal places and the appropriate unit
return `${size.toFixed(2)} ${units[index]}`;
}


const animationDuration = 500 // ms

export class ProgressBar extends LitElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import { until } from "lit/directives/until.js";
import { resolve } from "../../../../promises";
import { InstanceManager } from "../../../InstanceManager.js";
import { InspectorListItem } from "../../../preview/inspector/InspectorList.js";
import { JSONSchemaInput } from "../../../JSONSchemaInput.js";

import { getResourceUsage } from "../../../../validation/backend-configuration";
import { getResourceUsageBytes } from "../../../../validation/backend-configuration";

import { resolveBackendResults, updateSchema } from "../../../../../../../schemas/backend-configuration.schema";
import { getInfoFromId } from "./utils.js";
Expand Down Expand Up @@ -187,7 +186,7 @@ export class GuidedBackendConfigurationPage extends ManagedPage {
if (name === "chunk_shape") {
const input = instance.getFormElement(path).inputs["chunk_shape"];

const mbUsage = getResourceUsage(value, itemsizes[path.join("/")], 1e6);
const mbUsage = getResourceUsageBytes(value, itemsizes[path.join("/")], 1e6);

if (mbUsage > 20)
errors.push({
Expand Down Expand Up @@ -287,32 +286,34 @@ export class GuidedBackendConfigurationPage extends ManagedPage {
header: "Sessions",
instanceType: "Session",
instances,

controls: [
(id) => {
const instanceInfo = id
.split("/")
.reduce((acc, key) => acc[key.split("-").slice(1).join("-")], this.localState.results);

const backend = instanceInfo.configuration.backend ?? this.workflow.file_format.value;

return new JSONSchemaInput({
path: [],
schema: {
type: "string",
placeholder: "Select backend type",
enum: Object.keys(backendMap),
enumLabels: backendMap,
strict: true,
},
value: backend,
onUpdate: async (value) => {
if (instanceInfo.configuration.backend === value) return;
instanceInfo.configuration.backend = value; // Ensure new backend choice is persistent
await this.save();
await this.#update();
},
});
},
// // NOTE: Removes session-specific control over the backend type since Zarr is not completely supported yet
// (id) => {
// const instanceInfo = id
// .split("/")
// .reduce((acc, key) => acc[key.split("-").slice(1).join("-")], this.localState.results);

// const backend = instanceInfo.configuration.backend ?? this.workflow.file_format.value;

// return new JSONSchemaInput({
// path: [],
// schema: {
// type: "string",
// placeholder: "Select backend type",
// enum: Object.keys(backendMap),
// enumLabels: backendMap,
// strict: true,
// },
// value: backend,
// onUpdate: async (value) => {
// if (instanceInfo.configuration.backend === value) return;
// instanceInfo.configuration.backend = value; // Ensure new backend choice is persistent
// await this.save();
// await this.#update();
// },
// });
// },
{
name: "Save & Validate",
primary: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const questions = {
title: "What file format would you like to use?",
description: "Choose a default file format for your data.",
default: "hdf5",
ignore: true, // NOTE: This ensures that users can only use the default (HDF5) format
},

backend_configuration: {
Expand All @@ -92,6 +93,11 @@ const defaults = Object.entries(questions).reduce((acc, [name, info]) => {
return acc;
}, {});

const ignore = Object.entries(questions).reduce((acc, [name, info]) => {
if (info.ignore) acc[name] = true;
return acc;
}, {});

const dependents = Object.entries(questions).reduce((acc, [name, info]) => {
acc[name] = [];

Expand Down Expand Up @@ -160,6 +166,7 @@ export class GuidedPreform extends Page {

this.form = new JSONSchemaForm({
schema,
ignore,
results: this.state,
validateEmptyValues: false, // Only show errors after submission
validateOnChange: function (name, parent, path, value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import examplePipelines from "../../../../../../example_pipelines.yml";
import { run } from "../guided-mode/options/utils.js";
import { joinPath } from "../../../globals";
import { Modal } from "../../Modal";
import { ProgressBar, humanReadableBytes } from "../../ProgressBar";
import { ProgressBar } from "../../ProgressBar";
import { humanReadableBytes } from "../../utils/size";

const DATA_OUTPUT_PATH = joinPath(testDataFolderPath, "single_session_data");
const DATASET_OUTPUT_PATH = joinPath(testDataFolderPath, "multi_session_dataset");
Expand Down
20 changes: 20 additions & 0 deletions src/electron/frontend/core/components/utils/size.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function humanReadableBytes(size: number | string) {

// Define the units
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];

// Initialize the index to 0
let index = 0;

// Convert the size to a floating point number
size = parseFloat(size);

// Loop until the size is less than 1024 and increment the unit
while (size >= 1000 && index < units.length - 1) {
size /= 1000;
index += 1;
}

// Return the size formatted with 2 decimal places and the appropriate unit
return `${size.toFixed(2)} ${units[index]}`;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { humanReadableBytes } from "../components/utils/size";

const prod = (arr: number[]) => arr.reduce((accumulator, currentValue) => accumulator * currentValue, 1);

export const getResourceUsage = (shape: number[], itemsize: number, scale=1e9) => prod(shape) * (itemsize / scale) // Default to GB
export const getResourceUsageBytes = (shape: number[], itemsize: number, scale=1e9) => prod(shape) * (itemsize / scale) // Default to GB

export const getResourceUsage = (shape: number[], itemsize: number) => humanReadableBytes(getResourceUsageBytes(shape, itemsize, 1))
7 changes: 4 additions & 3 deletions src/schemas/backend-configuration.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const resolveBackendResults = (schema, results, itemsize) => {
const { full_shape } = results;
if (copy.properties.filter_methods) copy.properties.filter_methods.description = "The ordered collection of filtering methods to apply to this dataset prior to compression.<br/><small>Set blank to disable filtering</small>"
copy.properties.compression_method.description = "The specified compression method to apply to this dataset.<br/><small>Set blank to disable compression</small>"
copy.description = `<b>Full Shape:</b> ${full_shape}<br/><b>Source size:</b> ${getResourceUsage(full_shape, itemsize).toFixed(2)} GB`; // This is static
delete copy.properties.compression_method.default // Remove gzip as the default compression method
copy.description = `<b>Full Shape:</b> ${full_shape.join(' x ')}<br/><b>Source size:</b> ${getResourceUsage(full_shape, itemsize)}`; // This is static

updateSchema(copy, results, itemsize)

Expand All @@ -28,12 +29,12 @@ const propertiesToUpdate = [
]

// const bufferShapeDescription = (value, itemsize) => {
// return `Expected RAM usage: ${getResourceUsage(value, itemsize).toFixed(2)} GB.`;
// return `Expected RAM usage: ${getResourceUsage(value, itemsize)}.`;
// }

const chunkShapeDescription = (value, itemsize) => {
const hasNull = value.includes(null) || value.includes(undefined); // Both null after JSON processing
const diskSpaceMessage = hasNull ? 'Disk space usage will be determined automatically' : `Disk space usage per chunk: ${getResourceUsage(value, itemsize, 1e6).toFixed(2)} MB`;
const diskSpaceMessage = hasNull ? 'Disk space usage will be determined automatically' : `Disk space usage per chunk: ${getResourceUsage(value, itemsize)}`;
return `${diskSpaceMessage}<br/><small>Leave blank to auto-specify the axis</small>`;
}

Expand Down

0 comments on commit 8060c4d

Please sign in to comment.