uniqc.circuit_builder.qram module¶
Quantum RAM (QRAM) data structure.
Provides a simple binary-addressed classical memory used by quantum circuits. A QRAM is declared with an address size and data size; at runtime it stores integers (0 <= value < 2^data_size) indexed by addresses (0 <= addr < 2^addr_size).
Example usage in OriginIR-ext:
QRAMDECL my_ram 3,6
QINIT 9
CREG 0
my_ram q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8]
The above declares my_ram as a QRAM with 3-bit address and 6-bit data
(9 qubits total). Callers index it as
my_ram q[0],q[1],q[2],q[3],q[4],q[5],q[6],q[7],q[8] where q[0..2] are
the address bits (q[0] = LSB) and q[3..8] are the data bits (q[3] = LSB).
- class uniqc.circuit_builder.qram.QRAM(name, addr_size, data_size)[source]¶
Bases:
objectA simple binary-addressed quantum RAM.
- Parameters:
- read(addr)[source]¶
Read the value stored at addr.
- Parameters:
addr (int) – Address index (0 <= addr < 2^addr_size).
- Returns:
The stored integer.
- Raises:
IndexError – If addr is out of range.
- Return type:
- reset(value=0)[source]¶
Reset all entries to value (default 0).
- Parameters:
value (int) – Value to fill every address with.
- Raises:
ValueError – If value exceeds the data capacity.
- Return type:
None
- write(addr, value)[source]¶
Write value at address addr.
- Parameters:
- Raises:
IndexError – If addr is out of range.
ValueError – If value exceeds the data capacity.
- Return type:
None