loqs.internal¶
Functions¶
pin_worker_threads ¶
pin_worker_threads() -> None
Pin this process's numerical-library thread pools to one thread.
The primary, always-correct layer of the thread-oversubscription
discipline every chunk-processing worker entry point must apply as
its first action, regardless of which executor backend runs it:
environment variables (OMP_NUM_THREADS, etc.) only help if set
before the relevant library first initializes its own thread pool,
which isn't guaranteed for a worker process that already imported
numpy/pygsti-adjacent code before reaching this call. Meant to be
called directly inside a plain, module-level worker function -- not
built via a decorator, since a decorator would return a closure that
plain pickle (needed for mpi4py.futures.MPIPoolExecutor) can't
resolve by dotted import path.
Only the first call in each process pins: threadpool_limits scans
every loaded shared library, which takes about a second with LoQS's
dependencies loaded, so a worker that reaches this once per batch
would pay that every batch. The flag is keyed on os.getpid(), like
worker_id, so a forked child pins again.
worker_id ¶
worker_id() -> str
Return this process's cached hostname_pid_suffix worker identity
string, used to key per-writer checkpoint files across LoQS's parallel
dispatch mechanisms.
The suffix is a short UUID4-derived string, appended so that no two
workers ever resolve to the same identity even if the OS reuses a PID
across process launches on the same host. The result is cached
per-process, so multiple call sites within the same worker process
always agree -- but the cache is only reused after re-checking
os.getpid() against the cached PID, so a value cached before a
fork() is never silently inherited by the child process.