Skip to content

Implement Kikuchi graph oracles and block-encoding #1555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion dev_tools/qualtran_dev_tools/notebook_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import qualtran.bloqs.multiplexers.black_box_select
import qualtran.bloqs.multiplexers.select_base
import qualtran.bloqs.multiplexers.select_pauli_lcu
import qualtran.bloqs.optimization.k_xor_sat
import qualtran.bloqs.optimization.k_xor_sat.kikuchi_guiding_state
import qualtran.bloqs.phase_estimation.lp_resource_state
import qualtran.bloqs.phase_estimation.qubitization_qpe
Expand Down Expand Up @@ -809,14 +810,41 @@
# ----- Optimization ---------------------------------------------------
# --------------------------------------------------------------------------
OPTIMIZATION: List[NotebookSpecV2] = [
# ----- Algorithm ------------------------------------------
NotebookSpecV2(
title='kXOR: Instance load Oracles',
module=qualtran.bloqs.optimization.k_xor_sat.load_kxor_instance,
bloq_specs=[qualtran.bloqs.optimization.k_xor_sat.load_kxor_instance._LOAD_INSTANCE_DOC],
),
NotebookSpecV2(
title='Planted Noisy kXOR - Kikuchi Guiding State',
module=qualtran.bloqs.optimization.k_xor_sat.kikuchi_guiding_state,
bloq_specs=[
qualtran.bloqs.optimization.k_xor_sat.kikuchi_guiding_state._SIMPLE_GUIDING_STATE_DOC,
qualtran.bloqs.optimization.k_xor_sat.kikuchi_guiding_state._GUIDING_STATE_DOC,
],
)
),
NotebookSpecV2(
title='Planted Noisy kXOR: Kikuchi Adjacency List',
module=qualtran.bloqs.optimization.k_xor_sat.kikuchi_adjacency_list,
bloq_specs=[
qualtran.bloqs.optimization.k_xor_sat.kikuchi_adjacency_list._KIKUCHI_NONZERO_INDEX_DOC
],
),
NotebookSpecV2(
title='Planted Noisy kXOR: Kikuchi Adjacency Matrix',
module=qualtran.bloqs.optimization.k_xor_sat.kikuchi_adjacency_matrix,
bloq_specs=[
qualtran.bloqs.optimization.k_xor_sat.kikuchi_adjacency_matrix._KIKUCHI_MATRIX_ENTRY_DOC
],
),
NotebookSpecV2(
title='Planted Noisy kXOR: Block-encoding the Kikuchi Matrix',
module=qualtran.bloqs.optimization.k_xor_sat.kikuchi_block_encoding,
bloq_specs=[
qualtran.bloqs.optimization.k_xor_sat.kikuchi_block_encoding._KIKUCHI_HAMILTONIAN_DOC
],
),
]

# --------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ Bloqs Library
:maxdepth: 2
:caption: Optimization:

optimization/k_xor_sat/load_kxor_instance.ipynb
optimization/k_xor_sat/kikuchi_guiding_state.ipynb
optimization/k_xor_sat/kikuchi_adjacency_list.ipynb
optimization/k_xor_sat/kikuchi_adjacency_matrix.ipynb
optimization/k_xor_sat/kikuchi_block_encoding.ipynb

.. toctree::
:maxdepth: 2
Expand Down
4 changes: 4 additions & 0 deletions qualtran/bloqs/optimization/k_xor_sat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
# 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 .kikuchi_adjacency_list import KikuchiNonZeroIndex
from .kikuchi_adjacency_matrix import KikuchiMatrixEntry
from .kikuchi_block_encoding import KikuchiHamiltonian, KikuchiMatrixEntry, KikuchiNonZeroIndex
from .kikuchi_guiding_state import GuidingState, SimpleGuidingState
from .kxor_instance import Constraint, KXorInstance
from .load_kxor_instance import LoadConstraintScopes, LoadUniqueScopeIndex, PRGAUniqueConstraintRHS
180 changes: 180 additions & 0 deletions qualtran/bloqs/optimization/k_xor_sat/kikuchi_adjacency_list.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3c1703d8",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# Planted Noisy kXOR: Kikuchi Adjacency List"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ece15719",
"metadata": {
"cq.autogen": "top_imports"
},
"outputs": [],
"source": [
"from qualtran import Bloq, CompositeBloq, BloqBuilder, Signature, Register\n",
"from qualtran import QBit, QInt, QUInt, QAny\n",
"from qualtran.drawing import show_bloq, show_call_graph, show_counts_sigma\n",
"from typing import *\n",
"import numpy as np\n",
"import sympy\n",
"import cirq"
]
},
{
"cell_type": "markdown",
"id": "c187b17d",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.bloq_doc.md"
},
"source": [
"## `KikuchiNonZeroIndex`\n",
"Adjacency list oracle $O_F$ for the Kikuchi matrix.\n",
"\n",
"The oracle $O_F$ (Definition 4.5) takes in $i, k$,\n",
"and outputs $i, f(i, k)$ where $f(i, k)$ is\n",
"index of the $k$-th non-zero entry in row $i$.\n",
"\n",
"As the Kikuchi matrix is symmetric, we can use the same oracle for both rows and columns.\n",
"\n",
"The Kikuchi matrix is indexed by $S \\in {[n] \\choose k}$.\n",
"For a given row $S$ and column $T$, the entry $\\mathcal{K}_{k}_{S, T}$\n",
"is potentially non-zero if $S \\Delta T = U_j$ for some $j$, which is\n",
"equivalent to $T = S \\Delta U_j$.\n",
"Here, $U_j$ is the $j$-th unique scope in the instance $\\mathcal{I}$.\n",
"\n",
"To find the $k$-th non-zero entry, we use two oracles:\n",
"1. $(S, k) \\mapsto f(S, k)$, implemented by `ColumnOfKthNonZeroEntry`\n",
"2. $(S, f(S, k)) \\mapsto k$, implemented by `IndexOfNonZeroColumn`.\n",
"\n",
"Both these above oracles are unitary: they do not have any entangled ancilla/junk registers.\n",
"\n",
"\n",
"Note on sparsity: This bloq expects the user to provide the sparsity, as it is in general\n",
"difficult to compute the precise sparsity of the Kikuchi matrix efficiently. As long as the\n",
"provided number is at least the true sparsity, the algorithm will work as expected.\n",
"In case the provides sparsity is smaller, it is equivalent to making the remaining entries zero in the final block encoding.\n",
"\n",
"#### Parameters\n",
" - `inst`: the kXOR instance $\\mathcal{I}$.\n",
" - `ell`: Kikuchi parameter $\\ell$.\n",
" - `s`: sparsity, i.e. max number of non-zero entries in a row/column. \n",
"\n",
"#### Registers\n",
" - `i`: integer in [2^N]\n",
" - `k`: integer in [2^N] \n",
"\n",
"#### References\n",
" - [Quartic quantum speedups for planted inference](https://arxiv.org/abs/2406.19378v1). Theorem 4.17, proof para 4 (top of page 39).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d329e657",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.optimization.k_xor_sat import KikuchiNonZeroIndex"
]
},
{
"cell_type": "markdown",
"id": "8516f446",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "409ea009",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.kikuchi_nonzero_index"
},
"outputs": [],
"source": [
"from qualtran.bloqs.optimization.k_xor_sat.kxor_instance import example_kxor_instance\n",
"\n",
"inst = example_kxor_instance()\n",
"ell = 8\n",
"s = inst.brute_force_sparsity(ell)\n",
"\n",
"kikuchi_nonzero_index = KikuchiNonZeroIndex(inst, ell, s=s)"
]
},
{
"cell_type": "markdown",
"id": "c08eb466",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a7478a9a",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([kikuchi_nonzero_index],\n",
" ['`kikuchi_nonzero_index`'])"
]
},
{
"cell_type": "markdown",
"id": "2e07ff5a",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "138befd7",
"metadata": {
"cq.autogen": "KikuchiNonZeroIndex.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"kikuchi_nonzero_index_g, kikuchi_nonzero_index_sigma = kikuchi_nonzero_index.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(kikuchi_nonzero_index_g)\n",
"show_counts_sigma(kikuchi_nonzero_index_sigma)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading