qram_simulator.mpi¶
qram_simulator.mpi — MPI ensemble parallel execution (trajectory level).
Single-node multi-process CPU parallelism for the noisy QRAM ensemble
workload (the T2-MPI benchmark family):
ranks shard the Monte-Carlo trajectory ensemble cyclically (
[rank::size]);every trajectory is seeded deterministically via
set_seed(seed + trajectory_index)beforerun_normal(), so the per-trajectory outcome is independent of the process count and of the sharding;rank 0 gathers the per-rank partials and aggregates them into exactly the same artifacts a serial run of the same total trajectory count would produce (per-trajectory samples identical; the histogram may differ only by floating-point summation order, ~1e-16 relative).
Honest scope: this is trajectory/ensemble-level parallelism over CPU processes (the Python bindings are CPU-only). It is not multi-GPU and not a distributed sparse-state partitioning.
Usage under MPI:
mpirun -np 4 python bench_script.py --mpi # each rank enters the script
Without a process manager world_comm() returns SerialComm
(the same code path runs serially), which keeps the module importable and
testable in environments without an MPI runtime (e.g. CI). This guard is
also required for correctness: importing mpi4py outside mpirun
triggers OpenMPI's singleton init, which setenv()``s ``OMPI_*/PMI*
variables at C level (invisible to os.environ); any mpirun child
launched later inherits them and aborts with a silent exit code 1.
Classes¶
Drop-in stand-in for |
Functions¶
|
Deterministically merge per-rank partials into ensemble outputs. |
|
Runtime facts for the parallel-execution record (ranks + GPUs, honestly). |
|
Execute the whole ensemble under |
|
Run the bench-faithful pruned trajectory loop over |
|
Cyclic trajectory shard |
Return |
Package Contents¶
- class qram_simulator.mpi.SerialComm[源代码]¶
Drop-in stand-in for
mpi4py.MPI.COMM_WORLDwith size == 1.
- qram_simulator.mpi.aggregate(partials: list[dict], runs: int) dict[源代码]¶
Deterministically merge per-rank partials into ensemble outputs.
Per-trajectory samples are re-ordered by trajectory index, so they are bit-identical across shardings; the histogram is summed over partials in rank order (a serial global-order sum differs only by float associativity, ~1e-16 relative).
- qram_simulator.mpi.mpi_metadata(comm) dict[源代码]¶
Runtime facts for the parallel-execution record (ranks + GPUs, honestly).
- qram_simulator.mpi.run_ensemble(qs, *, depth: int, data_size: int, noise: dict[Any, float], runs: int, seed: int, memory: Sequence[int] | None = None, input_mode: str = 'zerobus', n_inputs: int = 0, comm=None) dict | None[源代码]¶
Execute the whole ensemble under
comm; aggregate on rank 0.Returns the
aggregate()result plus anmpimetadata block on rank 0 (Noneon other ranks).noisemapsOperationTypemembers (or their names / int values) to channel probabilities. Whenmemoryis None, rank 0 draws it viaset_memory_randomand broadcasts it, so every rank simulates the same memory.
- qram_simulator.mpi.run_trajectories(qs, *, indices: Sequence[int], seed: int, noise: dict[Any, float], depth: int, data_size: int, memory: Sequence[int] | None = None, input_mode: str = 'zerobus', n_inputs: int = 0) dict[源代码]¶
Run the bench-faithful pruned trajectory loop over
indices.Mirrors the reference serial loop of the T2 benchmark (
run_normal -> sample_and_get_fidelity -> get_output_distribution -> get_fidelity_conventions), with the single addition of a deterministic per-trajectory reseedset_seed(seed + index).qsis theqram_simulatormodule (injected so tests and the source-tree fallback loader can pass whichever import succeeded).
- qram_simulator.mpi.shard_indices(runs: int, size: int, rank: int) list[int][源代码]¶
Cyclic trajectory shard
[rank::size](balances per-trajectory cost).
- qram_simulator.mpi.world_comm()[源代码]¶
Return
mpi4py.MPI.COMM_WORLDunder a process manager, elseSerialComm.Launched under
mpirun/mpiexecthe launcher sets rank/size environment variables on every rank — only then is mpi4py imported andCOMM_WORLDreturned. Otherwise aSerialCommis returned so the exact same code path runs serially without importing mpi4py: importing it outside a process manager triggers OpenMPI's singleton init, whose C-levelsetenv()side effects (invisible toos.environ) silently break anympirunchild spawned later from this process (exit code 1, no diagnostics).