QRAM YAML 内存格式

oracq.infrastructure.qram_schema

Parsing, loading and writing of QRAM memory definition files (*.qram.yaml).

class oracq.infrastructure.qram_schema.RegisteredQRAM(name, address_length, word_length, cells)[源代码]

基类:object

An immutable host-side memory snapshot, separate from its RIR declaration.

Registration allocates no native backend object. Unspecified cells contain zero, and snapshot returns a fresh mapping suitable for execution.

name
address_length
word_length
cells
property type

RIR resource type, retaining both declared bit widths.

snapshot()[源代码]

Copy the registered words; missing addresses read as zero.

database()[源代码]

Build an XOR query oracle with this bank's resource name.

oracq.infrastructure.qram_schema.register_qram(data, address_length, word_length, *, name=None)[源代码]

Snapshot unsigned QRAM words without creating a backend dependency.

A sequence uses its indices as addresses; a mapping may be sparse. The default name is derived from the widths and contents. Explicit names must identify the same contents when multiple inputs share a bank.

class oracq.infrastructure.qram_schema.QramSegment(name, address_length, word_length, type, data, addresses=None)[源代码]

基类:object

One segment in a qram YAML file.

变量:
  • name (str) -- storage name, indexed by entry resource name at execution time.

  • address_length (int) -- address bit width, a positive integer, corresponding to the RIR QRAM address_width.

  • word_length (int) -- data word bit width, a positive integer, corresponding to the RIR QRAM data_width.

  • type (str) -- data type, see QRAM_DATA_TYPES; data is interpreted under this type.

  • data (tuple[int, ...] | tuple[float, ...]) -- source values, interpreted per type.

  • addresses (tuple[int, ...] | None) -- explicit sparse addresses, or None for a dense zero-padded array.

name
address_length
word_length
type
data
addresses = None
oracq.infrastructure.qram_schema.parse_qram_yaml(document)[源代码]

Parse and validate one qram YAML memory definition text.

参数:

document -- YAML text whose top level contains only the qram_segments list.

返回:

segment tuple in order of appearance in the file; data keeps the source values, interpreted per type.

返回类型:

tuple

抛出:

ValidationError -- the text is not valid YAML, the structure does not match, a segment name is missing or duplicated, a bit width is out of range, the data type is unsupported, or the source data falls outside the range set by type and word_length.

oracq.infrastructure.qram_schema.load_qram_yaml(path)[源代码]

Load a qram YAML memory definition file into the memory mapping accepted by executors.

Source data is encoded per segment type into unsigned words (sint takes the two's-complement bit pattern, fixedpoint multiplies by 2^word_length then truncates toward zero). Dense segments are zero-padded; sparse segments remain mappings; the resource name set and data ranges are cross-checked against program declarations by check_memory at execution time.

参数:

path -- YAML file path.

返回:

mapping from resource names to dense arrays or sparse address/word mappings, the same shape as the memory parameter of execution entry points such as simulate.

返回类型:

dict

oracq.infrastructure.qram_schema.dump_qram_yaml(program, memory, *, sparse=False)[源代码]

Write the entry's QRAM binding data as qram YAML text.

The data is first normalized and cross-checked by check_memory (sparse dicts densified, with zero cells and missing high cells both treated as zero), then segments are generated in entry resource declaration order; on the executor side the words are already unsigned integers within the bit width, so the segment type is always uint; the default dense array preserves the legacy format. With sparse=True, explicit address/value pairs avoid string-key ambiguity and expansion of zero cells.

参数:
  • program -- closed RIR program providing resource name and bit width declarations.

  • memory -- data provided by resource name; each item is a word sequence or a sparse address -> word dict, and None is treated as all zeros. The resource set must exactly match the entry declaration.

  • sparse -- Opt in to sparse pairs and JSON-compatible YAML output; omitted addresses read zero.

返回:

qram YAML text, written to disk or hashed by the caller.

返回类型:

str