From dc232115ac6004d95329def5d0a38c253dfa615d Mon Sep 17 00:00:00 2001 From: Unai Corzo Date: Wed, 3 Nov 2021 20:49:26 +0100 Subject: [PATCH 1/2] Define cirq.ISWAP_INV --- cirq-core/cirq/__init__.py | 1 + cirq-core/cirq/ops/pauli_string_test.py | 2 +- cirq-core/cirq/ops/swap_gates.py | 16 ++++++++++++++++ .../serialization/common_serializers_test.py | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/cirq-core/cirq/__init__.py b/cirq-core/cirq/__init__.py index 9085d27f959..8301077db6f 100644 --- a/cirq-core/cirq/__init__.py +++ b/cirq-core/cirq/__init__.py @@ -227,6 +227,7 @@ IdentityGate, InterchangeableQubitsGate, ISWAP, + ISWAP_INV, ISwapPowGate, KrausChannel, LinearCombinationOfGates, diff --git a/cirq-core/cirq/ops/pauli_string_test.py b/cirq-core/cirq/ops/pauli_string_test.py index 83e2f140656..a6e8dd7ebab 100644 --- a/cirq-core/cirq/ops/pauli_string_test.py +++ b/cirq-core/cirq/ops/pauli_string_test.py @@ -1492,7 +1492,7 @@ def _decompose_(self, qubits): cirq.CNOT, cirq.CZ, cirq.ISWAP, - cirq.ISWAP ** -1, + cirq.ISWAP_INV, cirq.SWAP, cirq.XX ** 0.5, cirq.YY ** 0.5, diff --git a/cirq-core/cirq/ops/swap_gates.py b/cirq-core/cirq/ops/swap_gates.py index fd464d6cd6b..7e8f7c6554c 100644 --- a/cirq-core/cirq/ops/swap_gates.py +++ b/cirq-core/cirq/ops/swap_gates.py @@ -16,6 +16,7 @@ This module creates Gate instances for the following gates: SWAP: the swap gate. ISWAP: a swap gate with a phase on the swapped subspace. + ISWAP_INV: inverse of the ISWAP gate. SQRT_ISWAP: square root of the ISWAP gate. SQRT_ISWAP_INV: inverse square root of the ISWAP gate. @@ -338,6 +339,21 @@ def riswap(rads: value.TParamVal) -> ISwapPowGate: """, ) +ISWAP_INV = ISwapPowGate(exponent=-1) +document( + ISWAP_INV, + """The inverse of iswap gate. + + Matrix: + ``` + [[1, 0, 0, 0], + [0, 0, -i, 0], + [0, -i, 0, 0], + [0, 0, 0, 1]] + ``` + """, +) + SQRT_ISWAP = ISwapPowGate(exponent=0.5) document( SQRT_ISWAP, diff --git a/cirq-google/cirq_google/serialization/common_serializers_test.py b/cirq-google/cirq_google/serialization/common_serializers_test.py index 6a7651366fa..c4b42cee61a 100644 --- a/cirq-google/cirq_google/serialization/common_serializers_test.py +++ b/cirq-google/cirq_google/serialization/common_serializers_test.py @@ -551,7 +551,7 @@ def test_wait_gate_multi_qubit(): (cirq.ISWAP ** 0.5, -np.pi / 4, 0), (cirq.ISWAP ** -0.5, np.pi / 4, 0), (cirq.ISWAP ** 1.0, -np.pi / 2, 0), - (cirq.ISWAP ** -1.0, np.pi / 2, 0), + (cirq.ISWAP_INV, np.pi / 2, 0), (cirq.ISWAP ** 0.0, 0, 0), (cirq.CZ, 0, np.pi), (cirq.CZ ** -1.0, 0, np.pi), From 1860bb252d2bf3f37ad3f64d6cf43e13526bdc5d Mon Sep 17 00:00:00 2001 From: Unai Corzo Date: Wed, 3 Nov 2021 21:01:27 +0100 Subject: [PATCH 2/2] Add ISWAP_INV to cirq.ops --- cirq-core/cirq/ops/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cirq-core/cirq/ops/__init__.py b/cirq-core/cirq/ops/__init__.py index 0b4041e5641..f9584f5f59a 100644 --- a/cirq-core/cirq/ops/__init__.py +++ b/cirq-core/cirq/ops/__init__.py @@ -267,6 +267,7 @@ from cirq.ops.swap_gates import ( ISWAP, + ISWAP_INV, ISwapPowGate, riswap, SQRT_ISWAP,