|
1525 | 1525 | "\\end{array} \\right]\n", |
1526 | 1526 | "$$\n", |
1527 | 1527 | "\n", |
1528 | | - "Below is a simple implementation of this gate in Cirq. To do this we simply define a class that inherits from `cirq.SingleQubitGate` and implements the `cirq.SupportsUnitary` protocol by implementing the `_unitary_(self)` method. We also define an optional `__str__` representation which Cirq will use when printing this gate out in a circuit diagram." |
| 1528 | + "Below is a simple implementation of this gate in Cirq. To do this we simply define a class that inherits from `cirq.Gate` and implements the `cirq.SupportsUnitary` protocol by implementing the `_unitary_(self)` method. We also define an optional `__str__` representation which Cirq will use when printing this gate out in a circuit diagram." |
1529 | 1529 | ] |
1530 | 1530 | }, |
1531 | 1531 | { |
|
1539 | 1539 | "\"\"\"Example of defining a custom gate in Cirq.\"\"\"\n", |
1540 | 1540 | "\n", |
1541 | 1541 | "\n", |
1542 | | - "class RationalGate(cirq.SingleQubitGate):\n", |
| 1542 | + "class RationalGate(cirq.Gate):\n", |
| 1543 | + " def _num_qubits_(self) -> int:\n", |
| 1544 | + " return 1\n", |
1543 | 1545 | " def _unitary_(self):\n", |
1544 | 1546 | " return np.array([[3 / 5, 4 / 5], [-4 / 5, 3 / 5]])\n", |
1545 | 1547 | "\n", |
|
1780 | 1782 | "\"\"\"Example of a custom gate which supports the decompose protocol.\"\"\"\n", |
1781 | 1783 | "\n", |
1782 | 1784 | "\n", |
1783 | | - "class HXGate(cirq.SingleQubitGate):\n", |
| 1785 | + "class HXGate(cirq.Gate):\n", |
| 1786 | + " def _num_qubits_(self) -> int:\n", |
| 1787 | + " return 1\n", |
1784 | 1788 | " def _decompose_(self, qubits):\n", |
1785 | 1789 | " return cirq.H(*qubits), cirq.X(*qubits)\n", |
1786 | 1790 | "\n", |
|
2832 | 2836 | }, |
2833 | 2837 | "outputs": [], |
2834 | 2838 | "source": [ |
2835 | | - "class InconsistentXGate(cirq.SingleQubitGate):\n", |
| 2839 | + "class InconsistentXGate(cirq.Gate):\n", |
| 2840 | + " def _num_qubits_(self) -> int:\n", |
| 2841 | + " return 1\n", |
2836 | 2842 | " def _decompose_(self, qubits):\n", |
2837 | 2843 | " yield cirq.H(qubits[0])\n", |
2838 | 2844 | " yield cirq.Z(qubits[0])\n", |
|
0 commit comments