From b6b3308b77e1e372a61de7ddf8caffa23eee1559 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Thu, 2 May 2024 17:37:42 -0400 Subject: [PATCH] Add noisy functionality --- .../measurements/MeasurementsLQubit.hpp | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp b/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp index 0e74849964..b8626d24c0 100644 --- a/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp +++ b/pennylane_lightning/core/src/simulators/lightning_qubit/measurements/MeasurementsLQubit.hpp @@ -31,6 +31,7 @@ #include "LinearAlgebra.hpp" #include "MeasurementsBase.hpp" +#include "NDPermuter.hpp" //transpose_state_tensor, sorting_indices #include "Observables.hpp" #include "SparseLinAlg.hpp" #include "StateVectorLQubitManaged.hpp" @@ -100,22 +101,30 @@ class Measurements final // Determining index that would sort the vector. // This information is needed later. const auto sorted_ind_wires = Pennylane::Util::sorting_indices(wires); + // Sorting wires. std::vector sorted_wires(wires.size()); for (size_t pos = 0; pos < wires.size(); pos++) { sorted_wires[pos] = wires[sorted_ind_wires[pos]]; } + + std::cout << "wires=" << wires << "\n"; + std::cout << "sorted_ind_wires=" << sorted_ind_wires << "\n"; + std::cout << "sorted_wires=" << sorted_wires << "\n"; + // Determining probabilities for the sorted wires. const ComplexT *arr_data = this->_statevector.getData(); size_t num_qubits = this->_statevector.getNumQubits(); - const std::vector all_indices = Gates::generateBitPatterns(sorted_wires, num_qubits); const std::vector all_offsets = Gates::generateBitPatterns( Gates::getIndicesAfterExclusion(sorted_wires, num_qubits), num_qubits); + std::cout << "all_indices=" << all_indices << "\n"; + std::cout << "all_offsets=" << all_offsets << "\n"; + std::vector probabilities(all_indices.size(), 0); size_t ind_probs = 0; @@ -125,13 +134,36 @@ class Measurements final } ind_probs++; } + std::cout << "probabilities=" << probabilities << "\n"; + // Transposing the probabilities tensor with the indices determined // at the beginning. if (wires != sorted_wires) { probabilities = Pennylane::Util::transpose_state_tensor( probabilities, sorted_ind_wires); } - return probabilities; + std::cout << "probabilities+1=" << probabilities << "\n"; + + // return probabilities; + + Pennylane::Util::Permuter> p; + std::vector shape(num_qubits, 2); + std::vector wire_labels_old(sorted_ind_wires.size(), ""); + std::vector wire_labels_new(sorted_ind_wires.size(), ""); + + std::transform(sorted_ind_wires.begin(), sorted_ind_wires.end(), + wire_labels_old.begin(), + [](std::size_t index) { return std::to_string(index); }); + std::transform(wires.begin(), wires.end(), wire_labels_new.begin(), + [](std::size_t index) { return std::to_string(index); }); + // for () + + auto probs_sorted = probabilities; + p.Transpose(probabilities, shape, probs_sorted, wire_labels_old, + wire_labels_new); + std::cout << "probabilities+2=" << probs_sorted << "\n"; + return probs_sorted; + // return probabilities; } /**