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

Fix applyMatrix in lightning.gpu #932

Merged
merged 4 commits into from
Oct 3, 2024
Merged
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
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@

### Bug fixes

* Bug fix for `applyMatrix` in `lightning.tensor`. Matrix operator data is not stored in the `cuGateCache` object to support `TensorProd` obs with multiple `Hermitian` obs.
[(#932)](https://github.com/PennyLaneAI/pennylane-lightning/pull/932)

* Bug fix for `_pauli_word` of `QuantumScriptSerializer`. `_pauli_word` can process `PauliWord` object: `I`.
[(#919)](https://github.com/PennyLaneAI/pennylane-lightning/pull/919)

Expand Down
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.39.0-dev36"
__version__ = "0.39.0-dev37"
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,19 @@ class StateVectorCudaMPI final
cuGates::getRot<CFP_t>(params[0], params[1], params[2]);
applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, false);
}
} else if (opName == "Matrix") {
DataBuffer<CFP_t, int> d_matrix{
gate_matrix.size(), BaseType::getDataBuffer().getDevTag(),
true};
d_matrix.CopyHostDataToGpu(gate_matrix.data(), d_matrix.getLength(),
false);
// ensure wire indexing correctly preserved for tensor-observables
const std::vector<std::size_t> ctrls_local{ctrls.rbegin(),
ctrls.rend()};
const std::vector<std::size_t> tgts_local{tgts.rbegin(),
tgts.rend()};
applyDeviceMatrixGate(d_matrix.getData(), ctrls_local, tgts_local,
adjoint);
} else if (par_gates_.find(opName) != par_gates_.end()) {
par_gates_.at(opName)(wires, adjoint, params);
} else { // No offloadable function call; defer to matrix passing
Expand Down Expand Up @@ -519,7 +532,7 @@ class StateVectorCudaMPI final
const std::vector<std::size_t> &wires,
bool adjoint = false) {
PL_ABORT_IF(wires.empty(), "Number of wires must be larger than 0");
const std::string opName = {};
const std::string opName = "Matrix";
std::size_t n = std::size_t{1} << wires.size();
const std::vector<std::complex<PrecisionT>> matrix(gate_matrix,
gate_matrix + n * n);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ class StateVectorCudaManaged
cuGates::getRot<CFP_t>(params[0], params[1], params[2]);
applyDeviceMatrixGate(rot_matrix.data(), ctrls, tgts, false);
}
} else if (opName == "Matrix") {
DataBuffer<CFP_t, int> d_matrix{
gate_matrix.size(), BaseType::getDataBuffer().getDevTag(),
true};
d_matrix.CopyHostDataToGpu(gate_matrix.data(), d_matrix.getLength(),
false);
// ensure wire indexing correctly preserved for tensor-observables
const std::vector<std::size_t> ctrls_local{ctrls.rbegin(),
ctrls.rend()};
const std::vector<std::size_t> tgts_local{tgts.rbegin(),
tgts.rend()};
applyDeviceMatrixGate(d_matrix.getData(), ctrls_local, tgts_local,
adjoint);
} else if (par_gates_.find(opName) != par_gates_.end()) {
par_gates_.at(opName)(wires, adjoint, params);
} else { // No offloadable function call; defer to matrix passing
Expand Down Expand Up @@ -439,7 +452,7 @@ class StateVectorCudaManaged
const std::vector<std::size_t> &wires,
bool adjoint = false) {
PL_ABORT_IF(wires.empty(), "Number of wires must be larger than 0");
const std::string opName = {};
const std::string opName = "Matrix";
std::size_t n = std::size_t{1} << wires.size();
const std::vector<std::complex<PrecisionT>> matrix(gate_matrix,
gate_matrix + n * n);
Expand Down
Loading