engine
tit.opt.ex.engine ¶
Single-class exhaustive search engine.
Replaces: runner.py (5 classes), roi_utils.py (4 functions). Direct SimNIBS usage — ROI metrics are computed inline.
ExSearchEngine ¶
ExSearchEngine(leadfield_hdf: str, roi_file: str | tuple[str, int] | list[str | tuple[str, int]], roi_name: str, logger: Logger)
Exhaustive TI electrode search engine.
Owns the full pipeline: leadfield loading, ROI resolution and the simulation loop.
Source code in tit/opt/ex/engine.py
initialize ¶
initialize(roi_radius: float = 3.0) -> None
Load leadfield, resolve the ROI (CSV/mask/atlas), find ROI + GM elements.
Source code in tit/opt/ex/engine.py
compute_ti_fields ¶
compute_ti_fields(e1_plus: str, e1_minus: str, e2_plus: str, e2_minus: str, current_ratios: list[tuple[float, float]]) -> list[dict[str, float]]
ROI metrics of one electrode montage at every current split.
The field is linear in the injected current, so each channel's
unit-current field is gathered once and scaled per split -- the
same current * (lf[a] - lf[b]) arithmetic TI.get_field
performs, restricted to the elements the metrics read.
Source code in tit/opt/ex/engine.py
run ¶
run(e1_plus: list[str], e1_minus: list[str], e2_plus: list[str], e2_minus: list[str], current_ratios: list[tuple[float, float]], all_combinations: bool, output_dir: str, n_jobs: int = 1, symmetry_mirror_map: dict[str, str] | None = None, symmetry_pairing: str = 'within_pairs') -> dict[str, dict[str, float]]
Run the full simulation loop. Returns {mesh_key: metrics}.
Candidates are evaluated in enumeration order, one electrode
montage (all its current splits) per task, on n_jobs forked
workers (n_jobs < 1: the job's CPU budget, see
:func:tit.opt.ex.parallel.resolve_n_jobs; 1: in-process).
A symmetry_mirror_map (bucket mode) restricts the enumeration to
left/right mirrored montages (see :mod:tit.opt.ex.symmetry).
Signals are left to the caller: Ctrl-C raises KeyboardInterrupt
and a job cancel's SIGTERM ends the process (tit/jobs/runner.py),
so an interrupted search returns nothing and its run folder never
gets the files of a finished run.
Source code in tit/opt/ex/engine.py
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 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 | |