From b8d6e4b3c453e4c7886153b4eaccd9474551261d Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 22 Nov 2024 13:52:49 -0500 Subject: [PATCH 01/10] initial commit From 045c1c2d09309b89183ca6a8c1af552792bda690 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 22 Nov 2024 20:01:53 +0000 Subject: [PATCH 02/10] fix lgpu rot adjoint --- .../lightning_gpu/StateVectorCudaMPI.hpp | 4 ++-- .../lightning_gpu/StateVectorCudaManaged.hpp | 18 +++++++----------- .../Test_StateVectorCudaManaged_Param.cpp | 4 ++-- .../lightning_gpu/lightning_gpu.toml | 4 ++-- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp index 6fbf9d8b86..881a0533ea 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp @@ -401,9 +401,9 @@ class StateVectorCudaMPI final } else if (opName == "Rot" || opName == "CRot") { auto rot_matrix = adjoint - ? cuGates::getRot(params[2], params[1], params[0]) + ? cuGates::getRot(-params[2], -params[1], -params[0]) : cuGates::getRot(params[0], params[1], params[2]); - applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, adjoint); + applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, false); } else if (opName == "Matrix") { applyDeviceMatrixGate(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp index ce00ad23b3..9e82a6c968 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp @@ -304,15 +304,11 @@ class StateVectorCudaManaged applyParametricPauliGate_({opName}, ctrls, tgts, params.front(), adjoint); } else if (opName == "Rot" || opName == "CRot") { - if (adjoint) { - auto rot_matrix = - cuGates::getRot(params[2], params[1], params[0]); - applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, true); - } else { - auto rot_matrix = - cuGates::getRot(params[0], params[1], params[2]); - applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, false); - } + auto rot_matrix = + adjoint + ? cuGates::getRot(-params[2], -params[1], -params[0]) + : cuGates::getRot(params[0], params[1], params[2]); + applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, false); } else if (opName == "Matrix") { applyDeviceMatrixGate_(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { @@ -408,10 +404,10 @@ class StateVectorCudaManaged } else if (opName == "Rot") { auto rot_matrix = adjoint - ? cuGates::getRot(params[2], params[1], params[0]) + ? cuGates::getRot(-params[2], -params[1], -params[0]) : cuGates::getRot(params[0], params[1], params[2]); applyDeviceGeneralGate_(rot_matrix.data(), ctrlsInt, tgtsInt, - ctrls_valuesInt, adjoint); + ctrls_valuesInt, false); } else if (par_gates_.find(opName) != par_gates_.end()) { // TODO: offload to par_gates_ if available auto &gateMap = diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp index 661de3a8fe..707f594bde 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/gates/tests/Test_StateVectorCudaManaged_Param.cpp @@ -372,7 +372,7 @@ TEMPLATE_TEST_CASE("LightningGPU::applyRot", "[LightningGPU_Param]", float, for (std::size_t i = 0; i < angles.size(); i++) { const auto rot_mat = (adjoint) ? Gates::getRot( - -angles[i][0], -angles[i][1], -angles[i][2]) + -angles[i][2], -angles[i][1], -angles[i][0]) : Gates::getRot( angles[i][0], angles[i][1], angles[i][2]); expected_results[i][0] = rot_mat[0]; @@ -419,7 +419,7 @@ TEMPLATE_TEST_CASE("LightningGPU::applyCRot", "[LightningGPU_Param]", float, std::vector expected_results(8); const auto rot_mat = (adjoint) ? Gates::getRot( - -angles[0], -angles[1], -angles[2]) + -angles[2], -angles[1], -angles[0]) : Gates::getRot( angles[0], angles[1], angles[2]); diff --git a/pennylane_lightning/lightning_gpu/lightning_gpu.toml b/pennylane_lightning/lightning_gpu/lightning_gpu.toml index 480b56c9c7..670e9e1421 100644 --- a/pennylane_lightning/lightning_gpu/lightning_gpu.toml +++ b/pennylane_lightning/lightning_gpu/lightning_gpu.toml @@ -32,7 +32,7 @@ PhaseShift = { properties = [ "invertible", "controllable", "differe RX = { properties = [ "invertible", "controllable", "differentiable" ] } RY = { properties = [ "invertible", "controllable", "differentiable" ] } RZ = { properties = [ "invertible", "controllable", "differentiable" ] } -Rot = { properties = [ "controllable", "differentiable" ] } +Rot = { properties = [ "invertible", "controllable", "differentiable" ] } CNOT = { properties = [ "invertible", "differentiable" ] } CY = { properties = [ "invertible", "differentiable" ] } CZ = { properties = [ "invertible", "differentiable" ] } @@ -47,7 +47,7 @@ ControlledPhaseShift = { properties = [ "invertible", "differe CRX = { properties = [ "invertible", "differentiable" ] } CRY = { properties = [ "invertible", "differentiable" ] } CRZ = { properties = [ "invertible", "differentiable" ] } -CRot = { } +CRot = { properties = [ "invertible" ] } SingleExcitation = { properties = [ "invertible", "controllable", "differentiable" ] } SingleExcitationPlus = { properties = [ "invertible", "controllable", "differentiable" ] } SingleExcitationMinus = { properties = [ "invertible", "controllable", "differentiable" ] } From a9e0752683598c3a4b9563274213deb195154752 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Fri, 22 Nov 2024 20:24:10 +0000 Subject: [PATCH 03/10] Auto update version from '0.40.0-dev14' to '0.40.0-dev15' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index 46600effac..e3474d59e8 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.40.0-dev14" +__version__ = "0.40.0-dev15" From 4746066e8f6b0a9c4a8032c069998781905b685d Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 22 Nov 2024 20:25:43 +0000 Subject: [PATCH 04/10] update changelog --- .github/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 8b3916b8d7..a35f38beb0 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -39,6 +39,9 @@ ### Bug fixes +* Fix issue with `lightning.gpu` Rot operation with adjoint. + [(#1004)](https://github.com/PennyLaneAI/pennylane-lightning/pull/1004) + * Fix issue with adjoint-jacobian of adjoint ops. [(#996)](https://github.com/PennyLaneAI/pennylane-lightning/pull/996) From 08312dfc7e75fadce4da313fabe15da8892ce50c Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 22 Nov 2024 20:36:42 +0000 Subject: [PATCH 05/10] trigger CI From 5c885588192cd3e86098607616ffa8758a2ff868 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Fri, 22 Nov 2024 20:40:11 +0000 Subject: [PATCH 06/10] trigger CI From 4c83a247510db103aeccf6994ae09ba34bc9006f Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Mon, 25 Nov 2024 16:15:08 +0000 Subject: [PATCH 07/10] remove default adj=false argument --- .../src/simulators/lightning_gpu/StateVectorCudaMPI.hpp | 4 +++- .../simulators/lightning_gpu/StateVectorCudaManaged.hpp | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp index 881a0533ea..ba0668a197 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp @@ -403,7 +403,9 @@ class StateVectorCudaMPI final adjoint ? cuGates::getRot(-params[2], -params[1], -params[0]) : cuGates::getRot(params[0], params[1], params[2]); - applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, false); + // Use default adjoint=false for applyDeviceMatrixGate() as reversed + // rot_matrix explicitly used + applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts); } else if (opName == "Matrix") { applyDeviceMatrixGate(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp index 9e82a6c968..3ac9ecf347 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp @@ -308,7 +308,9 @@ class StateVectorCudaManaged adjoint ? cuGates::getRot(-params[2], -params[1], -params[0]) : cuGates::getRot(params[0], params[1], params[2]); - applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, false); + // Use default adjoint=false for applyDeviceGeneralGate_() as + // reversed rot_matrix explicitly used + applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts); } else if (opName == "Matrix") { applyDeviceMatrixGate_(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { @@ -406,8 +408,10 @@ class StateVectorCudaManaged adjoint ? cuGates::getRot(-params[2], -params[1], -params[0]) : cuGates::getRot(params[0], params[1], params[2]); + // Use default adjoint=false for applyDeviceGeneralGate_() as + // reversed rot_matrix explicitly used applyDeviceGeneralGate_(rot_matrix.data(), ctrlsInt, tgtsInt, - ctrls_valuesInt, false); + ctrls_valuesInt); } else if (par_gates_.find(opName) != par_gates_.end()) { // TODO: offload to par_gates_ if available auto &gateMap = From 80c6e2e41b58d966df4d154235b026b4d93522b6 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Mon, 25 Nov 2024 17:27:17 +0000 Subject: [PATCH 08/10] use custatevec adjoint api --- .../lightning_gpu/StateVectorCudaMPI.hpp | 8 ++------ .../lightning_gpu/StateVectorCudaManaged.hpp | 14 ++++---------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp index ba0668a197..7117f9b1c4 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaMPI.hpp @@ -400,12 +400,8 @@ class StateVectorCudaMPI final adjoint); } else if (opName == "Rot" || opName == "CRot") { auto rot_matrix = - adjoint - ? cuGates::getRot(-params[2], -params[1], -params[0]) - : cuGates::getRot(params[0], params[1], params[2]); - // Use default adjoint=false for applyDeviceMatrixGate() as reversed - // rot_matrix explicitly used - applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts); + cuGates::getRot(params[0], params[1], params[2]); + applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, adjoint); } else if (opName == "Matrix") { applyDeviceMatrixGate(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp index 3ac9ecf347..42a718da38 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp @@ -305,12 +305,8 @@ class StateVectorCudaManaged adjoint); } else if (opName == "Rot" || opName == "CRot") { auto rot_matrix = - adjoint - ? cuGates::getRot(-params[2], -params[1], -params[0]) - : cuGates::getRot(params[0], params[1], params[2]); - // Use default adjoint=false for applyDeviceGeneralGate_() as - // reversed rot_matrix explicitly used - applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts); + cuGates::getRot(params[0], params[1], params[2]); + applyDeviceMatrixGate_(rot_matrix.data(), ctrls, tgts, adjoint); } else if (opName == "Matrix") { applyDeviceMatrixGate_(gate_matrix.data(), ctrls, tgts, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { @@ -405,13 +401,11 @@ class StateVectorCudaManaged params.front(), adjoint); } else if (opName == "Rot") { auto rot_matrix = - adjoint - ? cuGates::getRot(-params[2], -params[1], -params[0]) - : cuGates::getRot(params[0], params[1], params[2]); + cuGates::getRot(params[0], params[1], params[2]); // Use default adjoint=false for applyDeviceGeneralGate_() as // reversed rot_matrix explicitly used applyDeviceGeneralGate_(rot_matrix.data(), ctrlsInt, tgtsInt, - ctrls_valuesInt); + ctrls_valuesInt, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { // TODO: offload to par_gates_ if available auto &gateMap = From 427a0a2dc93bbc1610f382d036646f869501688c Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Mon, 25 Nov 2024 17:33:03 +0000 Subject: [PATCH 09/10] remove comment --- .../src/simulators/lightning_gpu/StateVectorCudaManaged.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp index 42a718da38..6da324dda4 100644 --- a/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_gpu/StateVectorCudaManaged.hpp @@ -402,8 +402,6 @@ class StateVectorCudaManaged } else if (opName == "Rot") { auto rot_matrix = cuGates::getRot(params[0], params[1], params[2]); - // Use default adjoint=false for applyDeviceGeneralGate_() as - // reversed rot_matrix explicitly used applyDeviceGeneralGate_(rot_matrix.data(), ctrlsInt, tgtsInt, ctrls_valuesInt, adjoint); } else if (par_gates_.find(opName) != par_gates_.end()) { From 147817690c707138b74fcad127c70529a794cb04 Mon Sep 17 00:00:00 2001 From: ringo-but-quantum Date: Mon, 25 Nov 2024 17:55:54 +0000 Subject: [PATCH 10/10] Auto update version from '0.40.0-dev15' to '0.40.0-dev16' --- pennylane_lightning/core/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/core/_version.py b/pennylane_lightning/core/_version.py index e3474d59e8..39618be329 100644 --- a/pennylane_lightning/core/_version.py +++ b/pennylane_lightning/core/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.40.0-dev15" +__version__ = "0.40.0-dev16"