UNPKG

parea-ai

Version:

Client SDK library to connect to Parea AI.

42 lines (41 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExperimentRunner = void 0; /** * Manages the execution of trials in parallel. */ class ExperimentRunner { /** * Creates a new ExperimentRunner instance. * @param concurrency The number of concurrent trials to run. */ constructor(concurrency) { this.concurrency = concurrency; } /** * Runs the given trials in parallel. * @param trials An array of Trial objects to be executed. * @returns A promise that resolves to an array of TrialResult objects. */ async runTrials(trials) { const results = []; let currentIndex = 0; /** * Runs a batch of trials concurrently. * @returns A promise that resolves when the batch is complete. */ const runBatch = async () => { const batch = trials.slice(currentIndex, currentIndex + this.concurrency); if (batch.length === 0) return; const batchPromises = batch.map((trial) => trial.run()); const batchResults = await Promise.all(batchPromises); results.push(...batchResults); currentIndex += batch.length; await runBatch(); }; await runBatch(); return results; } } exports.ExperimentRunner = ExperimentRunner;