Skip to content

Commit

Permalink
planted noisy kXOR algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
anurudhp committed Oct 8, 2024
1 parent fbb031b commit 04bbfa9
Show file tree
Hide file tree
Showing 56 changed files with 14,302 additions and 20 deletions.
72 changes: 72 additions & 0 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import qualtran.bloqs.block_encoding.phase
import qualtran.bloqs.block_encoding.product
import qualtran.bloqs.block_encoding.sparse_matrix
import qualtran.bloqs.block_encoding.sparse_matrix_hermitian
import qualtran.bloqs.block_encoding.tensor_product
import qualtran.bloqs.block_encoding.unitary
import qualtran.bloqs.bookkeeping
Expand Down Expand Up @@ -111,6 +112,18 @@
import qualtran.bloqs.gf_arithmetic.gf2_multiplication
import qualtran.bloqs.gf_arithmetic.gf2_square
import qualtran.bloqs.hamiltonian_simulation.hamiltonian_simulation_by_gqsp
import qualtran.bloqs.max_k_xor_sat
import qualtran.bloqs.max_k_xor_sat.arithmetic
import qualtran.bloqs.max_k_xor_sat.arithmetic.has_duplicates
import qualtran.bloqs.max_k_xor_sat.arithmetic.sort_in_place
import qualtran.bloqs.max_k_xor_sat.arithmetic.symmetric_difference
import qualtran.bloqs.max_k_xor_sat.guided_hamiltonian
import qualtran.bloqs.max_k_xor_sat.guided_hamiltonian.guided_hamiltonian
import qualtran.bloqs.max_k_xor_sat.guided_hamiltonian.walk_operator
import qualtran.bloqs.max_k_xor_sat.guiding_state
import qualtran.bloqs.max_k_xor_sat.kikuchi_block_encoding
import qualtran.bloqs.max_k_xor_sat.load_kxor_instance
import qualtran.bloqs.max_k_xor_sat.planted_noisy_kxor
import qualtran.bloqs.mcmt.and_bloq
import qualtran.bloqs.mcmt.controlled_via_and
import qualtran.bloqs.mcmt.ctrl_spec_and
Expand Down Expand Up @@ -746,6 +759,13 @@
module=qualtran.bloqs.block_encoding.sparse_matrix,
bloq_specs=[qualtran.bloqs.block_encoding.sparse_matrix._SPARSE_MATRIX_DOC],
),
NotebookSpecV2(
title='Sparse Matrix (Hermitian)',
module=qualtran.bloqs.block_encoding.sparse_matrix_hermitian,
bloq_specs=[
qualtran.bloqs.block_encoding.sparse_matrix_hermitian._SPARSE_MATRIX_HERMITIAN_DOC
],
),
NotebookSpecV2(
title='Chebyshev Polynomial',
module=qualtran.bloqs.block_encoding.chebyshev_polynomial,
Expand Down Expand Up @@ -875,6 +895,57 @@
],
),
]
# --------------------------------------------------------------------------
# ----- Quartic Speedups paper ------------------------------------------
# --------------------------------------------------------------------------
ALGO_QUARTIC_SPEEDUPS = [
# ----- Preliminaries ------------------------------------------
NotebookSpecV2(
title='Guided (sparse) Hamiltonian Problem',
module=qualtran.bloqs.max_k_xor_sat.guided_hamiltonian.guided_hamiltonian,
bloq_specs=[
qualtran.bloqs.max_k_xor_sat.guided_hamiltonian.guided_hamiltonian._GUIDED_HAMILTONIAN_DOC,
qualtran.bloqs.max_k_xor_sat.guided_hamiltonian.guided_hamiltonian._GUIDED_HAMILTONIAN_PHASE_ESTIMATION_DOC,
],
),
NotebookSpecV2(
title='Arithmetic Primitives',
module=qualtran.bloqs.max_k_xor_sat.arithmetic,
bloq_specs=[
qualtran.bloqs.max_k_xor_sat.arithmetic.sort_in_place._SORT_IN_PLACE_DOC,
qualtran.bloqs.max_k_xor_sat.arithmetic.symmetric_difference._SYMMETRIC_DIFFERENCE_DOC,
qualtran.bloqs.max_k_xor_sat.arithmetic.has_duplicates._HAS_DUPLICATES_DOC,
],
),
# ----- Algorithm ------------------------------------------
NotebookSpecV2(
title='kXOR: Instance load Oracles',
module=qualtran.bloqs.max_k_xor_sat.load_kxor_instance,
bloq_specs=[qualtran.bloqs.max_k_xor_sat.load_kxor_instance._LOAD_INSTANCE_DOC],
),
NotebookSpecV2(
title='Noisy kXOR: Guiding State',
module=qualtran.bloqs.max_k_xor_sat.guiding_state,
bloq_specs=[
qualtran.bloqs.max_k_xor_sat.guiding_state._SIMPLE_GUIDING_STATE_DOC,
qualtran.bloqs.max_k_xor_sat.guiding_state._GUIDING_STATE_DOC,
],
),
NotebookSpecV2(
title='Noisy kXOR: Block-encoding the Kikuchi Matrix',
module=qualtran.bloqs.max_k_xor_sat.kikuchi_block_encoding,
bloq_specs=[
qualtran.bloqs.max_k_xor_sat.kikuchi_adjacency_matrix._KIKUCHI_MATRIX_ENTRY_DOC,
qualtran.bloqs.max_k_xor_sat.kikuchi_adjacency_list._KIKUCHI_NONZERO_INDEX_DOC,
qualtran.bloqs.max_k_xor_sat.kikuchi_block_encoding._KIKUCHI_HAMILTONIAN_DOC,
],
),
NotebookSpecV2(
title='Algorithm: Planted Noise kXOR',
module=qualtran.bloqs.max_k_xor_sat.planted_noisy_kxor,
bloq_specs=[qualtran.bloqs.max_k_xor_sat.planted_noisy_kxor._PLANTED_NOISY_KXOR_DOC],
),
]

# --------------------------------------------------------------------------
# ----- Concepts -------------------------------------------------------
Expand Down Expand Up @@ -902,6 +973,7 @@
('GF Arithmetic', GF_ARITHMETIC),
('Rotations', ROT_QFT_PE),
('Block Encoding', BLOCK_ENCODING),
('Paper: Quartic Quantum Speedups for Planted Inference', ALGO_QUARTIC_SPEEDUPS),
('Other', OTHER),
]

Expand Down
12 changes: 12 additions & 0 deletions docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,21 @@ Bloqs Library
block_encoding/phase.ipynb
block_encoding/linear_combination.ipynb
block_encoding/sparse_matrix.ipynb
block_encoding/sparse_matrix_hermitian.ipynb
block_encoding/chebyshev_polynomial.ipynb
block_encoding/lcu_block_encoding.ipynb

.. toctree::
:maxdepth: 2
:caption: Paper: Quartic Quantum Speedups for Planted Inference:

max_k_xor_sat/guided_hamiltonian/guided_hamiltonian.ipynb
max_k_xor_sat/arithmetic/arithmetic.ipynb
max_k_xor_sat/load_kxor_instance.ipynb
max_k_xor_sat/guiding_state.ipynb
max_k_xor_sat/kikuchi_block_encoding.ipynb
max_k_xor_sat/planted_noisy_kxor.ipynb

.. toctree::
:maxdepth: 2
:caption: Other:
Expand Down
11 changes: 6 additions & 5 deletions qualtran/bloqs/arithmetic/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
bloq_example,
BloqBuilder,
BloqDocSpec,
DecomposeNotImplementedError,
DecomposeTypeError,
QBit,
QUInt,
Expand Down Expand Up @@ -222,8 +223,6 @@ def __attrs_post_init__(self):
k = self.half_length
if not is_symbolic(k):
assert k >= 1, "length of input lists must be positive"
# TODO(#1090) support non-power-of-two input lengths
assert (k & (k - 1)) == 0, "length of input lists must be a power of 2"

@cached_property
def signature(self) -> 'Signature':
Expand All @@ -249,14 +248,16 @@ def is_symbolic(self):
def build_composite_bloq(
self, bb: 'BloqBuilder', xs: 'SoquetT', ys: 'SoquetT'
) -> dict[str, 'SoquetT']:
if is_symbolic(self.half_length):
k = self.half_length
if is_symbolic(k):
raise DecomposeTypeError(f"Cannot decompose symbolic {self=}")
if (k & (k - 1)) == 0:
# TODO(#1090) support non-power-of-two input lengths
raise DecomposeNotImplementedError("length of input lists must be a power of 2")

assert isinstance(xs, np.ndarray)
assert isinstance(ys, np.ndarray)

k = self.half_length

first_round_junk = []
for i in range(k):
xs[i], ys[k - 1 - i], anc = bb.add(Comparator(self.bitsize), a=xs[i], b=ys[k - 1 - i])
Expand Down
3 changes: 2 additions & 1 deletion qualtran/bloqs/basic_gates/x_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,14 @@ def my_tensors(

def get_ctrl_system(self, ctrl_spec: 'CtrlSpec') -> Tuple['Bloq', 'AddControlledT']:
from qualtran.bloqs.basic_gates import CNOT, Toffoli
from qualtran.bloqs.mcmt import ControlledViaAnd

if ctrl_spec == CtrlSpec():
bloq: 'Bloq' = CNOT()
elif ctrl_spec == CtrlSpec(cvs=(1, 1)):
bloq = Toffoli()
else:
return super().get_ctrl_system(ctrl_spec)
return ControlledViaAnd.make_ctrl_system(self, ctrl_spec)

def add_controlled(
bb: 'BloqBuilder', ctrl_soqs: Sequence['SoquetT'], in_soqs: Dict[str, 'SoquetT']
Expand Down
1 change: 1 addition & 0 deletions qualtran/bloqs/block_encoding/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
from qualtran.bloqs.block_encoding.phase import Phase
from qualtran.bloqs.block_encoding.product import Product
from qualtran.bloqs.block_encoding.sparse_matrix import SparseMatrix
from qualtran.bloqs.block_encoding.sparse_matrix_hermitian import SparseMatrixHermitian
from qualtran.bloqs.block_encoding.tensor_product import TensorProduct
from qualtran.bloqs.block_encoding.unitary import Unitary
8 changes: 8 additions & 0 deletions qualtran/bloqs/block_encoding/block_encoding_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def ancilla_bitsize(self) -> SymbolicInt:
def resource_bitsize(self) -> SymbolicInt:
"""The number of resource qubits not counted in ancillas."""

@property
def ctrl_bitsize(self) -> SymbolicInt:
"""The number of control qubits, useful to define optimized custom controlled circuits.
Usually either 0 or 1, as all other control cases can be reduced to 1.
"""
return 0

@property
@abc.abstractmethod
def epsilon(self) -> SymbolicFloat:
Expand Down
Loading

0 comments on commit 04bbfa9

Please sign in to comment.