"""
CKS (Childs-Kothari-Somma) Linear System Solver Implementation
"""
from typing import Callable, Optional
import numpy as np
import pysparq as ps
[文档]
class ChebyshevPolynomialCoefficient:
"""Computes Chebyshev polynomial coefficients for quantum walk."""
def __init__(self, b: int) -> None: ...
[文档]
def C(self, Big: int, Small: int) -> float: ...
[文档]
def coef(self, j: int) -> float: ...
[文档]
def sign(self, j: int) -> bool: ...
[文档]
def step(self, j: int) -> int: ...
[文档]
def get_coef_positive_only(
mat_data_size: int, v: int, row: int, col: int
) -> list[complex]:
"""Get rotation matrix coefficients for positive-only matrix elements."""
...
[文档]
def get_coef_common(
mat_data_size: int, v: int, row: int, col: int
) -> list[complex]:
"""Get rotation matrix coefficients for general (signed) matrix elements."""
...
[文档]
def make_walk_angle_func(
mat_data_size: int, positive_only: bool
) -> Callable[[int, int, int], list[complex]]:
"""Create walk angle function for a matrix."""
...
[文档]
class SparseMatrixData:
"""Sparse matrix data for quantum simulation."""
[文档]
sparsity_offset: int
def __init__(
self,
n_row: int,
nnz_col: int,
data: list[int],
data_size: int,
positive_only: bool = ...,
sparsity_offset: int = ...,
) -> None: ...
[文档]
class SparseMatrix:
"""Sparse matrix representation for CKS algorithm."""
[文档]
sparsity_offset: int
def __init__(
self,
n_row: int,
nnz_col: int,
data: list[int],
data_size: int,
positive_only: bool = ...,
) -> None: ...
@classmethod
[文档]
def from_dense(
cls,
matrix: np.ndarray,
data_size: int = ...,
positive_only: Optional[bool] = ...,
) -> "SparseMatrix": ...
[文档]
def get_data(self) -> list[int]: ...
[文档]
def get_sparsity_offset(self) -> int: ...
[文档]
def get_walk_angle_func(self) -> Callable[[int, int, int], list[complex]]: ...
[文档]
class QuantumBinarySearch:
"""Quantum binary search for sparse matrix access."""
[文档]
qram: ps.QRAMCircuit_qutrit
[文档]
address_offset_reg: str
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self,
qram: ps.QRAMCircuit_qutrit,
address_offset_reg: str,
total_length: int,
target_reg: str,
result_reg: str,
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "QuantumBinarySearch": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "QuantumBinarySearch": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "QuantumBinarySearch": ...
[文档]
def clear_conditions(self) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
def __call__(self, state: ps.SparseState) -> None: ...
[文档]
class CondRotQW:
"""Conditional rotation for quantum walk."""
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self,
j_reg: str,
k_reg: str,
data_reg: str,
output_reg: str,
mat: SparseMatrix,
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "CondRotQW": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "CondRotQW": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "CondRotQW": ...
[文档]
def clear_conditions(self) -> None: ...
def __call__(self, state: ps.SparseState) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
[文档]
class TOperator:
"""T operator for CKS algorithm."""
[文档]
qram: ps.QRAMCircuit_qutrit
[文档]
data_offset_reg: str
[文档]
sparse_offset_reg: str
[文档]
search_result_reg: str
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self,
qram: ps.QRAMCircuit_qutrit,
data_offset_reg: str,
sparse_offset_reg: str,
j_reg: str,
b1_reg: str,
k_reg: str,
b2_reg: str,
search_result_reg: str,
nnz_col: int,
data_size: int,
mat: SparseMatrix,
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "TOperator": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "TOperator": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "TOperator": ...
[文档]
def clear_conditions(self) -> None: ...
def __call__(self, state: ps.SparseState) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
[文档]
class QuantumWalk:
"""Quantum walk operator for CKS algorithm."""
[文档]
qram: ps.QRAMCircuit_qutrit
[文档]
data_offset_reg: str
[文档]
sparse_offset_reg: str
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self,
qram: ps.QRAMCircuit_qutrit,
j_reg: str,
b1_reg: str,
k_reg: str,
b2_reg: str,
j_comp_reg: str,
k_comp_reg: str,
data_offset_reg: str,
sparse_offset_reg: str,
mat: SparseMatrix,
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "QuantumWalk": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "QuantumWalk": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "QuantumWalk": ...
[文档]
def clear_conditions(self) -> None: ...
def __call__(self, state: ps.SparseState) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
[文档]
class QuantumWalkNSteps:
"""Multiple quantum walk steps for CKS algorithm."""
[文档]
qram: ps.QRAMCircuit_qutrit
[文档]
default_reg_size: int
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self, mat: SparseMatrix, qram: Optional[ps.QRAMCircuit_qutrit] = ...
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "QuantumWalkNSteps": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "QuantumWalkNSteps": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "QuantumWalkNSteps": ...
[文档]
def clear_conditions(self) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
[文档]
def init_environment(self, state: ps.SparseState) -> None: ...
[文档]
def create_state(self) -> ps.SparseState: ...
[文档]
def first_step(self, state: ps.SparseState) -> None: ...
[文档]
def step(self, state: ps.SparseState) -> None: ...
[文档]
def make_n_step_state(self, n_steps: int) -> ps.SparseState: ...
[文档]
class LCUContainer:
"""LCU (Linear Combination of Unitaries) container for CKS."""
[文档]
chebyshev: ChebyshevPolynomialCoefficient
[文档]
walk: QuantumWalkNSteps
[文档]
current_state: Optional[ps.SparseState]
[文档]
step_state: Optional[ps.SparseState]
_condition_regs: list[str | int]
_condition_bits: list[tuple[str | int, int]]
def __init__(
self,
mat: SparseMatrix,
kappa: float,
eps: float,
qram: Optional[ps.QRAMCircuit_qutrit] = ...,
) -> None: ...
[文档]
def conditioned_by_nonzeros(
self, cond: str | int | list[str | int]
) -> "LCUContainer": ...
[文档]
def conditioned_by_all_ones(
self, conds: str | int | list[str | int]
) -> "LCUContainer": ...
[文档]
def conditioned_by_bit(self, reg: str | int, pos: int) -> "LCUContainer": ...
[文档]
def clear_conditions(self) -> None: ...
[文档]
def dag(self, state: ps.SparseState) -> None: ...
[文档]
def initialize(self) -> None: ...
[文档]
def iterate(self) -> bool: ...
[文档]
def cks_solve(
A: np.ndarray,
b: np.ndarray,
kappa: Optional[float] = ...,
eps: float = ...,
data_size: int = ...,
) -> np.ndarray:
"""Solve Ax = b using CKS quantum linear solver."""
...
[文档]
def create_cks_demo() -> str:
"""Generate a demo script for CKS solver."""
...