Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cirq-core/cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@
SingleQubitCliffordGate,
SingleQubitGate,
SingleQubitPauliStringGateOperation,
SQRT_ISWAP,
SQRT_ISWAP_INV,
SWAP,
SwapPowGate,
T,
Expand Down Expand Up @@ -326,6 +328,7 @@
SynchronizeTerminalMeasurements,
two_qubit_matrix_to_operations,
two_qubit_matrix_to_diagonal_and_operations,
two_qubit_matrix_to_sqrt_iswap_operations,
three_qubit_matrix_to_operations,
)

Expand Down
2 changes: 2 additions & 0 deletions cirq-core/cirq/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@
ISWAP,
ISwapPowGate,
riswap,
SQRT_ISWAP,
SQRT_ISWAP_INV,
SWAP,
SwapPowGate,
)
Expand Down
35 changes: 34 additions & 1 deletion cirq-core/cirq/ops/swap_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
This module creates Gate instances for the following gates:
SWAP: the swap gate.
ISWAP: a swap gate with a phase on the swapped subspace.
SQRT_ISWAP: square root of the ISWAP gate.
SQRT_ISWAP_INV: inverse square root of the ISWAP gate.

Each of these are implemented as EigenGates, which means that they can be
raised to a power (i.e. cirq.ISWAP**0.5). See the definition in EigenGate.
raised to a power (i.e. SQRT_ISWAP_INV=cirq.ISWAP**-0.5). See the definition in
EigenGate.
"""

from typing import Optional, Tuple, TYPE_CHECKING, List, Sequence
Expand Down Expand Up @@ -332,3 +335,33 @@ def riswap(rads: value.TParamVal) -> ISwapPowGate:
```
""",
)

SQRT_ISWAP = ISwapPowGate(exponent=0.5)
document(
SQRT_ISWAP,
"""The square root of iswap gate.

Matrix:
```
[[1, 0, 0, 0],
[0, 1/√2, i/√2, 0],
[0, i/√2, 1/√2, 0],
[0, 0, 0, 1]]
```
""",
)

SQRT_ISWAP_INV = ISwapPowGate(exponent=-0.5)
document(
SQRT_ISWAP_INV,
"""The inverse square root of iswap gate.

Matrix:
```
[[1, 0, 0, 0],
[0, 1/√2, -i/√2, 0],
[0, -i/√2, 1/√2, 0],
[0, 0, 0, 1]]
```
""",
)
28 changes: 28 additions & 0 deletions cirq-core/cirq/ops/swap_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,34 @@ def test_iswap_unitary():
# yapf: enable


def test_sqrt_iswap_unitary():
# yapf: disable
cirq.testing.assert_allclose_up_to_global_phase(
cirq.unitary(cirq.SQRT_ISWAP),
# Reference for the sqrt-iSWAP gate's matrix:
# https://arxiv.org/abs/2105.06074
np.array([[1, 0, 0, 0],
[0, 1/2**0.5, 1j/2**0.5, 0],
[0, 1j/2**0.5, 1/2**0.5, 0],
[0, 0, 0, 1]]),
atol=1e-8)
# yapf: enable


def test_sqrt_iswap_inv_unitary():
# yapf: disable
cirq.testing.assert_allclose_up_to_global_phase(
cirq.unitary(cirq.SQRT_ISWAP_INV),
# Reference for the inv-sqrt-iSWAP gate's matrix:
# https://arxiv.org/abs/2105.06074
np.array([[1, 0, 0, 0],
[0, 1/2**0.5, -1j/2**0.5, 0],
[0, -1j/2**0.5, 1/2**0.5, 0],
[0, 0, 0, 1]]),
atol=1e-8)
# yapf: enable


def test_repr():
assert repr(cirq.SWAP) == 'cirq.SWAP'
assert repr(cirq.SWAP ** 0.5) == '(cirq.SWAP**0.5)'
Expand Down
3 changes: 3 additions & 0 deletions cirq-core/cirq/optimizers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
two_qubit_matrix_to_operations,
two_qubit_matrix_to_diagonal_and_operations,
)
from cirq.optimizers.two_qubit_to_sqrt_iswap import (
two_qubit_matrix_to_sqrt_iswap_operations,
)

from cirq.optimizers.two_qubit_to_fsim import (
decompose_two_qubit_interaction_into_four_fsim_gates,
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/optimizers/two_qubit_decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Utility methods related to optimizing quantum circuits."""

from typing import Iterable, List, Tuple, Optional, cast, TYPE_CHECKING
from typing import Iterable, List, Sequence, Tuple, Optional, cast, TYPE_CHECKING

import numpy as np

Expand Down Expand Up @@ -161,7 +161,7 @@ def _xx_yy_zz_interaction_via_full_czs(
yield ops.H(q1)


def _cleanup_operations(operations: List[ops.Operation]):
def _cleanup_operations(operations: Sequence[ops.Operation]):
circuit = circuits.Circuit(operations)
merge_single_qubit_gates.merge_single_qubit_gates_into_phased_x_z(circuit)
eject_phased_paulis.EjectPhasedPaulis().optimize_circuit(circuit)
Expand Down
Loading