Skip to content

Commit

Permalink
planted noisy kXOR algorithm
Browse files Browse the repository at this point in the history
speedup
  • Loading branch information
anurudhp committed Nov 4, 2024
1 parent 58e6b71 commit 6cab862
Show file tree
Hide file tree
Showing 47 changed files with 13,444 additions and 18 deletions.
56 changes: 56 additions & 0 deletions dev_tools/qualtran_dev_tools/notebook_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
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.guided_hamiltonian
import qualtran.bloqs.mcmt.and_bloq
import qualtran.bloqs.mcmt.controlled_via_and
import qualtran.bloqs.mcmt.ctrl_spec_and
Expand Down Expand Up @@ -878,6 +881,58 @@
),
]

# --------------------------------------------------------------------------
# ----- 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],
),
]

NB_BY_SECTION = [
('Basic Gates', BASIC_GATES),
('Chemistry', CHEMISTRY),
Expand All @@ -886,5 +941,6 @@
('GF Arithmetic', GF_ARITHMETIC),
('Rotations', ROT_QFT_PE),
('Block Encoding', BLOCK_ENCODING),
('Paper: Quartic Quantum Speedups for Planted Inference', ALGO_QUARTIC_SPEEDUPS),
('Other', OTHER),
]
11 changes: 11 additions & 0 deletions docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ Bloqs Library
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
19 changes: 19 additions & 0 deletions qualtran/bloqs/max_k_xor_sat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .guiding_state import GuidingState, SimpleGuidingState
from .kikuchi_adjacency_list import KikuchiNonZeroIndex
from .kikuchi_adjacency_matrix import KikuchiMatrixEntry
from .kikuchi_block_encoding import KikuchiHamiltonian, KikuchiMatrixEntry, KikuchiNonZeroIndex
from .kxor_instance import Constraint, KXorInstance
from .planted_noisy_kxor import AliceTheorem, PlantedNoisyKXOR
16 changes: 16 additions & 0 deletions qualtran/bloqs/max_k_xor_sat/arithmetic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .has_duplicates import HasDuplicates
from .sort_in_place import SortInPlace
from .symmetric_difference import SymmetricDifference
Loading

0 comments on commit 6cab862

Please sign in to comment.