qram_simulator.baseline

Circuit-level QRAM baseline simulator (qubit architecture, 1-2 tree layers).

This subpackage provides an independent, gate-by-gate re-implementation of the qubit-architecture QRAM loading circuit on the UnifiedQuantum (uniqc) QuTiP density-matrix backend, used as a semi-quantitative cross-check baseline for the symbolic sparse-tree trajectory engine exported by qram_simulator.QRAMCircuitQubit.

The noise model mirrors the TimeStep scheduler of the C++ core: channels are placed only on the QRAM routing-tree qubits (never on the address register or the data bus), on every active position [0, 2*(2^l - 1)) of each time slice whose entangled-layer count is l, with marginal probability p per position per step (the channel-level counterpart of the C++ "nerror ~ Binomial(N, p), uniform positions" trajectory sampling).

See compare for the packaged comparison experiment and the module docstring of circuit_qram for the encoding and operator conventions.

Submodules

Classes

CircuitQRAMQubit

Circuit-level baseline of the qubit-architecture QRAM loading circuit.

Functions

classical_fidelity(p, q) → float

Classical distribution fidelity (sum of sqrt(p*q))^2.

tvd(p, q) → float

Total variation distance 0.5 * sum |p - q|.

Package Contents

class qram_simulator.baseline.CircuitQRAMQubit(addr_size: int, data_size: int, memory: Sequence[int], *, depolarizing: float = 0.0, damping: float = 0.0, bit_flip: float = 0.0, phase_flip: float = 0.0, input_mode: str = 'zerobus')[源代码]

Circuit-level baseline of the qubit-architecture QRAM loading circuit.

addr_sizeint

Address width = tree depth. Only 1 or 2 is supported (density-matrix size limit); addr=1 only exercises the noise-free bridge (plus the whole-tree part of Damping).

data_sizeint

Bits per memory cell (1 or 2).

memorysequence of int

Data tree, length 2**addr_size, every entry < 2**data_size (the C++ fidelity XORs raw values; out-of-range entries are silently scored 0).

depolarizing, dampingfloat

Noise probabilities of the two supported channels, mirroring QRAMCircuitQubit.set_noise_models. Applied on tree qubits only.

input_mode{"zerobus", "uniform"}

"zerobus" (default): uniform superposition of addresses, bus = 0 -- the discriminating input; "uniform": uniform address and bus.

fidelity_with_ideal(rho: numpy.ndarray, rho_ideal: numpy.ndarray = None) → float[源代码]

<psi_ideal|rho|psi_ideal>, the same convention as the C++ overlap_fid.

For the pure ideal state this equals Re Tr(rho @ rho_ideal); it is the statistic that matches the QRAM-Simulator trajectory average E|<psi_ideal|psi_traj>|^2 (avg_overlap_fid).

ideal_density_matrix() → numpy.ndarray[源代码]

Density matrix of the noise-free circuit (pure state, trace 1).

logical_density_matrix(rho: numpy.ndarray) → numpy.ndarray[源代码]

Trace out tree qubits; visible index is address + (bus << addr_size).

This retains address/bus coherences and sums only equal environment indices. It is independent of the sparse engine's observable code.

logical_fidelity_with_ideal(rho: numpy.ndarray) → float[源代码]

Overlap with the pure ideal address/bus query after a physical partial trace.

No router reset or postselection is imposed. This differs from the full-circuit fidelity_with_ideal and tree-insensitive conventions.

marginal_distribution(rho: numpy.ndarray) → dict[str, float][源代码]

Marginal (address:bus) distribution of a density matrix.

Same key convention as QRAMCircuitQubit.get_output_distribution ("addr:bus" with the plain integers), so the two sides compare key-for-key.

run(mode: str = 'faithful') → dict[str, Any][源代码]

Convenience wrapper: ideal + noisy density matrices and all metrics.

Returns a dict with ideal_rho/ideal_dist, rho/dist/trace and fidelity (= fidelity_with_ideal). The modern complete channels have trace one. Only explicit legacy/nojump diagnostics may return sub-normalized distributions; their trace is not the core's trajectory norm.

simulate_density(mode: str = 'faithful') → numpy.ndarray[源代码]

Run the noisy circuit on the uniqc QuTiP density-matrix backend.

mode{"faithful", "textbook", "legacy", "nojump"}

"faithful" (default): depolarizing as the {I,X,Z,Y} mixture and fixed whole-tree amplitude damping, matching the current core; "textbook": equivalent standard TP channels; "legacy": retired rho-dependent damping mirror, not a standard channel certificate; "nojump": damping K0 branch only (trace = no-jump weight).

to_gate_list() → list[Gate][源代码]

Flat noise-free gate list (input preparation gates excluded).

qram_simulator.baseline.classical_fidelity(p: Mapping[str, float], q: Mapping[str, float]) → float[源代码]

Classical distribution fidelity (sum of sqrt(p*q))^2.

qram_simulator.baseline.tvd(p: Mapping[str, float], q: Mapping[str, float]) → float[源代码]

Total variation distance 0.5 * sum |p - q|.