Source code for PySparQ.pysparq.algorithms.state_preparation
"""Quantum state preparation based on QRAM binary-tree decomposition."""
from __future__ import annotations
from typing import Union
[docs]
class StatePrepViaQRAM:
"""Quantum state-preparation operator based on QRAM binary-tree decomposition."""
def __init__(
self,
qram: object,
work_qubit: str,
data_size: int,
rational_size: int,
) -> None: ...
[docs]
def conditioned_by_nonzeros(
self, cond: Union[str, int, list[Union[str, int]]]
) -> "StatePrepViaQRAM": ...
[docs]
def conditioned_by_all_ones(
self, cond: Union[str, int, list[Union[str, int]]]
) -> "StatePrepViaQRAM": ...
[docs]
def conditioned_by_bit(
self, reg: Union[str, int], bit: int
) -> "StatePrepViaQRAM": ...
[docs]
def clear_conditions(self) -> "StatePrepViaQRAM": ...
def __call__(self, state: "SparseState") -> None: ...
[docs]
def dag(self, state: "SparseState") -> None: ...
[docs]
class StatePreparation:
"""High-level wrapper managing the full state-preparation pipeline."""
[docs]
qram: Union[object, None]
def __init__(self, qubit_number: int, data_size: int, data_range: int) -> None: ...
[docs]
def random_distribution(self) -> None:
"""Generate a random amplitude distribution."""
...
[docs]
def show_distribution(self) -> None:
"""Print the raw values and normalized amplitudes of the distribution."""
...
[docs]
def get_real_dist(self) -> list[float]:
"""Return the normalized amplitude distribution as a list of floats."""
...
[docs]
def make_tree(self) -> None:
"""Build the binary tree from the current distribution."""
...
[docs]
def show_tree(self) -> None:
"""Print the binary tree level by level."""
...
[docs]
def make_qram(self) -> None:
"""Create a QRAM circuit sized for the tree data."""
...
[docs]
def set_qram(self) -> None:
"""Load the binary-tree data into the QRAM circuit."""
...
[docs]
def get_fidelity(self) -> float:
"""Compute the fidelity between the prepared state and the target state."""
...
[docs]
def run(self) -> None:
"""Run the full state-preparation pipeline."""
...
[docs]
def create_state_preparation_demo() -> str:
"""Return a demo script string for state preparation."""
...