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

Update pyquil requirement from ~=3.5.4 to ~=4.11.0 #2063

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
59 changes: 30 additions & 29 deletions mitiq/interface/mitiq_pyquil/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
and modified to support a larger gateset (e.g. CPHASE).
"""

from math import pi
from typing import Any, Union, cast
from typing import cast

import numpy as np
from pyquil.gates import CZ, RX, RZ, XY, I
from pyquil.quil import FormalArgument, Program, Qubit, QubitPlaceholder
from pyquil.quilbase import Expression, Gate
from pyquil.quil import Program
from pyquil.quilatom import ParameterDesignator, QubitDesignator
from pyquil.quilbase import Gate

QubitLike = Union[Qubit, QubitPlaceholder, FormalArgument]
AngleLike = Union[Expression, Any, complex]


def _CCNOT(q0: QubitLike, q1: QubitLike, q2: QubitLike) -> Program:
def _CCNOT(
q0: QubitDesignator, q1: QubitDesignator, q2: QubitDesignator
) -> Program:
"""
A CCNOT in terms of RX(+-pi/2), RZ(theta), and CZ

Expand Down Expand Up @@ -50,7 +49,7 @@ def _CCNOT(q0: QubitLike, q1: QubitLike, q2: QubitLike) -> Program:
return p


def _CNOT(q0: QubitLike, q1: QubitLike) -> Program:
def _CNOT(q0: QubitDesignator, q1: QubitDesignator) -> Program:
"""
A CNOT in terms of RX(+-pi/2), RZ(theta), and CZ

Expand All @@ -65,7 +64,9 @@ def _CNOT(q0: QubitLike, q1: QubitLike) -> Program:
return p


def _CPHASE(angle: AngleLike, q0: QubitLike, q1: QubitLike) -> Program:
def _CPHASE(
angle: ParameterDesignator, q0: QubitDesignator, q1: QubitDesignator
) -> Program:
"""
from quilc:

Expand All @@ -85,7 +86,7 @@ def _CPHASE(angle: AngleLike, q0: QubitLike, q1: QubitLike) -> Program:
return p


def _H(q: QubitLike) -> Program:
def _H(q: QubitDesignator) -> Program:
"""
A Hadamard in terms of RX(+-pi/2) and RZ(theta)

Expand All @@ -98,7 +99,7 @@ def _H(q: QubitLike) -> Program:
return p


def _ISWAP(q0: QubitLike, q1: QubitLike) -> Program:
def _ISWAP(q0: QubitDesignator, q1: QubitDesignator) -> Program:
"""
An ISWAP as an XY(pi). Of course, assumes XY is available.
"""
Expand All @@ -107,7 +108,7 @@ def _ISWAP(q0: QubitLike, q1: QubitLike) -> Program:
return p


def _PHASE(angle: AngleLike, q: QubitLike) -> Program:
def _PHASE(angle: ParameterDesignator, q: QubitDesignator) -> Program:
"""
from quilc:

Expand All @@ -119,38 +120,38 @@ def _PHASE(angle: AngleLike, q: QubitLike) -> Program:
return p


def _RX(angle: AngleLike, q: QubitLike) -> Program:
def _RX(angle: ParameterDesignator, q: QubitDesignator) -> Program:
"""
A RX in terms of native RX(+-pi/2) and RZ gates.
"""
p = Program()
p += RZ(pi / 2, q)
p += RX(pi / 2, q)
p += RZ(np.pi / 2, q)
p += RX(np.pi / 2, q)
p += RZ(angle, q)
p += RX(-pi / 2, q)
p += RZ(-pi / 2, q)
p += RX(-np.pi / 2, q)
p += RZ(-np.pi / 2, q)
return p


def _RY(angle: AngleLike, q: QubitLike) -> Program:
def _RY(angle: ParameterDesignator, q: QubitDesignator) -> Program:
"""
A RY in terms of RX(+-pi/2) and RZ(theta)
"""
p = Program()
p += RX(pi / 2, q)
p += RX(np.pi / 2, q)
p += RZ(angle, q)
p += RX(-pi / 2, q)
p += RX(-np.pi / 2, q)
return p


def _S(q: QubitLike) -> Program:
def _S(q: QubitDesignator) -> Program:
"""
An S in terms of RZ(theta)
"""
return Program(RZ(np.pi / 2, q))


def _SWAP(q0: QubitLike, q1: QubitLike) -> Program:
def _SWAP(q0: QubitDesignator, q1: QubitDesignator) -> Program:
"""
A SWAP in terms of _CNOT

Expand All @@ -165,7 +166,7 @@ def _SWAP(q0: QubitLike, q1: QubitLike) -> Program:
return p


def _T(q: QubitLike, dagger: bool = False) -> Program:
def _T(q: QubitDesignator, dagger: bool = False) -> Program:
"""
A T in terms of RZ(theta)
"""
Expand All @@ -175,7 +176,7 @@ def _T(q: QubitLike, dagger: bool = False) -> Program:
return Program(RZ(np.pi / 4, q))


def _X(q: QubitLike) -> Program:
def _X(q: QubitDesignator) -> Program:
"""
An X in terms of RX(pi)

Expand All @@ -187,7 +188,7 @@ def _X(q: QubitLike) -> Program:
return p


def _Y(q: QubitLike) -> Program:
def _Y(q: QubitDesignator) -> Program:
"""
A Y in terms of _RY
"""
Expand All @@ -196,7 +197,7 @@ def _Y(q: QubitLike) -> Program:
return p


def _Z(q: QubitLike) -> Program:
def _Z(q: QubitDesignator) -> Program:
"""
A Z in terms of RZ
"""
Expand All @@ -210,8 +211,8 @@ def is_magic_angle(angle: complex) -> bool:
Checks to see if an angle is 0, +/-pi/2, or +/-pi.
"""
return bool(
np.isclose(np.abs(angle), pi / 2)
or np.isclose(np.abs(angle), pi)
np.isclose(np.abs(angle), np.pi / 2)
or np.isclose(np.abs(angle), np.pi)
or np.isclose(angle, 0.0)
)

Expand Down
17 changes: 7 additions & 10 deletions mitiq/interface/mitiq_pyquil/tests/test_conversions_pyquil.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,24 @@ def test_to_pyquil_from_pyquil_parameterized():
X 0
Y 1
Z 2
RX(pi/2) 0
RY(pi/2) 1
RZ(pi/2) 2
RX(1.5707963267948966) 0
RY(1.5707963267948966) 1
RZ(1.5707963267948966) 2
H 0
CZ 0 1
CNOT 1 2
CPHASE(pi/2) 0 1
CPHASE00(pi/2) 1 2
CPHASE01(pi/2) 0 1
CPHASE10(pi/2) 1 2
CPHASE(1.5707963267948966) 0 1
ISWAP 0 1
SWAP 1 2
XY(pi/2) 0 1
XY(1.5707963267948966) 0 1
CCNOT 0 1 2
CSWAP 0 1 2
"""


def test_to_pyquil_from_pyquil_almost_all_gates():
"""PHASE, PSWAP, S, T, declaration, and measurement don't convert back
and forth perfectly (in terms of labels -- the program unitaries and
"""PHASE, PSWAP, CHPASEij, S, T, declaration, and measurement don't convert
back and forth perfectly (in terms of labels -- the program unitaries and
number of measurements are equivalent)."""
p = Program(MEASURELESS_QUIL_PROGRAM)
assert p.out() == to_pyquil(from_pyquil(p)).out()
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-braket.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
amazon-braket-sdk~=1.69.0
cirq-ionq>=1.4.0,<1.5.0
cirq-ionq>=1.4.0,<1.5.0
4 changes: 2 additions & 2 deletions requirements/requirements-pyquil.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pyquil~=3.5.4
cirq-rigetti>=1.4.0,<1.5.0
pyquil~=4.11.0
cirq-rigetti>=1.4.0,<1.5.0
Loading