PySparQ.pysparq.algorithms.qram_utils

Classical helper functions for building QRAM circuits.

Attributes

PI

Pi constant matching the C++ constexpr double pi.

Functions

column_flatten(row_vec) → list[float]

Transpose a row-major square matrix into its column-major representation.

create_qram_utils_demo() → str

Return a demo script string showing typical usage of this module.

get_complement(data, data_sz) → int

Inverse two's complement: sign-extend an unsigned value to a signed integer.

make_complement(data, data_sz) → int

Convert a signed integer to its two's-complement representation.

make_func(value, n_digit) → list[complex]

Compute a 2x2 rotation matrix from a rational register value.

make_func_inv(value, n_digit) → list[complex]

Compute the inverse 2x2 rotation matrix from a rational register value.

make_vector_tree(dist, data_size) → list[int]

Build a binary tree for QRAM circuits from leaf-distribution data.

pow2(n) → int

Return 2**n via a left shift, matching basic.h semantics.

scale_and_convert_vector(input_vec, exponent, data_size) → list[int]

Scale floating-point values and convert to two's-complement integers.

Module Contents

PySparQ.pysparq.algorithms.qram_utils.column_flatten(row_vec: list[float]) → list[float][source]

Transpose a row-major square matrix into its column-major representation.

PySparQ.pysparq.algorithms.qram_utils.create_qram_utils_demo() → str[source]

Return a demo script string showing typical usage of this module.

PySparQ.pysparq.algorithms.qram_utils.get_complement(data: int, data_sz: int) → int[source]

Inverse two’s complement: sign-extend an unsigned value to a signed integer.

PySparQ.pysparq.algorithms.qram_utils.make_complement(data: int, data_sz: int) → int[source]

Convert a signed integer to its two’s-complement representation.

PySparQ.pysparq.algorithms.qram_utils.make_func(value: int, n_digit: int) → list[complex][source]

Compute a 2x2 rotation matrix from a rational register value.

PySparQ.pysparq.algorithms.qram_utils.make_func_inv(value: int, n_digit: int) → list[complex][source]

Compute the inverse 2x2 rotation matrix from a rational register value.

PySparQ.pysparq.algorithms.qram_utils.make_vector_tree(dist: list[int], data_size: int) → list[int][source]

Build a binary tree for QRAM circuits from leaf-distribution data.

PySparQ.pysparq.algorithms.qram_utils.pow2(n: int) → int[source]

Return 2**n via a left shift, matching basic.h semantics.

PySparQ.pysparq.algorithms.qram_utils.scale_and_convert_vector(input_vec: list[float] | numpy.ndarray, exponent: int, data_size: int, from_matrix: bool = ...) → list[int][source]

Scale floating-point values and convert to two’s-complement integers.

PySparQ.pysparq.algorithms.qram_utils.PI: float[source]

Pi constant matching the C++ constexpr double pi.