Batch API¶
Parallel simulation execution with thread-pool parallelism.
simulate_batch¶
idfkit.simulation.batch.simulate_batch(jobs, *, energyplus=None, max_workers=None, cache=None, progress=None, fs=None, on_progress=None, fail_fast=False)
¶
Run multiple EnergyPlus simulations in parallel.
Uses ThreadPoolExecutor to dispatch simulations concurrently. Individual job failures are captured as failed SimulationResult entries -- the batch never raises due to a single job failing, and by default every other job still runs.
With fail_fast=True the first failed job stops the batch instead:
queued jobs never start, running EnergyPlus processes are killed, and the
batch returns. Those jobs are reported as cancelled results
(BatchResult.cancelled);
jobs that had already finished keep their results.
An exception in the calling thread -- Ctrl-C, or one raised by a progress callback -- stops the batch the same way, but propagates once the workers have stopped, so no results are returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jobs
|
Sequence[SimulationJob]
|
Sequence of simulation jobs to execute. |
required |
energyplus
|
EnergyPlusConfig | None
|
Shared EnergyPlus configuration (auto-discovered if
|
None
|
max_workers
|
int | None
|
Maximum number of concurrent simulations. Defaults
to |
None
|
cache
|
SimulationCache | None
|
Optional simulation cache for content-hash lookups. See SimulationCache for what the key covers and which models are never cached. |
None
|
progress
|
BatchProgressCallback | None
|
Optional callback invoked after each job completes.
Called as |
None
|
fs
|
FileSystem | None
|
Optional file system backend passed through to each simulate call. |
None
|
on_progress
|
Callable[[SimulationProgress], None] | None
|
Optional callback invoked with
SimulationProgress events
during each individual simulation. Events include
|
None
|
fail_fast
|
bool
|
Stop the batch at the first failed job, cancelling the jobs still queued or running, instead of running every job. |
False
|
Returns:
| Type | Description |
|---|---|
BatchResult
|
A BatchResult with results in the same order as jobs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If jobs is empty, or fs is given and a job has no
|
TypeError
|
If progress cannot be called with the four keyword arguments above. |
Source code in idfkit/simulation/batch.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
SimulationJob¶
idfkit.simulation.batch.SimulationJob
dataclass
¶
Specification for a single simulation within a batch.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
AnyIDFDocument
|
The EnergyPlus model to simulate. |
weather |
str | Path | None
|
Path to the weather file, or |
label |
str
|
Human-readable label for progress reporting. |
output_dir |
str | Path | None
|
Directory for output files. |
expand_objects |
bool
|
Run ExpandObjects before simulation. |
annual |
bool
|
Run annual simulation. |
design_day |
bool
|
Run design-day-only simulation. |
output_prefix |
str
|
Prefix for output files. |
output_suffix |
Literal['C', 'L', 'D']
|
Output file naming suffix ( |
readvars |
bool
|
Run ReadVarsESO after simulation. |
timeout |
float
|
Maximum runtime in seconds for the main EnergyPlus subprocess. |
preprocessor_timeout |
float | None
|
Per-subprocess timeout (seconds) applied
individually to ExpandObjects, Slab, and Basement when they
run automatically. |
extra_args |
Sequence[str] | None
|
Additional command-line arguments. Any sequence of
strings is accepted, as |
auto_migrate |
bool
|
Forward-migrate a copy of the model to the installed
EnergyPlus version before the run, as
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If model is a path rather than a loaded document (load it with load_idf first), or extra_args is a single string rather than a sequence of them. |
Source code in idfkit/simulation/batch.py
annual = False
class-attribute
instance-attribute
¶
auto_migrate = False
class-attribute
instance-attribute
¶
design_day = False
class-attribute
instance-attribute
¶
expand_objects = True
class-attribute
instance-attribute
¶
extra_args = None
class-attribute
instance-attribute
¶
label = ''
class-attribute
instance-attribute
¶
model
instance-attribute
¶
output_dir = None
class-attribute
instance-attribute
¶
output_prefix = 'eplus'
class-attribute
instance-attribute
¶
output_suffix = 'C'
class-attribute
instance-attribute
¶
preprocessor_timeout = None
class-attribute
instance-attribute
¶
readvars = False
class-attribute
instance-attribute
¶
timeout = 3600.0
class-attribute
instance-attribute
¶
weather = None
class-attribute
instance-attribute
¶
BatchResult¶
idfkit.simulation.batch.BatchResult
dataclass
¶
Bases: Sequence[SimulationResult]
Aggregated results from a batch simulation run.
A real Sequence of the results, in job order, so
for result in batch, enumerate(batch), batch[0], len(batch),
reversed(batch) and result in batch all work and all type-check.
It behaved that way at runtime long before it type-checked. __len__ and
__getitem__ alone make an object iterable through the legacy sequence
protocol, so for result in batch ran fine and every static checker rejected
it, which pushed seven documented examples into writing batch.results
instead. Documenting a workaround for a call that already worked is worse than
either fixing it or removing it, so the base class is declared.
Every result is in exactly one of succeeded, failed and cancelled.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
tuple[SimulationResult, ...]
|
Simulation results in the same order as the input jobs. |
total_runtime_seconds |
float
|
Wall-clock time for the entire batch. |
Source code in idfkit/simulation/batch.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
all_succeeded
property
¶
Whether every job in the batch succeeded.
cancelled
property
¶
Results of the jobs fail_fast=True cancelled after another job failed.
Always empty without fail_fast. Each has
cancelled set and
its refusal names the job that failed.
failed
property
¶
Results that failed, not counting the jobs fail_fast=True cancelled.
results
instance-attribute
¶
succeeded
property
¶
Results that completed successfully.
total_runtime_seconds
instance-attribute
¶
cleanup()
¶
Call SimulationResult.cleanup on every result.
Deletes the temporary run directories idfkit created for jobs without an
output_dir; a job's own output_dir is never touched. Using the
batch as a context manager (with simulate_batch(jobs) as batch:)
calls this on exit. Safe to call more than once.