Skip to content

Commit

Permalink
Rename iswap rotation (#2526)
Browse files Browse the repository at this point in the history
  • Loading branch information
viathor committed Nov 13, 2019
1 parent 7a15f02 commit 6d5087c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
QubitOrderOrList,
reset,
ResetChannel,
riswap,
Rx,
Ry,
Rz,
Expand Down
1 change: 1 addition & 0 deletions cirq/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
ISWAP,
ISwapPowGate,
ISwapRotation,
riswap,
SWAP,
SwapPowGate,
)
Expand Down
13 changes: 9 additions & 4 deletions cirq/ops/swap_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import sympy

from cirq import protocols, value
from cirq._compat import proper_repr
from cirq._compat import deprecated, proper_repr
from cirq._doc import document
from cirq.ops import common_gates, gate_features, eigen_gate, raw_types

Expand Down Expand Up @@ -248,10 +248,15 @@ def __repr__(self):
self._global_shift)


def ISwapRotation(angle_rads: value.TParamVal) -> ISwapPowGate:
def riswap(rads: value.TParamVal) -> ISwapPowGate:
"""Returns gate with matrix exp(+i angle_rads (X⊗X + Y⊗Y) / 2)."""
pi = sympy.pi if protocols.is_parameterized(angle_rads) else np.pi
return ISwapPowGate()**(2 * angle_rads / pi)
pi = sympy.pi if protocols.is_parameterized(rads) else np.pi
return ISwapPowGate()**(2 * rads / pi)


@deprecated(deadline='v0.8.0', fix='Use cirq.riswap, instead.')
def ISwapRotation(angle_rads: value.TParamVal) -> ISwapPowGate:
return riswap(angle_rads)


SWAP = SwapPowGate()
Expand Down
19 changes: 13 additions & 6 deletions cirq/ops/swap_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def test_trace_distance_over_range_of_exponents():


@pytest.mark.parametrize('angle_rads', (-np.pi, -np.pi / 3, -0.1, np.pi / 5))
def test_iswap_rotation_unitary(angle_rads):
actual = cirq.unitary(cirq.ISwapRotation(angle_rads))
def test_riswap_unitary(angle_rads):
actual = cirq.unitary(cirq.riswap(angle_rads))
c = np.cos(angle_rads)
s = 1j * np.sin(angle_rads)
# yapf: disable
Expand All @@ -159,8 +159,8 @@ def test_iswap_rotation_unitary(angle_rads):


@pytest.mark.parametrize('angle_rads', (-2 * np.pi / 3, -0.2, 0.4, np.pi / 4))
def test_iswap_rotation_hamiltonian(angle_rads):
actual = cirq.unitary(cirq.ISwapRotation(angle_rads))
def test_riswap_hamiltonian(angle_rads):
actual = cirq.unitary(cirq.riswap(angle_rads))
x = np.array([[0, 1], [1, 0]])
y = np.array([[0, -1j], [1j, 0]])
xx = np.kron(x, x)
Expand All @@ -170,6 +170,13 @@ def test_iswap_rotation_hamiltonian(angle_rads):


@pytest.mark.parametrize('angle_rads', (-np.pi / 5, 0.4, 2, np.pi))
def test_iswap_rotation_has_consistent_protocols(angle_rads):
def test_riswap_has_consistent_protocols(angle_rads):
cirq.testing.assert_implements_consistent_protocols(
cirq.ISwapRotation(angle_rads), ignoring_global_phase=False)
cirq.riswap(angle_rads), ignoring_global_phase=False)


@pytest.mark.parametrize('angle_rads', (-1, -0.3, 0.2, 1))
def test_deprecated_riswap(angle_rads):
assert np.all(
cirq.unitary(cirq.ISwapRotation(angle_rads)) == cirq.unitary(
cirq.riswap(angle_rads)))
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Unitary effects that can be applied to one or more qubits.
cirq.SWAP
cirq.TOFFOLI
cirq.identity_each
cirq.riswap
cirq.CCXPowGate
cirq.CCZPowGate
cirq.CNotPowGate
Expand Down

0 comments on commit 6d5087c

Please sign in to comment.