Skip to content

Commit

Permalink
Replaced qubits unordered maps in the MPS simulator with vectors, it …
Browse files Browse the repository at this point in the history
…should be faster that way (nothing spectacular, it was already O(1)).
  • Loading branch information
aromanro committed Sep 19, 2024
1 parent 6784332 commit 2671560
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions QCSim/MPSSimulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "MPSSimulatorImpl.h"

#include <unordered_map>
#include <vector>

namespace QC
{
Expand All @@ -20,8 +20,8 @@ namespace QC
MPSSimulatorState& operator=(const MPSSimulatorState&) = default;
MPSSimulatorState& operator=(MPSSimulatorState&&) = default;

std::unordered_map<MPSSimulatorInterface::IndexType, MPSSimulatorInterface::IndexType> qubitsMap;
std::unordered_map<MPSSimulatorInterface::IndexType, MPSSimulatorInterface::IndexType> qubitsMapInv;
std::vector<MPSSimulatorInterface::IndexType> qubitsMap;
std::vector<MPSSimulatorInterface::IndexType> qubitsMapInv;
};


Expand Down Expand Up @@ -133,8 +133,8 @@ namespace QC
impl.print();

std::cout << "Qubits map: ";
for (const auto [q1, q2] : qubitsMap)
std::cout << q1 << "->" << q2 << " ";
for (int q = 0; q < qubitsMap.size(); ++q)
std::cout << q << "->" << qubitsMap[q] << " ";
std::cout << std::endl;
}

Expand Down Expand Up @@ -246,8 +246,8 @@ namespace QC
private:
void InitQubitsMap()
{
qubitsMap.clear();
qubitsMapInv.clear();
qubitsMap.resize(getNrQubits());
qubitsMapInv.resize(getNrQubits());

for (IndexType i = 0; i < static_cast<IndexType>(getNrQubits()); ++i)
qubitsMapInv[i] = qubitsMap[i] = i;
Expand Down Expand Up @@ -289,8 +289,8 @@ namespace QC
}

MPSSimulatorImpl impl;
std::unordered_map<IndexType, IndexType> qubitsMap;
std::unordered_map<IndexType, IndexType> qubitsMapInv;
std::vector<IndexType> qubitsMap;
std::vector<IndexType> qubitsMapInv;
QC::Gates::SwapGate<MatrixClass> swapGate;
bool swapDown = false;
};
Expand Down

0 comments on commit 2671560

Please sign in to comment.