Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #132 from dmclark17/daclark/single_gate_rot
Browse files Browse the repository at this point in the history
Implements qml.Rot with single cuSV API
  • Loading branch information
mlxd authored Aug 21, 2023
2 parents b9d9a7b + 8197b43 commit 30a412e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 51 deletions.
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

### Improvements

* Optimizes the single qubit rotation gate by using a single cuStateVector API call instead of separate Pauli gate applications.
[(#132)] (https://github.com/PennyLaneAI/pennylane-lightning-gpu/pull/132)

### Documentation

### Bug fixes
Expand All @@ -20,7 +23,7 @@

This release contains contributions from (in alphabetical order):

Shuli Shu
David Clark (NVIDIA), Shuli Shu

---

Expand Down
38 changes: 13 additions & 25 deletions pennylane_lightning_gpu/src/simulator/StateVectorCudaMPI.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Xanadu Quantum Technologies Inc.
// Copyright 2022-2023 Xanadu Quantum Technologies Inc. and contributors.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -385,13 +385,13 @@ class StateVectorCudaMPI
adjoint);
} else if (opName == "Rot" || opName == "CRot") {
if (adjoint) {
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[2], true);
applyParametricPauliGate({"RY"}, ctrls, tgts, params[1], true);
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[0], true);
auto rot_matrix =
cuGates::getRot<CFP_t>(params[2], params[1], params[0]);
applyHostMatrixGate(rot_matrix, ctrls, tgts, true);
} else {
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[0], false);
applyParametricPauliGate({"RY"}, ctrls, tgts, params[1], false);
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[2], false);
auto rot_matrix =
cuGates::getRot<CFP_t>(params[0], params[1], params[2]);
applyHostMatrixGate(rot_matrix, ctrls, tgts, false);
}
} else if (par_gates_.find(opName) != par_gates_.end()) {
par_gates_.at(opName)(wires, adjoint, params);
Expand Down Expand Up @@ -559,15 +559,9 @@ class StateVectorCudaMPI
}
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint,
Precision param0, Precision param1, Precision param2) {
if (!adjoint) {
applyRZ(wires, false, param0);
applyRY(wires, false, param1);
applyRZ(wires, false, param2);
} else {
applyRZ(wires, true, param2);
applyRY(wires, true, param1);
applyRZ(wires, true, param0);
}
const std::string opName = "Rot";
const std::vector<Precision> params = {param0, param1, param2};
applyOperation(opName, wires, adjoint, params);
}
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint,
const std::vector<Precision> &params) {
Expand Down Expand Up @@ -636,15 +630,9 @@ class StateVectorCudaMPI
inline void applyCRot(const std::vector<std::size_t> &wires, bool adjoint,
Precision param0, Precision param1,
Precision param2) {
if (!adjoint) {
applyCRZ(wires, false, param0);
applyCRY(wires, false, param1);
applyCRZ(wires, false, param2);
} else {
applyCRZ(wires, true, param2);
applyCRY(wires, true, param1);
applyCRZ(wires, true, param0);
}
const std::string opName = "CRot";
const std::vector<Precision> params = {param0, param1, param2};
applyOperation(opName, wires, adjoint, params);
}

inline void applyCRX(const std::vector<std::size_t> &wires, bool adjoint,
Expand Down
38 changes: 13 additions & 25 deletions pennylane_lightning_gpu/src/simulator/StateVectorCudaManaged.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Xanadu Quantum Technologies Inc. and contributors.
// Copyright 2022-2023 Xanadu Quantum Technologies Inc. and contributors.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -212,13 +212,13 @@ class StateVectorCudaManaged
adjoint);
} else if (opName == "Rot" || opName == "CRot") {
if (adjoint) {
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[2], true);
applyParametricPauliGate({"RY"}, ctrls, tgts, params[1], true);
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[0], true);
auto rot_matrix =
cuGates::getRot<CFP_t>(params[2], params[1], params[0]);
applyHostMatrixGate(rot_matrix, ctrls, tgts, true);
} else {
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[0], false);
applyParametricPauliGate({"RY"}, ctrls, tgts, params[1], false);
applyParametricPauliGate({"RZ"}, ctrls, tgts, params[2], false);
auto rot_matrix =
cuGates::getRot<CFP_t>(params[0], params[1], params[2]);
applyHostMatrixGate(rot_matrix, ctrls, tgts, false);
}
} else if (par_gates_.find(opName) != par_gates_.end()) {
par_gates_.at(opName)(wires, adjoint, params);
Expand Down Expand Up @@ -387,15 +387,9 @@ class StateVectorCudaManaged
}
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint,
Precision param0, Precision param1, Precision param2) {
if (!adjoint) {
applyRZ(wires, false, param0);
applyRY(wires, false, param1);
applyRZ(wires, false, param2);
} else {
applyRZ(wires, true, param2);
applyRY(wires, true, param1);
applyRZ(wires, true, param0);
}
const std::string opName = "Rot";
const std::vector<Precision> params = {param0, param1, param2};
applyOperation(opName, wires, adjoint, params);
}
inline void applyRot(const std::vector<std::size_t> &wires, bool adjoint,
const std::vector<Precision> &params) {
Expand Down Expand Up @@ -464,15 +458,9 @@ class StateVectorCudaManaged
inline void applyCRot(const std::vector<std::size_t> &wires, bool adjoint,
Precision param0, Precision param1,
Precision param2) {
if (!adjoint) {
applyCRZ(wires, false, param0);
applyCRY(wires, false, param1);
applyCRZ(wires, false, param2);
} else {
applyCRZ(wires, true, param2);
applyCRY(wires, true, param1);
applyCRZ(wires, true, param0);
}
const std::string opName = "CRot";
const std::vector<Precision> params = {param0, param1, param2};
applyOperation(opName, wires, adjoint, params);
}

inline void applyCRX(const std::vector<std::size_t> &wires, bool adjoint,
Expand Down

0 comments on commit 30a412e

Please sign in to comment.