Async API¶
Non-blocking simulation execution using asyncio.
async_simulate¶
idfkit.simulation.async_runner.async_simulate(model, weather, *, output_dir=None, energyplus=None, expand_objects=True, annual=False, design_day=False, output_prefix='eplus', output_suffix='C', readvars=False, timeout=3600.0, extra_args=None, cache=None, fs=None, on_progress=None)
async
¶
Run an EnergyPlus simulation without blocking the event loop.
This is the async counterpart to simulate.
All parameters and return values are identical; the only difference is that
EnergyPlus runs as an asyncio subprocess, allowing the caller to
await the result while other coroutines continue executing.
Cancellation is supported: if the wrapping asyncio.Task is cancelled, the EnergyPlus subprocess is killed and cleaned up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The EnergyPlus model to simulate. |
required |
weather
|
str | Path
|
Path to the weather file (.epw). |
required |
output_dir
|
str | Path | None
|
Directory for output files (default: auto temp dir). |
None
|
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. If None, uses find_energyplus for auto-discovery. |
None
|
expand_objects
|
bool
|
Run ExpandObjects before simulation. When
|
True
|
annual
|
bool
|
Run annual simulation ( |
False
|
design_day
|
bool
|
Run design-day-only simulation ( |
False
|
output_prefix
|
str
|
Prefix for output files (default "eplus"). |
'eplus'
|
output_suffix
|
Literal['C', 'L', 'D']
|
Output file naming suffix: |
'C'
|
readvars
|
bool
|
Run ReadVarsESO after simulation ( |
False
|
timeout
|
float
|
Maximum runtime in seconds (default 3600). |
3600.0
|
extra_args
|
list[str] | None
|
Additional command-line arguments. |
None
|
cache
|
SimulationCache | None
|
Optional simulation cache for content-hash lookups. |
None
|
fs
|
FileSystem | AsyncFileSystem | None
|
Optional file system backend for storing results on remote
storage (e.g., S3). Both sync FileSystem
and async AsyncFileSystem are accepted.
When an |
None
|
on_progress
|
Callable[[SimulationProgress], Any] | Literal['tqdm'] | None
|
Optional callback invoked with a
SimulationProgress event
each time EnergyPlus emits a progress line. Both synchronous
and async callables are accepted -- async callables are awaited.
Pass |
None
|
Returns:
| Type | Description |
|---|---|
SimulationResult
|
SimulationResult with paths to output files. |
Raises:
| Type | Description |
|---|---|
SimulationError
|
On timeout, OS error, or missing weather file. |
ExpandObjectsError
|
If a preprocessing step fails. |
EnergyPlusNotFoundError
|
If EnergyPlus cannot be found. |
Source code in src/idfkit/simulation/async_runner.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
async_simulate_batch¶
idfkit.simulation.async_batch.async_simulate_batch(jobs, *, energyplus=None, max_concurrent=None, cache=None, fs=None, on_progress=None)
async
¶
Run multiple EnergyPlus simulations concurrently using asyncio.
This is the async counterpart to simulate_batch. Concurrency is controlled with an asyncio.Semaphore instead of a thread pool.
Individual job failures are captured as failed SimulationResult entries -- the batch never raises due to a single job failing.
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_concurrent
|
int | None
|
Maximum number of concurrent simulations. Defaults
to |
None
|
cache
|
SimulationCache | None
|
Optional simulation cache for content-hash lookups. |
None
|
fs
|
FileSystem | AsyncFileSystem | None
|
Optional file system backend passed through to each async_simulate call. |
None
|
on_progress
|
Callable[[SimulationProgress], Any] | None
|
Optional callback invoked with
SimulationProgress events
during each individual simulation. Events include
|
None
|
Returns:
| Type | Description |
|---|---|
BatchResult
|
A BatchResult with results in the |
BatchResult
|
same order as jobs. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If jobs is empty. |
Source code in src/idfkit/simulation/async_batch.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 | |
async_simulate_batch_stream¶
idfkit.simulation.async_batch.async_simulate_batch_stream(jobs, *, energyplus=None, max_concurrent=None, cache=None, fs=None, on_progress=None)
async
¶
Run simulations concurrently, yielding events as each one completes.
This is an async generator variant of async_simulate_batch that yields SimulationEvent objects in completion order. This enables real-time progress reporting without needing a callback:
.. code-block:: python
async for event in async_simulate_batch_stream(jobs, max_concurrent=4):
print(f"[{event.completed}/{event.total}] {event.label}")
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_concurrent
|
int | None
|
Maximum number of concurrent simulations. Defaults
to |
None
|
cache
|
SimulationCache | None
|
Optional simulation cache for content-hash lookups. |
None
|
fs
|
FileSystem | AsyncFileSystem | None
|
Optional file system backend. |
None
|
on_progress
|
Callable[[SimulationProgress], Any] | None
|
Optional callback invoked with
SimulationProgress events
during each individual simulation. Events include
|
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[SimulationEvent]
|
SimulationEvent for each completed simulation, in the order |
AsyncIterator[SimulationEvent]
|
they finish. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If jobs is empty. |
Source code in src/idfkit/simulation/async_batch.py
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 237 238 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 | |
SimulationEvent¶
idfkit.simulation.async_batch.SimulationEvent
dataclass
¶
Progress event emitted by async_simulate_batch_stream.
Each event represents a single simulation that has finished (successfully or not). Events are yielded in completion order, not submission order.
Attributes:
| Name | Type | Description |
|---|---|---|
index |
int
|
Zero-based position of this job in the original jobs sequence. |
label |
str
|
Human-readable label from the SimulationJob. |
result |
SimulationResult
|
The simulation result. |
completed |
int
|
Number of jobs completed so far (including this one). |
total |
int
|
Total number of jobs in the batch. |