量子数据结构(qsample 与 sample-and-query)

oracq.algorithms.input_model.qdata

KP/QFVM style quantum data structures: QVector (qsample) with a squared-norm tree, and the sample-and-query QMatrix.

QVector implements the data structure shared by Kerenidis-Prakash (arXiv:1603.08675 Thm 5.1 + Appendix A.1) and QFVM (arXiv:2102.03557 Eqs. 15–22): a binary tree whose leaves store squared components rolled up layer by layer, with internal nodes caching RY rotation angle words; the quantum side prepares the normalized state layer by layer, with two QRAM queries per layer. Signs are written through an independent 1-bit bank by phase kickback. On top of this, QMatrix implements sample-and-query access (arXiv:1704.04992 §I.1): the entries bank supports queries in arbitrary superposition, the row trees give Ũ|i⟩|0⟩→|i⟩|Ā_i⟩, and the row-norm root tree gives Ṽ|0⟩|j⟩→|Ã⟩|j⟩.

class oracq.algorithms.input_model.qdata.QVector(values, *, fmt=None, angle_width=8, name='qvec')[源代码]

基类:object

qsample vector: squared-norm binary tree + angle-word/sign banks, supporting O(log) classical local updates.

signs()[源代码]

Sign bank content; when all signs are zero the signed preparation can be omitted.

返回:

Mapping from indices to sign bits, containing only negative-component entries.

返回类型:

dict[int, int]

update(index, value)[源代码]

Single-point update: only the sums and angle words along the leaf-to-root path are recomputed; returns the changes to the angle word bank.

参数:
  • index -- Index of the component to update, range 0..2^width-1.

  • value -- New component value, which must be encodable by the fixed-point format.

返回:

Changes to the angle word bank, keyed by the address, i.e. the tree node number minus one.

返回类型:

dict[int, int]

property norm

the square root of the squared-norm tree root (computed from the fixed-point decoded values).

Type:

Euclidean norm of the vector

amplitudes()[源代码]

Normalized expected amplitudes (including quantization and signs), as the classical reference.

返回:

Amplitude table of length 2^width after division by the Euclidean norm.

返回类型:

list[float]

snapshot(*, signed=False)[源代码]

Export a snapshot of the QRAM bank contents, for simulate and the like to bind data by name.

参数:

signed -- When True, attach the sign bank, containing only negative-component entries.

返回:

Keys are {name}_angles (address is the tree node number minus one), plus the optional {name}_sign.

返回类型:

dict

preparation(*, signed=False, name=None)[源代码]

Layer-by-layer tree preparation addressed via QMem; when signed, the phase is written via Load→Z→inverse Load.

参数:
  • signed -- When True, attach the phase writing from the sign bank.

  • name -- Name of the generated operation; derived from the vector name and bit widths by default.

返回:

View preparing the normalized state via layer-by-layer QRAM queries.

返回类型:

StatePreparation

class oracq.algorithms.input_model.qdata.QMatrix(matrix, *, fmt=None, angle_width=8, name='qmat')[源代码]

基类:object

Sample-and-query matrix: entry query + row qsample Ũ + row-norm root tree Ṽ; entries are restricted to nonnegative values.

update(row, column, value)[源代码]

Single-entry update: recompute the affected row tree and the root tree path; returns the changes to each bank.

参数:
  • row -- Row index of the entry to update, range 0..2^rows-1.

  • column -- Column index of the entry to update, range 0..2^cols-1.

  • value -- New entry value, which must lie within the nonnegative range of the fixed-point format.

返回:

Changes to the three banks entries, row_angles and root_angles.

返回类型:

dict[str, dict[int, int]]

property frobenius

the square root of the root tree root, i.e. the square root of the sum of squared entries.

Type:

Frobenius norm of the matrix

row_norm(index)[源代码]

Return the Euclidean norm of row index (the square root of the row tree root).

参数:

index -- Row index, range 0..2^rows-1.

返回:

Square root of the sum of squared entries of that row.

返回类型:

float

row_amplitudes(index)[源代码]

Normalized expected amplitudes of row index (the reference ground truth for the row qsample).

参数:

index -- Row index, range 0..2^rows-1.

返回:

Amplitude table of that row after division by the row norm.

返回类型:

list[float]

user_amplitudes()[源代码]

Normalized expected amplitudes of the root tree (the reference ground truth for the user superposition prepared by Ṽ).

返回:

The i-th entry is the ratio of the i-th row norm to the Frobenius norm.

返回类型:

list[float]

snapshot()[源代码]

Export a snapshot of the entries bank and the row/root angle banks.

返回:

Keys are entries (row-major flattened addresses to fixed-point words), row_angles and root_angles.

返回类型:

dict

query()[源代码]

Entry XOR query: the word at address (row, column) is XORed into data, addressed by a two-dimensional pointer.

返回:

Query view backed by the row-major flattened entries bank.

返回类型:

XorDatabase

row_preparation()[源代码]

Ũ: prepare the item register from the zero state into the normalized row vector of row i; the row trees are addressed two-dimensionally by (row, prefix).

返回:

The unitary operation implementing Ũ.

返回类型:

Operation

amplitude_preparation()[源代码]

Ṽ: prepare the zero-state row register into the user distribution Ã, with the item register passed through.

返回:

The unitary operation implementing Ṽ.

返回类型:

Operation

row_state_prep(user)[源代码]

One-dimensional tree preparation of the classical row user, with the row number folded into a constant address.

参数:

user -- Classical row number, range 0..2^rows-1.

返回:

1D tree preparation view of that row's normalized row vector.

返回类型:

StatePreparation