ParallelStrategy¶
Bases: Serializable
Bundles program-level chunk dispatch together with optional nested
shot-level parallelism, reused identically by every
loqs.tools call site that parallelizes "one QuantumProgram per
chunk item" work (edesign circuits, error-injected programs,
noise-sweep points -- each of which builds and runs exactly one
QuantumProgram).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
ParallelStrategy ¶
ParallelStrategy(program_executor: SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable[[], SubmitExecutor | MapArrayExecutor] | None = None, n_program_chunks: int | None = None, n_shot_batches: int | None = None, shot_executor: SubmitExecutor | Callable[[], SubmitExecutor] | None = None, collect_resource_stats: bool = False, resource_sample_interval: float = 0.2, _resource_stats: list[ChunkResourceStats] = list(), _resolved_program_executor: SubmitExecutor | MapArrayExecutor | None = None) -> None
Attributes¶
| Name | Type | Value | Doc |
|---|---|---|---|
collect_resource_stats |
bool |
False |
|
is_chunked |
bool |
read-only property | Whether program_executor is set, i.e. whether chunks are |
n_program_chunks |
int | None |
None |
|
n_shot_batches |
int | None |
None |
|
program_executor |
|
None |
|
resource_sample_interval |
float |
0.2 |
|
shot_executor |
|
None |
decode¶
Inherited static method from Serializable.decode().
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
describe ¶
describe(items: Sequence[T] | None = None, num_shots: int | None = None) -> str
Human-readable summary of this strategy's configured parallelism at each axis, for sanity-checking a configuration before running anything.
Each axis is reported as a short backend tag (e.g.
"loky(max_workers=2)", via _describe_executor_tag/
ExecutorSpec.describe), followed by whichever indented fields
can actually be computed from what's known -- a field is simply
omitted (not printed as "unknown") when a required input (items,
num_shots, or a worker count the executor doesn't expose) is
missing. The program axis can report a genuine chunk count
(n_program_chunks is an explicit, independently-chosen setting)
alongside how many chunks land on each worker; the shot axis has
no analogous chunking setting -- shots are dispatched one at a
time -- so it only reports the total and the resulting average
per worker.
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
dispatch ¶
dispatch(worker_fn: Callable[[list[T]], R], chunks: Sequence[list[T]], desc: str = 'Processing chunks', on_poll: Callable[[], None] | None = None, poll_interval: float = 1.0) -> list[R]
Dispatch worker_fn over chunks via program_executor,
picking the dispatch mechanism (.submit()-per-chunk vs. a bulk
.map_array() call) automatically. Only valid when is_chunked
is True.
When collect_resource_stats is set, each chunk's worker is
transparently wrapped to self-report its own resource usage (see
_self_reporting_worker) -- the wrapping/unwrapping happens
entirely here, so this method's own return value (one real
result per chunk, in chunks order) is unaffected either way;
collected stats are appended to _resource_stats, retrievable
via pop_resource_stats().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
on_poll
|
Callable[[], None] | None
|
Optional callback invoked during dispatch polling (only relevant for certain executors/strategies). |
None
|
poll_interval
|
float
|
Polling interval in seconds (default 1.0). |
1.0
|
dump¶
Inherited method from Serializable.dump().
encode¶
Inherited static method from Serializable.encode().
load¶
Inherited class method from Serializable.load().
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
make_chunks ¶
make_chunks(items: Sequence[T]) -> list[list[T]]
Split items into round-robin chunks per n_program_chunks
(defaulting to one chunk per item when unset).
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
plot ¶
plot(items: Sequence[T] | None = None, program_workers: int | None = None, shot_workers: int | None = None, node_count: int = 1, legend: bool = True) -> matplotlib.axes.Axes
Diagram of this strategy's real dispatch structure.
See _plot for full documentation.
| Name | Type | Description | Default |
|---|---|---|---|
program_executor
|
SubmitExecutor | MapArrayExecutor | ExecutorSpec | Callable | None
|
How chunks are dispatched; An |
None
|
n_program_chunks
|
int | None
|
Number of round-robin chunks to split work into. Required when
|
None
|
n_shot_batches
|
int | None
|
Number of batches to split shots into when |
None
|
shot_executor
|
SubmitExecutor | Callable[[], SubmitExecutor] | None
|
Nested shot-level parallelism, forwarded as
|
None
|
collect_resource_stats
|
bool
|
Whether |
False
|
resource_sample_interval
|
float
|
Sampling interval (seconds) used when |
0.2
|
pop_resource_stats ¶
pop_resource_stats() -> list[ChunkResourceStats]
Return and clear every ChunkResourceStats collected by
dispatch() since the last call -- used by
profile_strategies() to drain one run's worth of
self-reported stats without leaving them to accumulate silently
across unrelated later calls.
read¶
Inherited class method from Serializable.read().
serialize_function¶
Inherited static method from Serializable.serialize_function().
write¶
Inherited method from Serializable.write().