From 3dc04f3a9fd8a642686553a9a6f696528b6eae5b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 19:57:26 +0000 Subject: [PATCH 1/6] bump pyquil to v4; cirq to 1.4.1 --- requirements/requirements-pyquil.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements/requirements-pyquil.txt b/requirements/requirements-pyquil.txt index 7c8f5861f7..4b0f6985c5 100644 --- a/requirements/requirements-pyquil.txt +++ b/requirements/requirements-pyquil.txt @@ -1,2 +1,2 @@ -pyquil~=3.5.4 -cirq-rigetti>=1.0.0,<1.4.0 \ No newline at end of file +pyquil~=4.11.0 +cirq-rigetti>=1.4.1 \ No newline at end of file From e68635ea09afb8a6db3a22537b42f3858d2aaef3 Mon Sep 17 00:00:00 2001 From: nate stemen Date: Mon, 6 Nov 2023 16:34:55 -0800 Subject: [PATCH 2/6] use pyquil built in types for qubits/params --- mitiq/interface/mitiq_pyquil/compiler.py | 42 +++++++++++++----------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/mitiq/interface/mitiq_pyquil/compiler.py b/mitiq/interface/mitiq_pyquil/compiler.py index e98c2079eb..487731f680 100644 --- a/mitiq/interface/mitiq_pyquil/compiler.py +++ b/mitiq/interface/mitiq_pyquil/compiler.py @@ -11,18 +11,18 @@ """ 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 @@ -50,7 +50,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 @@ -65,7 +65,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: @@ -85,7 +87,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) @@ -98,7 +100,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. """ @@ -107,7 +109,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: @@ -119,7 +121,7 @@ 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. """ @@ -132,7 +134,7 @@ def _RX(angle: AngleLike, q: QubitLike) -> Program: 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) """ @@ -143,14 +145,14 @@ def _RY(angle: AngleLike, q: QubitLike) -> Program: 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 @@ -165,7 +167,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) """ @@ -175,7 +177,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) @@ -187,7 +189,7 @@ def _X(q: QubitLike) -> Program: return p -def _Y(q: QubitLike) -> Program: +def _Y(q: QubitDesignator) -> Program: """ A Y in terms of _RY """ @@ -196,7 +198,7 @@ def _Y(q: QubitLike) -> Program: return p -def _Z(q: QubitLike) -> Program: +def _Z(q: QubitDesignator) -> Program: """ A Z in terms of RZ """ From be16b7bb56743a9fb58a71574adaf109f7a5ee34 Mon Sep 17 00:00:00 2001 From: nate stemen Date: Mon, 6 Nov 2023 16:37:11 -0800 Subject: [PATCH 3/6] use numpy.pi everywhere --- mitiq/interface/mitiq_pyquil/compiler.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mitiq/interface/mitiq_pyquil/compiler.py b/mitiq/interface/mitiq_pyquil/compiler.py index 487731f680..6fc8b83e83 100644 --- a/mitiq/interface/mitiq_pyquil/compiler.py +++ b/mitiq/interface/mitiq_pyquil/compiler.py @@ -10,7 +10,6 @@ and modified to support a larger gateset (e.g. CPHASE). """ -from math import pi from typing import cast import numpy as np @@ -126,11 +125,11 @@ 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 @@ -139,9 +138,9 @@ 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 @@ -212,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) ) From 6c0744161bbe121975a260f921267ba764bb59c7 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Mon, 24 Jun 2024 16:09:03 +0200 Subject: [PATCH 4/6] Remove dependency to deprecated Cirq internal function --- mitiq/benchmarks/randomized_benchmarking.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mitiq/benchmarks/randomized_benchmarking.py b/mitiq/benchmarks/randomized_benchmarking.py index 8c5360c391..d0a42c15ca 100644 --- a/mitiq/benchmarks/randomized_benchmarking.py +++ b/mitiq/benchmarks/randomized_benchmarking.py @@ -16,7 +16,7 @@ import numpy as np from cirq.experiments.qubit_characterizations import ( _find_inv_matrix, - _gate_seq_to_mats, + _reduce_gate_seq, _single_qubit_cliffords, _two_qubit_clifford, _two_qubit_clifford_matrices, @@ -60,9 +60,6 @@ def generate_rb_circuits( rng = np.random.RandomState(seed) if n_qubits == 1: c1 = cliffords.c1_in_xy - cfd_mat_1q = np.array( - [_gate_seq_to_mats(gates) for gates in c1], dtype=np.complex64 - ) circuits = [] clifford_group_size = 24 for _ in range(trials): @@ -70,10 +67,7 @@ def generate_rb_circuits( gate_sequence = [ gate for gate_id in gate_ids for gate in c1[gate_id] ] - idx = _find_inv_matrix( - _gate_seq_to_mats(gate_sequence), cfd_mat_1q - ) - gate_sequence.extend(c1[idx]) + gate_sequence.append(_reduce_gate_seq(gate_sequence) ** -1) circuits.append( cirq.Circuit(gate(qubits[0]) for gate in gate_sequence) ) From 068a18c938c7853528993db675594344875da9e5 Mon Sep 17 00:00:00 2001 From: nate stemen Date: Wed, 26 Jun 2024 22:26:25 -0700 Subject: [PATCH 5/6] bump cirq deps --- requirements/requirements-braket.txt | 2 +- requirements/requirements-cirq.txt | 2 +- requirements/requirements.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/requirements-braket.txt b/requirements/requirements-braket.txt index 2f954b8cc6..c8a6928a90 100644 --- a/requirements/requirements-braket.txt +++ b/requirements/requirements-braket.txt @@ -1,2 +1,2 @@ amazon-braket-sdk~=1.69.0 -cirq-ionq>=1.0.0,<1.4.0 \ No newline at end of file +cirq-ionq>=1.4.1 \ No newline at end of file diff --git a/requirements/requirements-cirq.txt b/requirements/requirements-cirq.txt index 8f9e15b617..89dc63cf29 100644 --- a/requirements/requirements-cirq.txt +++ b/requirements/requirements-cirq.txt @@ -1,4 +1,4 @@ # This file is redundant, since Cirq is the core internal representation # for quantum circuits in Mitiq. # Keeping this file anyway for consistency with other integrations. -cirq-core>=1.0.0,<1.4.0 +cirq-core>=1.4.1 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index bced4585e5..526b527b81 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,4 +1,4 @@ numpy>=1.22.0 scipy>=1.10.1,<=1.13.1 -cirq-core>=1.0.0,<1.4.0 +cirq-core>=1.4.1 tabulate From dfdc45587c94b4ade22e68622dc951422e9d1dfe Mon Sep 17 00:00:00 2001 From: nate stemen Date: Tue, 8 Oct 2024 09:04:13 -0700 Subject: [PATCH 6/6] remove problematic CPHASEij gate, and pi --- .../tests/test_conversions_pyquil.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/mitiq/interface/mitiq_pyquil/tests/test_conversions_pyquil.py b/mitiq/interface/mitiq_pyquil/tests/test_conversions_pyquil.py index 26f7abdd6a..2dc49d415e 100644 --- a/mitiq/interface/mitiq_pyquil/tests/test_conversions_pyquil.py +++ b/mitiq/interface/mitiq_pyquil/tests/test_conversions_pyquil.py @@ -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()