Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iSWAP and CPhase gates #45

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pennylane_cirq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
from .qsim_device import QSimDevice, QSimhDevice
from .pasqal_device import PasqalDevice

from .ops import BitFlip, PhaseFlip, PhaseDamp, AmplitudeDamp, Depolarize
from .ops import BitFlip, PhaseFlip, PhaseDamp, AmplitudeDamp, Depolarize, ISWAP, CPhase
from ._version import __version__
2 changes: 2 additions & 0 deletions pennylane_cirq/cirq_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ def __init__(self, wires, shots, analytic, qubits=None):
"T": CirqOperation(lambda: cirq.T),
"CNOT": CirqOperation(lambda: cirq.CNOT),
"SWAP": CirqOperation(lambda: cirq.SWAP),
"ISWAP": CirqOperation(lambda: cirq.ISWAP),
"CZ": CirqOperation(lambda: cirq.CZ),
"PhaseShift": CirqOperation(lambda phi: cirq.ZPowGate(exponent=phi / np.pi)),
"CPhase": CirqOperation(lambda phi: cirq.CZPowGate(exponent=phi / np.pi)),
"RX": CirqOperation(cirq.rx),
"RY": CirqOperation(cirq.ry),
"RZ": CirqOperation(cirq.rz),
Expand Down
40 changes: 40 additions & 0 deletions pennylane_cirq/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,43 @@ class Depolarize(Operation):

grad_method = None
grad_recipe = None


class ISWAP(Operation):
"""Cirq ``ISWAP`` operation.

See the `Cirq docs <https://cirq.readthedocs.io/en/stable/generated/cirq.ISWAP.html>`_
for further details."""

num_params = 0
num_wires = 2
par_domain = None

grad_method = None
grad_recipe = None


class CPhase(Operation):
r"""Conditional phase operation following PennyLane conventions.

Implemented as Cirq ``CZPowGate(exponent=phi / np.pi)``.

.. math::

CPhase(\phi) =
\begin{bmatrix}
[[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, e^{i\phi]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[0, 0, 0, e^{i\phi]]
[0, 0, 0, e^{i\phi}]]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the bmatrix need newlines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're completely right. This is a very ugly mix of Python and Latex. 😆

\end{bmatrix}.

See the `Cirq docs <https://cirq.readthedocs.io/en/stable/generated/cirq.CZPowGate.html>`_
for further details."""

num_params = 1
num_wires = 2
par_domain = "R"

grad_method = None
grad_recipe = None