Skip to content
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

Bloqs for one hot encoding #1508

Open
wants to merge 2 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
9 changes: 9 additions & 0 deletions dev_tools/qualtran_dev_tools/notebook_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
import qualtran.bloqs.state_preparation.state_preparation_via_rotation
import qualtran.bloqs.swap_network.cswap_approx
import qualtran.bloqs.swap_network.multiplexed_cswap
import qualtran.bloqs.swap_network.one_hot_encoding
import qualtran.bloqs.swap_network.swap_with_zero

from .jupyter_autogen import NotebookSpecV2
Expand Down Expand Up @@ -224,6 +225,14 @@
qualtran.bloqs.swap_network.multiplexed_cswap._MULTIPLEXED_CSWAP_DOC,
],
),
NotebookSpecV2(
title='One Hot Encodings',
module=qualtran.bloqs.swap_network.one_hot_encoding,
bloq_specs=[
qualtran.bloqs.swap_network.one_hot_encoding._ONE_HOT_LOG_DEPTH_DOC,
qualtran.bloqs.swap_network.one_hot_encoding._ONE_HOT_LINEAR_DEPTH_DOC,
],
),
NotebookSpecV2(
title='Global Phase',
module=qualtran.bloqs.basic_gates.global_phase,
Expand Down
1 change: 1 addition & 0 deletions docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Bloqs Library
basic_gates/states_and_effects.ipynb
basic_gates/swap.ipynb
swap_network/swap_network.ipynb
swap_network/one_hot_encoding.ipynb
basic_gates/global_phase.ipynb
basic_gates/identity.ipynb
bookkeeping/bookkeeping.ipynb
Expand Down
236 changes: 236 additions & 0 deletions qualtran/bloqs/swap_network/one_hot_encoding.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "fc2b66f2",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# One Hot Encodings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fe93874",
"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": "cf33d078",
"metadata": {
"cq.autogen": "OneHotLogDepth.bloq_doc.md"
},
"source": [
"## `OneHotLogDepth`\n",
"Log depth one hot encoding using N - 1 CSWAPs."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d873a11f",
"metadata": {
"cq.autogen": "OneHotLogDepth.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.swap_network import OneHotLogDepth"
]
},
{
"cell_type": "markdown",
"id": "ddd4c000",
"metadata": {
"cq.autogen": "OneHotLogDepth.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bd0a15fa",
"metadata": {
"cq.autogen": "OneHotLogDepth.one_hot_log_depth"
},
"outputs": [],
"source": [
"from qualtran import BQUInt\n",
"\n",
"one_hot_log_depth = OneHotLogDepth(BQUInt(4, 14))"
]
},
{
"cell_type": "markdown",
"id": "6d5915cb",
"metadata": {
"cq.autogen": "OneHotLogDepth.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4b05b47",
"metadata": {
"cq.autogen": "OneHotLogDepth.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([one_hot_log_depth],\n",
" ['`one_hot_log_depth`'])"
]
},
{
"cell_type": "markdown",
"id": "05b1373f",
"metadata": {
"cq.autogen": "OneHotLogDepth.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7973a854",
"metadata": {
"cq.autogen": "OneHotLogDepth.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"one_hot_log_depth_g, one_hot_log_depth_sigma = one_hot_log_depth.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(one_hot_log_depth_g)\n",
"show_counts_sigma(one_hot_log_depth_sigma)"
]
},
{
"cell_type": "markdown",
"id": "f440d529",
"metadata": {
"cq.autogen": "OneHotLinearDepth.bloq_doc.md"
},
"source": [
"## `OneHotLinearDepth`\n",
"Linear depth one hot encoding using N - 1 CSWAPs."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "916169e5",
"metadata": {
"cq.autogen": "OneHotLinearDepth.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.swap_network import OneHotLinearDepth"
]
},
{
"cell_type": "markdown",
"id": "d0647430",
"metadata": {
"cq.autogen": "OneHotLinearDepth.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "68bd4068",
"metadata": {
"cq.autogen": "OneHotLinearDepth.one_hot_linear_depth"
},
"outputs": [],
"source": [
"from qualtran import BQUInt\n",
"\n",
"one_hot_linear_depth = OneHotLinearDepth(BQUInt(4, 14))"
]
},
{
"cell_type": "markdown",
"id": "dde49844",
"metadata": {
"cq.autogen": "OneHotLinearDepth.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9440730a",
"metadata": {
"cq.autogen": "OneHotLinearDepth.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([one_hot_linear_depth],\n",
" ['`one_hot_linear_depth`'])"
]
},
{
"cell_type": "markdown",
"id": "47ab8e36",
"metadata": {
"cq.autogen": "OneHotLinearDepth.call_graph.md"
},
"source": [
"### Call Graph"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96546b81",
"metadata": {
"cq.autogen": "OneHotLinearDepth.call_graph.py"
},
"outputs": [],
"source": [
"from qualtran.resource_counting.generalizers import ignore_split_join\n",
"one_hot_linear_depth_g, one_hot_linear_depth_sigma = one_hot_linear_depth.call_graph(max_depth=1, generalizer=ignore_split_join)\n",
"show_call_graph(one_hot_linear_depth_g)\n",
"show_counts_sigma(one_hot_linear_depth_sigma)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading