Skip to content

Commit

Permalink
Add noisy functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mlxd committed May 2, 2024
1 parent a8a47fb commit b6b3308
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<size_t> 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<size_t> all_indices =
Gates::generateBitPatterns(sorted_wires, num_qubits);
const std::vector<size_t> 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<PrecisionT> probabilities(all_indices.size(), 0);

size_t ind_probs = 0;
Expand All @@ -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<Pennylane::Util::DefaultPermuter<1024>> p;
std::vector<std::size_t> shape(num_qubits, 2);
std::vector<std::string> wire_labels_old(sorted_ind_wires.size(), "");
std::vector<std::string> 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;
}

/**
Expand Down

0 comments on commit b6b3308

Please sign in to comment.