From 0ea3c8088b33a69ffac841661042ddc181634f15 Mon Sep 17 00:00:00 2001 From: WrathfulSpatula Date: Fri, 31 May 2024 17:27:21 -0400 Subject: [PATCH] Revert "Decompose QFT" This reverts commit de6f5e085eae8ac71b16622017fdb9f3fa17e568. --- pennylane_qrack/QrackDeviceConfig.toml | 2 +- pennylane_qrack/qrack_device.cpp | 14 ++++++++++++++ pennylane_qrack/qrack_device.py | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pennylane_qrack/QrackDeviceConfig.toml b/pennylane_qrack/QrackDeviceConfig.toml index ca3a67e..24ec83d 100644 --- a/pennylane_qrack/QrackDeviceConfig.toml +++ b/pennylane_qrack/QrackDeviceConfig.toml @@ -48,6 +48,7 @@ U2 = { properties = [ "controllable", "invertible" ] } U1 = { properties = [ "controllable", "invertible" ] } MultiControlledX = { properties = [ "controllable", "invertible" ] } Identity = { properties = [ "controllable", "invertible" ] } +QFT = { properties = [ "invertible" ] } # Operators that should be decomposed according to the algorithm used # by PennyLane's device API. @@ -78,7 +79,6 @@ Identity = { properties = [ "controllable", "invertible" ] } # IsingYY = {} # IsingZZ = {} # IsingXY = {} -# QFT = {} # Gates which should be translated to QubitUnitary # [operators.gates.matrix] diff --git a/pennylane_qrack/qrack_device.cpp b/pennylane_qrack/qrack_device.cpp index 66f3a99..bbfe850 100644 --- a/pennylane_qrack/qrack_device.cpp +++ b/pennylane_qrack/qrack_device.cpp @@ -192,6 +192,20 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { qsim->U(target, Qrack::PI_R1 / 2, params[0U], params[1U]); } } + } else if (name == "QFT") { + const size_t maxLcv = wires.size() >> 1U; + const size_t end = wires.size() - 1U; + if (inverse) { + for (size_t i = 0U; i < maxLcv; ++i) { + qsim->Swap(wires[i], wires[end - i]); + } + qsim->IQFTR(wires); + } else { + qsim->QFTR(wires); + for (size_t i = 0U; i < maxLcv; ++i) { + qsim->Swap(wires[i], wires[end - i]); + } + } } else if (name != "Identity") { throw std::domain_error("Unrecognized gate name: " + name); } diff --git a/pennylane_qrack/qrack_device.py b/pennylane_qrack/qrack_device.py index 035718e..d7295f7 100644 --- a/pennylane_qrack/qrack_device.py +++ b/pennylane_qrack/qrack_device.py @@ -154,6 +154,7 @@ class QrackDevice(QubitDevice): "C(CPhase)", "MultiControlledX", "C(MultiControlledX)", + "QFT", } config = pathlib.Path( @@ -597,6 +598,14 @@ def _apply_gate(self, op): -par[1], -par[2], ) + elif opname == "QFT": + self._state.qft(device_wires.labels) + for i in range(len(device_wires.labels) >> 1): + self._state.swap(device_wires.labels[i], device_wires.labels[-i]) + elif opname == "QFT.inv": + for i in range(len(device_wires.labels) >> 1): + self._state.swap(device_wires.labels[i], device_wires.labels[-i]) + self._state.iqft(device_wires.labels) elif opname not in [ "Identity", "Identity.inv",