qram_simulator.word_backend

Reference native backend for the ideal sparse wide-word query chain.

Executes the frozen SparseWordMemory.apply_xor operator protocol (see qram_simulator.word_memory) on an exact dict-backed statevector whose basis indices are arbitrary-precision Python ints. Registers are named machine words of MACHINE_WORD_BITS bits, so logical registers wider than 64 bits genuinely span several words — the same layout discipline SparQSim’s production native backend follows.

This module is QRAM-Simulator’s own verification and product-demo executor. Production-scale native execution is provided by the caller’s backend (SparQSim); both are validated against the shared fixture bindings/python/test/fixtures/word_query_fixture.json.

Attributes

Classes

InplaceWordBackend

Protocol variant whose conditioned_by_bit returns None (pure mutation).

ReferenceWordBackend

Named machine-word register file with exact X / controlled-X execution.

SparseStateVector

Exact amplitudes over arbitrary-width basis indices (dict-backed).

WordXOperator

A native X on one machine-word bit, optionally controlled on |1>.

Functions

encode_basis(basis, pairs, value, backend) → int

OR the little-endian value into basis at the given coordinates.

word_layout(width, prefix[, machine_word_bits]) → list[tuple[str, int]]

Little-endian coordinates of one logical register over machine words.

Module Contents

class qram_simulator.word_backend.InplaceWordBackend(machine_word_bits: int = 64)[source]

Bases: ReferenceWordBackend

Protocol variant whose conditioned_by_bit returns None (pure mutation).

X_Bool(name, bit_index)[source]
class qram_simulator.word_backend.ReferenceWordBackend(machine_word_bits: int = 64)[source]

Named machine-word register file with exact X / controlled-X execution.

Every operation is an exact unitary permutation of the amplitudes — a genuine statevector execution, not a call recorder. Bit indices are confined to one machine word; wider logical registers span several word registers (see word_layout()).

X_Bool(name: str, bit_index: int) → WordXOperator[source]
make_state() → SparseStateVector[source]
position(pair: tuple[str, int]) → int[source]
register(*views) → None[source]

Touch every coordinate so later state creation sees the layout.

word_slot(name: str) → int[source]
class qram_simulator.word_backend.SparseStateVector[source]

Exact amplitudes over arbitrary-width basis indices (dict-backed).

amplitude(basis: int) → complex[source]
class qram_simulator.word_backend.WordXOperator(backend: ReferenceWordBackend, position: int)[source]

A native X on one machine-word bit, optionally controlled on |1>.

Follows the frozen protocol: conditioned_by_bit accepts the bit coordinate list, mutates the operator and returns self.

conditioned_by_bit(pairs)[source]
qram_simulator.word_backend.encode_basis(basis: int, pairs, value: int, backend: ReferenceWordBackend) → int[source]

OR the little-endian value into basis at the given coordinates.

qram_simulator.word_backend.word_layout(width: int, prefix: str, machine_word_bits: int = 64) → list[tuple[str, int]][source]

Little-endian coordinates of one logical register over machine words.

qram_simulator.word_backend.MACHINE_WORD_BITS: int = 64[source]