ParallelSimulationProvider

class ParallelSimulationProvider @JvmOverloads constructor(modelBuilder: ModelBuilderIfc, modelConfiguration: Map<String, String>? = null, baseRunParameters: ExperimentRunParametersIfc? = null, templateModel: Model? = null, simulationRunCache: SimulationRunCacheIfc? = null, shortCircuitSinglePoint: Boolean = true, dispatcher: CoroutineDispatcher = Dispatchers.IO.limitedParallelism(SimulationDispatcher.availableProcessors)) : SimulationOracleIfc(source)

A SimulationOracleIfc that executes the points of an EvaluationRequest concurrently, each on its own freshly built Model, honoring the request's common-random-numbers (CRN) vs. independent stream choice through per-point run parameters.

A single-point request has nothing to parallelize, so it is short-circuited to one reused model (no build, no coroutine) via an embedded SimulationProvider. Point-by-point solvers therefore pay no extra cost in parallel mode; only multi-point batches (e.g. a Cross-Entropy population or an R-SPLINE simplex/neighborhood) fan out across models.

The supplied modelBuilder MUST return an independent, freshly built Model on each call to build(...) (a bundle-backed builder does). A builder that returns a shared or cached instance is a data race under concurrent execution and must not be used here.

Each point runs a full experiment on its own model, mirroring the proven ParallelDesignedExperiment pattern; per-point conversion to a ResponseMap happens sequentially on the calling thread after the parallel phase completes. Built models are kept silent (no summary printing, no CSV) and never touch their (now lazy) outputDirectory, so a long run neither interleaves stdout nor accumulates output-file handles.

Parameters

modelBuilder

builds a fresh model per point; must yield independent instances

modelConfiguration

opaque configuration forwarded to modelBuilder.build(...)

baseRunParameters

baseline run parameters shared by all points; if null, taken from the template model

templateModel

an already-built model to adopt as the template and single-point reuse model; if null, one is built

simulationRunCache

optional cache used only by the single-point (sequential) path

shortCircuitSinglePoint

when true (default), size-1 requests run on the reused model instead of the parallel path

dispatcher

the bounded dispatcher governing worker concurrency; defaults to a dedicated view sized to the processors

Constructors

Link copied to clipboard
constructor(modelBuilder: ModelBuilderIfc, modelConfiguration: Map<String, String>? = null, baseRunParameters: ExperimentRunParametersIfc? = null, templateModel: Model? = null, simulationRunCache: SimulationRunCacheIfc? = null, shortCircuitSinglePoint: Boolean = true, dispatcher: CoroutineDispatcher = Dispatchers.IO.limitedParallelism(SimulationDispatcher.availableProcessors))

Properties

Link copied to clipboard

The identifier of the model produced by the builder, used to validate incoming requests.

Functions

Link copied to clipboard
open override fun simulate(evaluationRequest: EvaluationRequest): Map<ModelInputs, Result<ResponseMap>>

Executes multiple simulations based on the provided evaluation request and maps each request to a corresponding ResponseMap. Each request is processed individually, and the results of the simulations are stored as a key-value pair in the returned map. If the input list is empty, an exception is thrown. This default implementation runs all the requests sequentially based on the order within the evaluation request.