Skip to content

Commit

Permalink
Merge branch 'main' into fix_zero_sized_registers
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujkhattar authored Jul 20, 2024
2 parents 650afab + b0d4840 commit 13a139d
Show file tree
Hide file tree
Showing 15 changed files with 421 additions and 177 deletions.
14 changes: 9 additions & 5 deletions dev_tools/autogenerate-bloqs-notebooks-v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,14 @@
bloq_specs=[qualtran.bloqs.basic_gates.cnot._CNOT_DOC],
),
NotebookSpecV2(
title='S Gate',
module=qualtran.bloqs.basic_gates.s_gate,
bloq_specs=[qualtran.bloqs.basic_gates.s_gate._S_GATE_DOC],
title='Z, S, and CZ',
module=qualtran.bloqs.basic_gates.z_basis,
path_stem='diag_gates',
bloq_specs=[
qualtran.bloqs.basic_gates.z_basis._Z_GATE_DOC,
qualtran.bloqs.basic_gates.s_gate._S_GATE_DOC,
qualtran.bloqs.basic_gates.z_basis._CZ_DOC,
],
),
NotebookSpecV2(
title='Y Gate',
Expand All @@ -167,6 +172,7 @@
NotebookSpecV2(
title='States and Effects',
module=qualtran.bloqs.basic_gates.z_basis,
path_stem='states_and_effects',
bloq_specs=[
qualtran.bloqs.basic_gates.z_basis._ZERO_STATE_DOC,
qualtran.bloqs.basic_gates.z_basis._ZERO_EFFECT_DOC,
Expand All @@ -179,8 +185,6 @@
qualtran.bloqs.basic_gates.x_basis._MINUS_STATE_DOC,
qualtran.bloqs.basic_gates.x_basis._MINUS_EFFECT_DOC,
],
directory=f'{SOURCE_DIR}/bloqs/basic_gates',
path_stem='states_and_effects',
),
NotebookSpecV2(
title='Swap Network',
Expand Down
2 changes: 1 addition & 1 deletion docs/bloqs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Bloqs Library
basic_gates/toffoli.ipynb
basic_gates/hadamard.ipynb
basic_gates/cnot.ipynb
basic_gates/s_gate.ipynb
basic_gates/diag_gates.ipynb
basic_gates/y_gate.ipynb
mcmt/and_bloq.ipynb
basic_gates/states_and_effects.ipynb
Expand Down
2 changes: 1 addition & 1 deletion qualtran/bloqs/basic_gates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
from .toffoli import Toffoli
from .x_basis import MinusEffect, MinusState, PlusEffect, PlusState, XGate
from .y_gate import CYGate, YGate
from .z_basis import IntEffect, IntState, OneEffect, OneState, ZeroEffect, ZeroState, ZGate
from .z_basis import CZ, IntEffect, IntState, OneEffect, OneState, ZeroEffect, ZeroState, ZGate
279 changes: 279 additions & 0 deletions qualtran/bloqs/basic_gates/diag_gates.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "82ad144d",
"metadata": {
"cq.autogen": "title_cell"
},
"source": [
"# Z, S, and CZ"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfaec0e3",
"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": "aebd73ef",
"metadata": {
"cq.autogen": "ZGate.bloq_doc.md"
},
"source": [
"## `ZGate`\n",
"The Z gate.\n",
"\n",
"This causes a phase flip: Z|+> = |-> and vice-versa."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5a50dd9b",
"metadata": {
"cq.autogen": "ZGate.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import ZGate"
]
},
{
"cell_type": "markdown",
"id": "4bf0966c",
"metadata": {
"cq.autogen": "ZGate.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f1df6149",
"metadata": {
"cq.autogen": "ZGate.zgate"
},
"outputs": [],
"source": [
"zgate = ZGate()"
]
},
{
"cell_type": "markdown",
"id": "69313d0e",
"metadata": {
"cq.autogen": "ZGate.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f386e781",
"metadata": {
"cq.autogen": "ZGate.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([zgate],\n",
" ['`zgate`'])"
]
},
{
"cell_type": "markdown",
"id": "b735f98a",
"metadata": {
"cq.autogen": "SGate.bloq_doc.md"
},
"source": [
"## `SGate`\n",
"The S gate.\n",
"\n",
"The unitary matrix of `SGate` is\n",
"$$\n",
"\\begin{bmatrix}\n",
" 1 & 0 \\\\\n",
" 0 & i\n",
"\\end{bmatrix}\n",
"$$\n",
"\n",
"It is the 'square root' of the Z gate: $S\\cdot S = Z$.\n",
"\n",
"#### Registers\n",
" - `q`: The qubit\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "232eb559",
"metadata": {
"cq.autogen": "SGate.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import SGate"
]
},
{
"cell_type": "markdown",
"id": "8313afa6",
"metadata": {
"cq.autogen": "SGate.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "52c54793",
"metadata": {
"cq.autogen": "SGate.s_gate"
},
"outputs": [],
"source": [
"s_gate = SGate()"
]
},
{
"cell_type": "markdown",
"id": "70d66060",
"metadata": {
"cq.autogen": "SGate.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a4405a00",
"metadata": {
"cq.autogen": "SGate.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([s_gate],\n",
" ['`s_gate`'])"
]
},
{
"cell_type": "markdown",
"id": "b4474ada",
"metadata": {
"cq.autogen": "CZ.bloq_doc.md"
},
"source": [
"## `CZ`\n",
"Two-qubit controlled-Z gate.\n",
"\n",
"#### Registers\n",
" - `ctrl`: One-bit control register.\n",
" - `target`: One-bit target register.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81108e72",
"metadata": {
"cq.autogen": "CZ.bloq_doc.py"
},
"outputs": [],
"source": [
"from qualtran.bloqs.basic_gates import CZ"
]
},
{
"cell_type": "markdown",
"id": "053ef676",
"metadata": {
"cq.autogen": "CZ.example_instances.md"
},
"source": [
"### Example Instances"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f233e08",
"metadata": {
"cq.autogen": "CZ.cz"
},
"outputs": [],
"source": [
"cz = CZ()"
]
},
{
"cell_type": "markdown",
"id": "ba4f9ff9",
"metadata": {
"cq.autogen": "CZ.graphical_signature.md"
},
"source": [
"#### Graphical Signature"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "db97bbab",
"metadata": {
"cq.autogen": "CZ.graphical_signature.py"
},
"outputs": [],
"source": [
"from qualtran.drawing import show_bloqs\n",
"show_bloqs([cz],\n",
" ['`cz`'])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion qualtran/bloqs/basic_gates/hadamard.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
"\n",
"#### Registers\n",
" - `ctrl`: The control qubit.\n",
" - `q`: The target qubit.\n"
" - `target`: The target qubit.\n"
]
},
{
Expand Down
Loading

0 comments on commit 13a139d

Please sign in to comment.