diff --git a/notebooks/logical_qubit_extended_memory_experiment.ipynb b/notebooks/logical_qubit_extended_memory_experiment.ipynb index d1d197fc..8cb21eb3 100644 --- a/notebooks/logical_qubit_extended_memory_experiment.ipynb +++ b/notebooks/logical_qubit_extended_memory_experiment.ipynb @@ -8,14 +8,14 @@ "\n", "This notebook aims at performing a memory experiment on an extended logical qubit (see image below).\n", "\n", - "![A logical qubit that has been extended horizontally by 2 plaquettes](./images/extended_logical_qubit.png)" + "![A logical qubit that has been extended horizontally by 2 plaquettes](./images/extended_logical_qubit.png)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Mandatory imports" + "## Mandatory imports\n" ] }, { @@ -43,14 +43,14 @@ ")\n", "from tqec.plaquette.plaquette import Plaquette\n", "from tqec.plaquette.library import (\n", - " ZSquareInitialisationPlaquette,\n", - " ZRoundedInitialisationPlaquette,\n", - " XXMemoryPlaquette,\n", - " XXXXMemoryPlaquette,\n", - " ZZMemoryPlaquette,\n", - " ZZZZMemoryPlaquette,\n", - " MeasurementRoundedPlaquette,\n", - " MeasurementSquarePlaquette,\n", + " z_initialisation_square_plaquette,\n", + " z_initialisation_rounded_plaquette,\n", + " xx_memory_plaquette,\n", + " xxxx_memory_plaquette,\n", + " zz_memory_plaquette,\n", + " zzzz_memory_plaquette,\n", + " measurement_rounded_plaquette,\n", + " measurement_square_plaquette,\n", ")\n", "from tqec.templates.display import display_template" ] @@ -65,7 +65,7 @@ "\n", "The first pass normalises the `cirq.Circuit` produced. This pass was performing several modifications before, but is now simply removing potential empty `cirq.Moment` instances from the `cirq.Circuit` instance.\n", "\n", - "The second pass applies the noise model(s) we want to consider in the `stim` simulation." + "The second pass applies the noise model(s) we want to consider in the `stim` simulation.\n" ] }, { @@ -102,7 +102,7 @@ "\n", "The main goal of the `tqec` library is to construct the `cirq.Circuit` instance representing the QEC experiment we are interested in. In this notebook, we want to perform a memory experiment on an \"extended\" logical qubit.\n", "\n", - "The different pre-defined Plaquette instances `XXPlaquetteList`, ... implement by default the memory experiment, so we can use them without worrying about the quantum circuits actually executed." + "The different pre-defined Plaquette instances `XXPlaquetteList`, ... implement by default the memory experiment, so we can use them without worrying about the quantum circuits actually executed.\n" ] }, { @@ -144,58 +144,58 @@ " # - Measurement index is 8\n", " plaquettes: list[list[Plaquette]] = [\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.UP),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.UP,\n", " [1, 2, 5, 6, 7, 8],\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, [1, 2, 5, 6, 7, 8]),\n", - " MeasurementRoundedPlaquette(\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, [1, 2, 5, 6, 7, 8]),\n", + " measurement_rounded_plaquette(\n", " PlaquetteOrientation.UP, include_detector=False\n", " ),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.LEFT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.LEFT, [1, 5, 6, 8], is_first_round=True\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, [1, 5, 6, 8]),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, [1, 5, 6, 8]),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.LEFT),\n", " ],\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " XXXXMemoryPlaquette(\n", + " z_initialisation_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", " [1, 2, 3, 4, 5, 6, 7, 8], include_detector=False, is_first_round=True\n", " ),\n", - " XXXXMemoryPlaquette([1, 2, 3, 4, 5, 6, 7, 8]),\n", - " MeasurementSquarePlaquette(include_detector=False),\n", + " xxxx_memory_plaquette([1, 2, 3, 4, 5, 6, 7, 8]),\n", + " measurement_square_plaquette(include_detector=False),\n", " ],\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " ZZZZMemoryPlaquette([1, 3, 4, 5, 6, 8], is_first_round=True),\n", - " ZZZZMemoryPlaquette([1, 3, 4, 5, 6, 8]),\n", - " MeasurementSquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " zzzz_memory_plaquette([1, 3, 4, 5, 6, 8], is_first_round=True),\n", + " zzzz_memory_plaquette([1, 3, 4, 5, 6, 8]),\n", + " measurement_square_plaquette(),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.RIGHT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.RIGHT, [1, 3, 4, 8], is_first_round=True\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.RIGHT, [1, 3, 4, 8]),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(PlaquetteOrientation.RIGHT, [1, 3, 4, 8]),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.DOWN),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.DOWN,\n", " [1, 2, 3, 4, 7, 8],\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, [1, 2, 3, 4, 7, 8]),\n", - " MeasurementRoundedPlaquette(\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, [1, 2, 3, 4, 7, 8]),\n", + " measurement_rounded_plaquette(\n", " PlaquetteOrientation.DOWN, include_detector=False\n", " ),\n", " ],\n", @@ -262,7 +262,7 @@ "\n", "In order to perform the experiement and to compute the error threshold for such an experiment, we need to be able to vary the noise applied to our circuit. Also, we would like to only have one input that controls both the width and the height, to be able to vary only that input.\n", "\n", - "The following function builds a template that is twice as large horizontally than vertically and applies the provided noise level to the whole circuit before translating the circuit to `Stim`." + "The following function builds a template that is twice as large horizontally than vertically and applies the provided noise level to the whole circuit before translating the circuit to `Stim`.\n" ] }, { @@ -292,7 +292,7 @@ "source": [ "## TQEC plots\n", "\n", - "We should finally be ready to perform the `stim` simulations and plot the results of our `tqec`-generated QEC memory experiment." + "We should finally be ready to perform the `stim` simulations and plot the results of our `tqec`-generated QEC memory experiment.\n" ] }, { @@ -350,7 +350,7 @@ "source": [ "## Circuit visualisation\n", "\n", - "Some debugging relicates that are left here if you want to visualise/compare the quantum circuits generated." + "Some debugging relicates that are left here if you want to visualise/compare the quantum circuits generated.\n" ] }, { @@ -380,7 +380,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.0" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/notebooks/logical_qubit_memory_experiment.ipynb b/notebooks/logical_qubit_memory_experiment.ipynb index 20be2bfc..6beae91b 100644 --- a/notebooks/logical_qubit_memory_experiment.ipynb +++ b/notebooks/logical_qubit_memory_experiment.ipynb @@ -6,14 +6,14 @@ "source": [ "# Memory experiment replication\n", "\n", - "This notebook aims at replicating the results from the memory experiment already implemented in `stim`. It serves as an example on how to use the `tqec` Python library as well as a large functional test, testing most of the `tqec` library on its external results rather than on its internal implementation." + "This notebook aims at replicating the results from the memory experiment already implemented in `stim`. It serves as an example on how to use the `tqec` Python library as well as a large functional test, testing most of the `tqec` library on its external results rather than on its internal implementation.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Mandatory imports" + "## Mandatory imports\n" ] }, { @@ -41,14 +41,14 @@ ")\n", "from tqec.plaquette.plaquette import Plaquette\n", "from tqec.plaquette.library import (\n", - " ZSquareInitialisationPlaquette,\n", - " ZRoundedInitialisationPlaquette,\n", - " XXMemoryPlaquette,\n", - " XXXXMemoryPlaquette,\n", - " ZZMemoryPlaquette,\n", - " ZZZZMemoryPlaquette,\n", - " MeasurementSquarePlaquette,\n", - " MeasurementRoundedPlaquette,\n", + " z_initialisation_square_plaquette,\n", + " z_initialisation_rounded_plaquette,\n", + " xx_memory_plaquette,\n", + " xxxx_memory_plaquette,\n", + " zz_memory_plaquette,\n", + " zzzz_memory_plaquette,\n", + " measurement_rounded_plaquette,\n", + " measurement_square_plaquette,\n", ")" ] }, @@ -62,7 +62,7 @@ "\n", "The first pass normalises the `cirq.Circuit` produced. This pass was performing several modifications before, but is now simply removing potential empty `cirq.Moment` instances from the `cirq.Circuit` instance.\n", "\n", - "The second pass applies the noise model(s) we want to consider in the `stim` simulation." + "The second pass applies the noise model(s) we want to consider in the `stim` simulation.\n" ] }, { @@ -99,7 +99,7 @@ "\n", "The main goal of the `tqec` library is to construct the `cirq.Circuit` instance representing the QEC experiment we are interest about. In this notebook, we want to perform a simple logical qubit memory experiment.\n", "\n", - "The different pre-defined Plaquette instances `XXPlaquetteList`, ... implement by default the memory experiment, so we can use them without worrying about the quantum circuits actually executed." + "The different pre-defined Plaquette instances `XXPlaquetteList`, ... implement by default the memory experiment, so we can use them without worrying about the quantum circuits actually executed.\n" ] }, { @@ -126,58 +126,58 @@ " # - Measurement index is 8\n", " plaquettes: list[list[Plaquette]] = [\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.UP),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.UP,\n", " [1, 2, 5, 6, 7, 8],\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, [1, 2, 5, 6, 7, 8]),\n", - " MeasurementRoundedPlaquette(\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, [1, 2, 5, 6, 7, 8]),\n", + " measurement_rounded_plaquette(\n", " PlaquetteOrientation.UP, include_detector=False\n", " ),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.LEFT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.LEFT, [1, 5, 6, 8], is_first_round=True\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, [1, 5, 6, 8]),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, [1, 5, 6, 8]),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.LEFT),\n", " ],\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " XXXXMemoryPlaquette(\n", + " z_initialisation_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", " [1, 2, 3, 4, 5, 6, 7, 8], include_detector=False, is_first_round=True\n", " ),\n", - " XXXXMemoryPlaquette([1, 2, 3, 4, 5, 6, 7, 8]),\n", - " MeasurementSquarePlaquette(include_detector=False),\n", + " xxxx_memory_plaquette([1, 2, 3, 4, 5, 6, 7, 8]),\n", + " measurement_square_plaquette(include_detector=False),\n", " ],\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " ZZZZMemoryPlaquette([1, 3, 4, 5, 6, 8], is_first_round=True),\n", - " ZZZZMemoryPlaquette([1, 3, 4, 5, 6, 8]),\n", - " MeasurementSquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " zzzz_memory_plaquette([1, 3, 4, 5, 6, 8], is_first_round=True),\n", + " zzzz_memory_plaquette([1, 3, 4, 5, 6, 8]),\n", + " measurement_square_plaquette(),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.RIGHT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.RIGHT, [1, 3, 4, 8], is_first_round=True\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.RIGHT, [1, 3, 4, 8]),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(PlaquetteOrientation.RIGHT, [1, 3, 4, 8]),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", " ],\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.DOWN),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.DOWN,\n", " [1, 2, 3, 4, 7, 8],\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, [1, 2, 3, 4, 7, 8]),\n", - " MeasurementRoundedPlaquette(\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, [1, 2, 3, 4, 7, 8]),\n", + " measurement_rounded_plaquette(\n", " PlaquetteOrientation.DOWN, include_detector=False\n", " ),\n", " ],\n", @@ -242,7 +242,7 @@ "source": [ "## Normalise the API between `stim` and `tqec`\n", "\n", - "Both libraries have slight variations in their API that makes their side-by-side use error-prone. To avoid typos and inattention issues, we create 2 functions with the same API that take care of handling the small discrepencies for us." + "Both libraries have slight variations in their API that makes their side-by-side use error-prone. To avoid typos and inattention issues, we create 2 functions with the same API that take care of handling the small discrepencies for us.\n" ] }, { @@ -291,7 +291,7 @@ "source": [ "## TQEC plots\n", "\n", - "We should finally be ready to perform the `stim` simulations and plot the results to check if our `tqec`-generated QEC memory experiment obtains the same results as the `stim`-generated one." + "We should finally be ready to perform the `stim` simulations and plot the results to check if our `tqec`-generated QEC memory experiment obtains the same results as the `stim`-generated one.\n" ] }, { @@ -347,7 +347,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Stim plots" + "## Stim plots\n" ] }, { @@ -405,7 +405,7 @@ "source": [ "## Circuit visualisation\n", "\n", - "Some debugging relicates that are left here if you want to visualise/compare the quantum circuits generated." + "Some debugging relicates that are left here if you want to visualise/compare the quantum circuits generated.\n" ] }, { @@ -453,7 +453,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.0" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/notebooks/move_qubit_along_a_line.ipynb b/notebooks/move_qubit_along_a_line.ipynb index 449428dd..729e4c9e 100644 --- a/notebooks/move_qubit_along_a_line.ipynb +++ b/notebooks/move_qubit_along_a_line.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Move qubit along a line" + "# Move qubit along a line\n" ] }, { @@ -15,7 +15,7 @@ } }, "source": [ - "This notebook aims at moving a logical qubit along a line during the logical memory experiment, \n", + "This notebook aims at moving a logical qubit along a line during the logical memory experiment,\n", "which is depicted in the following figure:\n", "\n", "![Move logical qubit along a line](./images/move_qubit_along_a_line/move_qubit_along_z.png)\n", @@ -28,14 +28,14 @@ "\n", "The above steps will take $3d$ rounds in total. We will compare the logical Z(X) error rate of the above experiment with the logical Z(X) error rate of the standard static logical memory experiment. If the implementation is correct, the logical Z(X) error rate of the above experiment should be at least as good as the logical Z(X) error rate of the standard static logical memory experiment.\n", "\n", - "> In principle, we should be able to move the qubit for any long distance. However, I found making the move distance generic pose great difficulty in the implementation. Specifically, the overlap between the original qubit and the moved qubit varies with the move distance and code distance, which makes it difficult to build the generic templates. Therefore, we will only consider the case where **the move distance is equal to $d-1$** in this notebook." + "> In principle, we should be able to move the qubit for any long distance. However, I found making the move distance generic pose great difficulty in the implementation. Specifically, the overlap between the original qubit and the moved qubit varies with the move distance and code distance, which makes it difficult to build the generic templates. Therefore, we will only consider the case where **the move distance is equal to $d-1$** in this notebook.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Imports" + "## Imports\n" ] }, { @@ -74,16 +74,16 @@ " BeforeMeasurementFlipNoise,\n", ")\n", "from tqec.plaquette.library import (\n", - " ZSquareInitialisationPlaquette,\n", - " ZRoundedInitialisationPlaquette,\n", - " XXMemoryPlaquette,\n", - " XXXXMemoryPlaquette,\n", - " ZZMemoryPlaquette,\n", - " ZZZZMemoryPlaquette,\n", - " EmptySquarePlaquette,\n", - " EmptyRoundedPlaquette,\n", - " MeasurementSquarePlaquette,\n", - " MeasurementRoundedPlaquette,\n", + " z_initialisation_square_plaquette,\n", + " z_initialisation_rounded_plaquette,\n", + " xx_memory_plaquette,\n", + " xxxx_memory_plaquette,\n", + " zz_memory_plaquette,\n", + " zzzz_memory_plaquette,\n", + " empty_square_plaquette,\n", + " empty_rounded_plaquette,\n", + " measurement_rounded_plaquette,\n", + " measurement_square_plaquette,\n", ")\n", "from tqec.templates.display import display_template" ] @@ -98,7 +98,7 @@ "\n", "The first pass normalises the `cirq.Circuit` produced. This pass was performing several modifications before, but is now simply removing potential empty `cirq.Moment` instances from the `cirq.Circuit` instance.\n", "\n", - "The second pass applies the noise model(s) we want to consider in the `stim` simulation." + "The second pass applies the noise model(s) we want to consider in the `stim` simulation.\n" ] }, { @@ -142,7 +142,7 @@ "\n", "What we want to build is as follows:\n", "\n", - "![Built template](./images/move_qubit_along_a_line/built_templates.png)" + "![Built template](./images/move_qubit_along_a_line/built_templates.png)\n" ] }, { @@ -261,7 +261,7 @@ "6. Do logical memory circuits for $d-1$ rounds\n", "7. Measure the destination qubit\n", "\n", - "We then build the plaquettes according to the layers." + "We then build the plaquettes according to the layers.\n" ] }, { @@ -285,187 +285,197 @@ "PLAQUETTES = [\n", " # 1\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx, include_detector=False, is_first_round=True),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " MeasurementSquarePlaquette(include_detector=False),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", + " schedule_xxxx, include_detector=False, is_first_round=True\n", + " ),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " measurement_square_plaquette(include_detector=False),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", " ],\n", " # 2\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " ZZZZMemoryPlaquette(schedule_zzzz, is_first_round=True),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " MeasurementSquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " zzzz_memory_plaquette(schedule_zzzz, is_first_round=True),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " measurement_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", " ],\n", " # 3\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " ZZZZMemoryPlaquette(schedule_zzzz, is_first_round=True),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " EmptySquarePlaquette(),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.LEFT),\n", + " z_initialisation_square_plaquette(),\n", + " zzzz_memory_plaquette(schedule_zzzz, is_first_round=True),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " empty_square_plaquette(),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.LEFT),\n", " ],\n", " # 4\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx, include_detector=False, is_first_round=True),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", + " schedule_xxxx, include_detector=False, is_first_round=True\n", + " ),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", " ],\n", " # 5\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.UP),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.UP,\n", " schedule_xx_up,\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", " ],\n", " # 6\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.DOWN),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.DOWN,\n", " schedule_xx_down,\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", " ],\n", " # 7\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.LEFT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.LEFT,\n", " schedule_zz_left,\n", " is_first_round=True,\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.LEFT),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.LEFT),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.LEFT),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", + " zz_memory_plaquette(PlaquetteOrientation.LEFT, schedule_zz_left),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.LEFT),\n", + " empty_rounded_plaquette(PlaquetteOrientation.LEFT),\n", + " empty_rounded_plaquette(PlaquetteOrientation.LEFT),\n", " ],\n", " # 8\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx, include_detector=False, is_first_round=True),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " EmptySquarePlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " MeasurementSquarePlaquette(include_detector=False),\n", + " z_initialisation_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", + " schedule_xxxx, include_detector=False, is_first_round=True\n", + " ),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " empty_square_plaquette(),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " measurement_square_plaquette(include_detector=False),\n", " ],\n", " # 9\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", - " ZZZZMemoryPlaquette(schedule_zzzz, is_first_round=True),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " EmptySquarePlaquette(),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " MeasurementSquarePlaquette(),\n", + " z_initialisation_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " zzzz_memory_plaquette(schedule_zzzz, is_first_round=True),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " empty_square_plaquette(),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " measurement_square_plaquette(),\n", " ],\n", " # 10\n", " [\n", - " ZSquareInitialisationPlaquette(),\n", - " EmptySquarePlaquette(),\n", - " EmptySquarePlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx, include_detector=False, is_first_round=True),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " EmptySquarePlaquette(),\n", - " XXXXMemoryPlaquette(schedule_xxxx),\n", - " MeasurementSquarePlaquette(include_detector=False),\n", + " z_initialisation_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " empty_square_plaquette(),\n", + " xxxx_memory_plaquette(\n", + " schedule_xxxx, include_detector=False, is_first_round=True\n", + " ),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " empty_square_plaquette(),\n", + " xxxx_memory_plaquette(schedule_xxxx),\n", + " measurement_square_plaquette(include_detector=False),\n", " ],\n", " # 11\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.RIGHT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.RIGHT, schedule_zz_right, is_first_round=True\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " EmptySquarePlaquette(),\n", - " ZZZZMemoryPlaquette(schedule_zzzz),\n", - " MeasurementSquarePlaquette(),\n", + " zz_memory_plaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " empty_square_plaquette(),\n", + " zzzz_memory_plaquette(schedule_zzzz),\n", + " measurement_square_plaquette(),\n", " ],\n", " # 12\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.UP),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.UP),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.UP,\n", " schedule_xx_up,\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.UP),\n", - " XXMemoryPlaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.UP, include_detector=False),\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", + " empty_rounded_plaquette(PlaquetteOrientation.UP),\n", + " xx_memory_plaquette(PlaquetteOrientation.UP, schedule_xx_up),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.UP, include_detector=False),\n", " ],\n", " # 13\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.DOWN),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", - " XXMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(\n", " PlaquetteOrientation.DOWN,\n", " schedule_xx_down,\n", " include_detector=False,\n", " is_first_round=True,\n", " ),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.DOWN),\n", - " XXMemoryPlaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.DOWN, include_detector=False),\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", + " empty_rounded_plaquette(PlaquetteOrientation.DOWN),\n", + " xx_memory_plaquette(PlaquetteOrientation.DOWN, schedule_xx_down),\n", + " measurement_rounded_plaquette(\n", + " PlaquetteOrientation.DOWN, include_detector=False\n", + " ),\n", " ],\n", " # 14\n", " [\n", - " ZRoundedInitialisationPlaquette(PlaquetteOrientation.RIGHT),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", - " ZZMemoryPlaquette(\n", + " z_initialisation_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " empty_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " empty_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(\n", " PlaquetteOrientation.RIGHT,\n", " schedule_zz_right,\n", " is_first_round=True,\n", " ),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", - " EmptyRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", - " ZZMemoryPlaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", - " MeasurementRoundedPlaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", + " empty_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", + " zz_memory_plaquette(PlaquetteOrientation.RIGHT, schedule_zz_right),\n", + " measurement_rounded_plaquette(PlaquetteOrientation.RIGHT),\n", " ],\n", "]" ] @@ -474,7 +484,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Build the circuit" + "## Build the circuit\n" ] }, { @@ -599,7 +609,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Simulation" + "## Simulation\n" ] }, { @@ -678,7 +688,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.0" + "version": "3.12.2" } }, "nbformat": 4, diff --git a/src/tqec/circuit/circuit_test.py b/src/tqec/circuit/circuit_test.py index ee70ed6e..48ce5259 100644 --- a/src/tqec/circuit/circuit_test.py +++ b/src/tqec/circuit/circuit_test.py @@ -3,7 +3,7 @@ from tqec.circuit.circuit import generate_circuit from tqec.exceptions import TQECException -from tqec.plaquette.library import ZSquareInitialisationPlaquette +from tqec.plaquette.library import z_initialisation_square_plaquette from tqec.plaquette.plaquette import Plaquette from tqec.templates.atomic.rectangle import RawRectangleTemplate from tqec.templates.base import Template @@ -11,7 +11,7 @@ @pytest.fixture def initialisation_plaquette() -> Plaquette: - return ZSquareInitialisationPlaquette() + return z_initialisation_square_plaquette() @pytest.fixture diff --git a/src/tqec/plaquette/library/__init__.py b/src/tqec/plaquette/library/__init__.py index 7f303673..909fe8e0 100644 --- a/src/tqec/plaquette/library/__init__.py +++ b/src/tqec/plaquette/library/__init__.py @@ -1,12 +1,22 @@ -from .empty import EmptyRoundedPlaquette, EmptySquarePlaquette +from .empty import ( + empty_plaquette, + empty_rounded_plaquette, + empty_square_plaquette, +) from .initialisation import ( - XRoundedInitialisationPlaquette, - XSquareInitialisationPlaquette, - ZRoundedInitialisationPlaquette, - ZSquareInitialisationPlaquette, + x_initialisation_plaquette, + x_initialisation_rounded_plaquette, + x_initialisation_square_plaquette, + z_initialisation_plaquette, + z_initialisation_rounded_plaquette, + z_initialisation_square_plaquette, +) +from .measurement import ( + measurement_plaquette, + measurement_rounded_plaquette, + measurement_square_plaquette, ) -from .measurement import MeasurementRoundedPlaquette, MeasurementSquarePlaquette -from .xx import XXMemoryPlaquette -from .xxxx import XXXXMemoryPlaquette -from .zz import ZZMemoryPlaquette -from .zzzz import ZZZZMemoryPlaquette +from .xx import xx_memory_plaquette +from .xxxx import xxxx_memory_plaquette +from .zz import zz_memory_plaquette +from .zzzz import zzzz_memory_plaquette diff --git a/src/tqec/plaquette/library/empty.py b/src/tqec/plaquette/library/empty.py index b7aef961..d905ca14 100644 --- a/src/tqec/plaquette/library/empty.py +++ b/src/tqec/plaquette/library/empty.py @@ -10,16 +10,13 @@ ) -class EmptyPlaquette(Plaquette): - def __init__(self, qubits: PlaquetteQubits) -> None: - super().__init__(qubits, ScheduledCircuit(cirq.Circuit())) +def empty_plaquette(qubits: PlaquetteQubits) -> Plaquette: + return Plaquette(qubits, ScheduledCircuit(cirq.Circuit())) -class EmptySquarePlaquette(EmptyPlaquette): - def __init__(self) -> None: - super().__init__(SquarePlaquetteQubits()) +def empty_square_plaquette() -> Plaquette: + return empty_plaquette(SquarePlaquetteQubits()) -class EmptyRoundedPlaquette(EmptyPlaquette): - def __init__(self, orientation: PlaquetteOrientation) -> None: - super().__init__(RoundedPlaquetteQubits(orientation)) +def empty_rounded_plaquette(orientation: PlaquetteOrientation) -> Plaquette: + return empty_plaquette(RoundedPlaquetteQubits(orientation)) diff --git a/src/tqec/plaquette/library/initialisation.py b/src/tqec/plaquette/library/initialisation.py index 43fb78a6..b9d5824b 100644 --- a/src/tqec/plaquette/library/initialisation.py +++ b/src/tqec/plaquette/library/initialisation.py @@ -12,38 +12,32 @@ ) -class ZInitialisationPlaquette(Plaquette): - def __init__(self, qubits: PlaquetteQubits) -> None: - circuit = cirq.Circuit( - cirq.R(q).with_tags(self._MERGEABLE_TAG) for q in qubits.to_grid_qubit() - ) - super().__init__(qubits, ScheduledCircuit(circuit)) +def z_initialisation_plaquette(qubits: PlaquetteQubits) -> Plaquette: + circuit = cirq.Circuit( + cirq.R(q).with_tags(Plaquette._MERGEABLE_TAG) for q in qubits.to_grid_qubit() + ) + return Plaquette(qubits, ScheduledCircuit(circuit)) -class ZSquareInitialisationPlaquette(ZInitialisationPlaquette): - def __init__(self) -> None: - super().__init__(SquarePlaquetteQubits()) +def z_initialisation_square_plaquette() -> Plaquette: + return z_initialisation_plaquette(SquarePlaquetteQubits()) -class ZRoundedInitialisationPlaquette(ZInitialisationPlaquette): - def __init__(self, orientation: PlaquetteOrientation) -> None: - super().__init__(RoundedPlaquetteQubits(orientation)) +def z_initialisation_rounded_plaquette(orientation: PlaquetteOrientation) -> Plaquette: + return z_initialisation_plaquette(RoundedPlaquetteQubits(orientation)) -class XInitialisationPlaquette(Plaquette): - def __init__(self, qubits: PlaquetteQubits) -> None: - circuit = cirq.Circuit( - (cirq.R(q).with_tags(self._MERGEABLE_TAG), cirq.H(q)) - for q in qubits.to_grid_qubit() - ) - super().__init__(qubits, ScheduledCircuit(circuit)) +def x_initialisation_plaquette(qubits: PlaquetteQubits) -> Plaquette: + circuit = cirq.Circuit( + (cirq.R(q).with_tags(Plaquette._MERGEABLE_TAG), cirq.H(q)) + for q in qubits.to_grid_qubit() + ) + return Plaquette(qubits, ScheduledCircuit(circuit)) -class XSquareInitialisationPlaquette(XInitialisationPlaquette): - def __init__(self) -> None: - super().__init__(SquarePlaquetteQubits()) +def x_initialisation_square_plaquette() -> Plaquette: + return x_initialisation_plaquette(SquarePlaquetteQubits()) -class XRoundedInitialisationPlaquette(XInitialisationPlaquette): - def __init__(self, orientation: PlaquetteOrientation) -> None: - super().__init__(RoundedPlaquetteQubits(orientation)) +def x_initialisation_rounded_plaquette(orientation: PlaquetteOrientation) -> Plaquette: + return x_initialisation_plaquette(RoundedPlaquetteQubits(orientation)) diff --git a/src/tqec/plaquette/library/measurement.py b/src/tqec/plaquette/library/measurement.py index 0f781509..0b840772 100644 --- a/src/tqec/plaquette/library/measurement.py +++ b/src/tqec/plaquette/library/measurement.py @@ -11,38 +11,37 @@ ) -class MeasurementPlaquette(Plaquette): - def __init__(self, qubits: PlaquetteQubits, include_detector: bool = True): - (syndrome_qubit,) = qubits.get_syndrome_qubits_cirq() - data_qubits = qubits.get_data_qubits_cirq() - measurement_qubits = [syndrome_qubit, *data_qubits] - detector = make_detector( - syndrome_qubit, - [(meas_qubit - syndrome_qubit, -1) for meas_qubit in measurement_qubits], - ) - super().__init__( - qubits, - circuit=ScheduledCircuit( - cirq.Circuit( - [ - cirq.Moment( - cirq.M(q).with_tags(self._MERGEABLE_TAG) - for q in data_qubits - ), - cirq.Moment(detector) if include_detector else [], - ] - ), +def measurement_plaquette( + qubits: PlaquetteQubits, include_detector: bool = True +) -> Plaquette: + (syndrome_qubit,) = qubits.get_syndrome_qubits_cirq() + data_qubits = qubits.get_data_qubits_cirq() + measurement_qubits = [syndrome_qubit, *data_qubits] + detector = make_detector( + syndrome_qubit, + [(meas_qubit - syndrome_qubit, -1) for meas_qubit in measurement_qubits], + ) + return Plaquette( + qubits, + circuit=ScheduledCircuit( + cirq.Circuit( + [ + cirq.Moment( + cirq.M(q).with_tags(Plaquette._MERGEABLE_TAG) + for q in data_qubits + ), + cirq.Moment(detector) if include_detector else [], + ] ), - ) + ), + ) -class MeasurementRoundedPlaquette(MeasurementPlaquette): - def __init__( - self, orientation: PlaquetteOrientation, include_detector: bool = True - ): - super().__init__(RoundedPlaquetteQubits(orientation), include_detector) +def measurement_square_plaquette(include_detector: bool = True) -> Plaquette: + return measurement_plaquette(SquarePlaquetteQubits(), include_detector) -class MeasurementSquarePlaquette(MeasurementPlaquette): - def __init__(self, include_detector: bool = True): - super().__init__(SquarePlaquetteQubits(), include_detector) +def measurement_rounded_plaquette( + orientation: PlaquetteOrientation, include_detector: bool = True +) -> Plaquette: + return measurement_plaquette(RoundedPlaquetteQubits(orientation), include_detector) diff --git a/src/tqec/plaquette/library/pauli.py b/src/tqec/plaquette/library/pauli.py index b6fcd51b..7947f841 100644 --- a/src/tqec/plaquette/library/pauli.py +++ b/src/tqec/plaquette/library/pauli.py @@ -8,33 +8,29 @@ from tqec.plaquette.qubit import PlaquetteQubits -class PauliMemoryPlaquette(Plaquette): - def __init__( - self, - qubits: PlaquetteQubits, - pauli_string: str, - schedule: list[int], - include_detector: bool = True, - is_first_round: bool = False, - ): - (syndrome_qubit,) = qubits.get_syndrome_qubits() - data_qubits = qubits.get_data_qubits() +def pauli_memory_plaquette( + qubits: PlaquetteQubits, + pauli_string: str, + schedule: list[int], + include_detector: bool = True, + is_first_round: bool = False, +) -> Plaquette: + (syndrome_qubit,) = qubits.get_syndrome_qubits() + data_qubits = qubits.get_data_qubits() - if len(pauli_string) != len(data_qubits): - raise TQECException( - f"{PauliMemoryPlaquette.__name__} requires the exact same " - f"number of data qubits and Pauli terms. Got {len(pauli_string)} " - f"pauli terms and {len(data_qubits)} data qubits." - ) + if len(pauli_string) != len(data_qubits): + raise TQECException( + f"pauli_memory_plaquette requires the exact same " + f"number of data qubits and Pauli terms. Got {len(pauli_string)} " + f"pauli terms and {len(data_qubits)} data qubits." + ) - circuit = make_pauli_syndrome_measurement_circuit( - syndrome_qubit, data_qubits, pauli_string + circuit = make_pauli_syndrome_measurement_circuit( + syndrome_qubit, data_qubits, pauli_string + ) + if include_detector: + circuit.append( + cirq.Moment(make_memory_experiment_detector(syndrome_qubit, is_first_round)) ) - if include_detector: - circuit.append( - cirq.Moment( - make_memory_experiment_detector(syndrome_qubit, is_first_round) - ) - ) - super().__init__(qubits, ScheduledCircuit(circuit, schedule)) + return Plaquette(qubits, ScheduledCircuit(circuit, schedule)) diff --git a/src/tqec/plaquette/library/xx.py b/src/tqec/plaquette/library/xx.py index 6afb1f0b..e101ef11 100644 --- a/src/tqec/plaquette/library/xx.py +++ b/src/tqec/plaquette/library/xx.py @@ -1,22 +1,21 @@ from __future__ import annotations from tqec.enums import PlaquetteOrientation -from tqec.plaquette.library.pauli import PauliMemoryPlaquette +from tqec.plaquette.library.pauli import pauli_memory_plaquette +from tqec.plaquette.plaquette import Plaquette from tqec.plaquette.qubit import RoundedPlaquetteQubits -class XXMemoryPlaquette(PauliMemoryPlaquette): - def __init__( - self, - orientation: PlaquetteOrientation, - schedule: list[int], - include_detector: bool = True, - is_first_round: bool = False, - ): - super().__init__( - RoundedPlaquetteQubits(orientation), - "XX", - schedule, - include_detector, - is_first_round, - ) +def xx_memory_plaquette( + orientation: PlaquetteOrientation, + schedule: list[int], + include_detector: bool = True, + is_first_round: bool = False, +) -> Plaquette: + return pauli_memory_plaquette( + RoundedPlaquetteQubits(orientation), + "XX", + schedule, + include_detector, + is_first_round, + ) diff --git a/src/tqec/plaquette/library/xxxx.py b/src/tqec/plaquette/library/xxxx.py index 6abda7bd..de720ab6 100644 --- a/src/tqec/plaquette/library/xxxx.py +++ b/src/tqec/plaquette/library/xxxx.py @@ -1,20 +1,19 @@ from __future__ import annotations -from tqec.plaquette.library.pauli import PauliMemoryPlaquette +from tqec.plaquette.library.pauli import pauli_memory_plaquette +from tqec.plaquette.plaquette import Plaquette from tqec.plaquette.qubit import SquarePlaquetteQubits -class XXXXMemoryPlaquette(PauliMemoryPlaquette): - def __init__( - self, - schedule: list[int], - include_detector: bool = True, - is_first_round: bool = False, - ): - super().__init__( - SquarePlaquetteQubits(), - "XXXX", - schedule, - include_detector, - is_first_round, - ) +def xxxx_memory_plaquette( + schedule: list[int], + include_detector: bool = True, + is_first_round: bool = False, +) -> Plaquette: + return pauli_memory_plaquette( + SquarePlaquetteQubits(), + "XXXX", + schedule, + include_detector, + is_first_round, + ) diff --git a/src/tqec/plaquette/library/zz.py b/src/tqec/plaquette/library/zz.py index 3a597c05..dfbcc70d 100644 --- a/src/tqec/plaquette/library/zz.py +++ b/src/tqec/plaquette/library/zz.py @@ -1,22 +1,21 @@ from __future__ import annotations from tqec.enums import PlaquetteOrientation -from tqec.plaquette.library.pauli import PauliMemoryPlaquette +from tqec.plaquette.library.pauli import pauli_memory_plaquette +from tqec.plaquette.plaquette import Plaquette from tqec.plaquette.qubit import RoundedPlaquetteQubits -class ZZMemoryPlaquette(PauliMemoryPlaquette): - def __init__( - self, - orientation: PlaquetteOrientation, - schedule: list[int], - include_detector: bool = True, - is_first_round: bool = False, - ): - super().__init__( - RoundedPlaquetteQubits(orientation), - "ZZ", - schedule, - include_detector, - is_first_round, - ) +def zz_memory_plaquette( + orientation: PlaquetteOrientation, + schedule: list[int], + include_detector: bool = True, + is_first_round: bool = False, +) -> Plaquette: + return pauli_memory_plaquette( + RoundedPlaquetteQubits(orientation), + "ZZ", + schedule, + include_detector, + is_first_round, + ) diff --git a/src/tqec/plaquette/library/zzzz.py b/src/tqec/plaquette/library/zzzz.py index 92558021..c2c71bbe 100644 --- a/src/tqec/plaquette/library/zzzz.py +++ b/src/tqec/plaquette/library/zzzz.py @@ -1,20 +1,19 @@ from __future__ import annotations -from tqec.plaquette.library.pauli import PauliMemoryPlaquette +from tqec.plaquette.library.pauli import pauli_memory_plaquette +from tqec.plaquette.plaquette import Plaquette from tqec.plaquette.qubit import SquarePlaquetteQubits -class ZZZZMemoryPlaquette(PauliMemoryPlaquette): - def __init__( - self, - schedule: list[int], - include_detector: bool = True, - is_first_round: bool = False, - ): - super().__init__( - SquarePlaquetteQubits().permute_data_qubits([0, 2, 1, 3]), - "ZZZZ", - schedule, - include_detector, - is_first_round, - ) +def zzzz_memory_plaquette( + schedule: list[int], + include_detector: bool = True, + is_first_round: bool = False, +) -> Plaquette: + return pauli_memory_plaquette( + SquarePlaquetteQubits().permute_data_qubits([0, 2, 1, 3]), + "ZZZZ", + schedule, + include_detector, + is_first_round, + )