Skip to content

Commit

Permalink
Replace H1-2 with H1-1
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-cqc committed Dec 11, 2023
1 parent 479f229 commit 5520d74
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/Quantinuum_arbitrary_angle_zz.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/Quantinuum_conditional_gates.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["<div style=\"text-align: center;\"><br>\n", "<img src=\"https://assets-global.website-files.com/62b9d45fb3f64842a96c9686/62d84db4aeb2f6552f3a2f78_Quantinuum%20Logo__horizontal%20blue.svg\" width=\"200\" height=\"200\" /></div>"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Conditional Gates"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Quantinuum H-Series hardware and pytket support conditional gating. This may be for implementing error correction or reducing noise. This capability is well-supported by Quantinuum hardware, which supports mid-circuit measurement and reset and qubit reuse. See [Conditional Gates](https://tket.quantinuum.com/user-manual/manual_circuit.html#classical-and-conditional-operations) for more information on pytket's implementation. The following example demonstrates a quantum teleportation protocol."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.circuit import Circuit, if_bit\n", "from pytket.circuit.display import render_circuit_jupyter"]}, {"cell_type": "markdown", "metadata": {}, "source": ["create a circuit and add quantum and classical registers"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ = Circuit(name=\"Conditional Gates Example\")\n", "qreg = circ.add_q_register(\"q\", 3)\n", "creg = circ.add_c_register(\"b\", 2)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["prepare q[0] to be in the state |->, which we wish to teleport to q[2]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.X(qreg[0]).H(qreg[0])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["prepare a Bell state on qubits q[1] and q[2]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.H(qreg[1])\n", "circ.CX(qreg[1], qreg[2])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["construct the teleportation protocol"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.CX(qreg[0], qreg[1])\n", "circ.H(qreg[0])\n", "circ.Measure(qreg[0], creg[0])\n", "circ.Measure(qreg[1], creg[1])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["if (creg[1] == 1)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.X(qreg[2], condition=if_bit(creg[1]))"]}, {"cell_type": "markdown", "metadata": {}, "source": ["if (creg[0] == 1)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.Z(qreg[2], condition=if_bit(creg[0]))"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["render_circuit_jupyter(circ)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["We can utilise pytket's [Assertion](https://tket.quantinuum.com/user-manual/manual_assertion.html) feature to verify the successful teleportation of the state $| - \\rangle$."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.circuit import ProjectorAssertionBox\n", "import numpy as np"]}, {"cell_type": "markdown", "metadata": {}, "source": ["|-><-|"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["proj = np.array([[0.5, -0.5], [-0.5, 0.5]])\n", "circ.add_assertion(ProjectorAssertionBox(proj), [qreg[2]], name=\"debug\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["render_circuit_jupyter(circ)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.extensions.quantinuum import QuantinuumBackend"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["machine = \"H1-1E\"\n", "n_shots = 100\n", "backend = QuantinuumBackend(device_name=machine)\n", "compiled_circuit = backend.get_compiled_circuit(circ)\n", "backend.cost(compiled_circuit, n_shots=n_shots, syntax_checker=\"H1-2SC\")\n", "handle = backend.process_circuit(compiled_circuit, n_shots=n_shots)\n", "status = backend.circuit_status(handle)\n", "status"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["result = backend.get_result(handle)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The `get_debug_info` function returns the success rate of the state assertion averaged across shots. Note that the failed shots are caused by the simulated device errors"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["result.get_debug_info()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["<div align=\"center\"> &copy; 2024 by Quantinuum. All Rights Reserved. </div>"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.6.4"}}, "nbformat": 4, "nbformat_minor": 2}
{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["<div style=\"text-align: center;\"><br>\n", "<img src=\"https://assets-global.website-files.com/62b9d45fb3f64842a96c9686/62d84db4aeb2f6552f3a2f78_Quantinuum%20Logo__horizontal%20blue.svg\" width=\"200\" height=\"200\" /></div>"]}, {"cell_type": "markdown", "metadata": {}, "source": ["# Conditional Gates"]}, {"cell_type": "markdown", "metadata": {}, "source": ["Quantinuum H-Series hardware and pytket support conditional gating. This may be for implementing error correction or reducing noise. This capability is well-supported by Quantinuum hardware, which supports mid-circuit measurement and reset and qubit reuse. See [Conditional Gates](https://tket.quantinuum.com/user-manual/manual_circuit.html#classical-and-conditional-operations) for more information on pytket's implementation. The following example demonstrates a quantum teleportation protocol."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.circuit import Circuit, if_bit\n", "from pytket.circuit.display import render_circuit_jupyter"]}, {"cell_type": "markdown", "metadata": {}, "source": ["create a circuit and add quantum and classical registers"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ = Circuit(name=\"Conditional Gates Example\")\n", "qreg = circ.add_q_register(\"q\", 3)\n", "creg = circ.add_c_register(\"b\", 2)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["prepare q[0] to be in the state |->, which we wish to teleport to q[2]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.X(qreg[0]).H(qreg[0])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["prepare a Bell state on qubits q[1] and q[2]"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.H(qreg[1])\n", "circ.CX(qreg[1], qreg[2])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["construct the teleportation protocol"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.CX(qreg[0], qreg[1])\n", "circ.H(qreg[0])\n", "circ.Measure(qreg[0], creg[0])\n", "circ.Measure(qreg[1], creg[1])"]}, {"cell_type": "markdown", "metadata": {}, "source": ["if (creg[1] == 1)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.X(qreg[2], condition=if_bit(creg[1]))"]}, {"cell_type": "markdown", "metadata": {}, "source": ["if (creg[0] == 1)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["circ.Z(qreg[2], condition=if_bit(creg[0]))"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["render_circuit_jupyter(circ)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["We can utilise pytket's [Assertion](https://tket.quantinuum.com/user-manual/manual_assertion.html) feature to verify the successful teleportation of the state $| - \\rangle$."]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.circuit import ProjectorAssertionBox\n", "import numpy as np"]}, {"cell_type": "markdown", "metadata": {}, "source": ["|-><-|"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["proj = np.array([[0.5, -0.5], [-0.5, 0.5]])\n", "circ.add_assertion(ProjectorAssertionBox(proj), [qreg[2]], name=\"debug\")"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["render_circuit_jupyter(circ)"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["from pytket.extensions.quantinuum import QuantinuumBackend"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["machine = \"H1-1E\"\n", "n_shots = 100\n", "backend = QuantinuumBackend(device_name=machine)\n", "compiled_circuit = backend.get_compiled_circuit(circ)\n", "backend.cost(compiled_circuit, n_shots=n_shots, syntax_checker=\"H1-1SC\")\n", "handle = backend.process_circuit(compiled_circuit, n_shots=n_shots)\n", "status = backend.circuit_status(handle)\n", "status"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["result = backend.get_result(handle)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The `get_debug_info` function returns the success rate of the state assertion averaged across shots. Note that the failed shots are caused by the simulated device errors"]}, {"cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": ["result.get_debug_info()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["<div align=\"center\"> &copy; 2024 by Quantinuum. All Rights Reserved. </div>"]}], "metadata": {"kernelspec": {"display_name": "Python 3", "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.6.4"}}, "nbformat": 4, "nbformat_minor": 2}
Loading

0 comments on commit 5520d74

Please sign in to comment.