1111#include " sc/heuristic/HeuristicMapper.hpp"
1212
1313#include " ir/Definitions.hpp"
14+ #include " ir/Permutation.hpp"
1415#include " ir/operations/CompoundOperation.hpp"
1516#include " ir/operations/OpType.hpp"
1617#include " ir/operations/StandardOperation.hpp"
@@ -106,6 +107,20 @@ void HeuristicMapper::map(const Configuration& configuration) {
106107 }
107108}
108109
110+ namespace {
111+ // search for current position of target value in map and afterward exchange
112+ // it with the value at new position
113+ void findAndSWAP (const qc::Qubit targetValue, const qc::Qubit newPosition,
114+ qc::Permutation& map) {
115+ for (const auto & q : map) {
116+ if (q.second == targetValue) {
117+ std::swap (map.at (newPosition), map.at (q.first ));
118+ break ;
119+ }
120+ }
121+ }
122+ } // namespace
123+
109124void HeuristicMapper::staticInitialMapping () {
110125 for (const auto & gate : layers.at (0U )) {
111126 if (gate.singleQubit ()) {
@@ -120,11 +135,12 @@ void HeuristicMapper::staticInitialMapping() {
120135 locations.at (static_cast <std::uint16_t >(gate.control )) =
121136 static_cast <std::int16_t >(q0);
122137 locations.at (gate.target ) = static_cast <std::int16_t >(q1);
123- qcMapped.initialLayout .at (q0) = static_cast <qc::Qubit>(gate.control );
124- qcMapped.initialLayout .at (q1) = static_cast <qc::Qubit>(gate.target );
125- qcMapped.outputPermutation .at (q0) =
126- static_cast <qc::Qubit>(gate.control );
127- qcMapped.outputPermutation .at (q1) = static_cast <qc::Qubit>(gate.target );
138+ findAndSWAP (static_cast <qc::Qubit>(gate.control ), q0,
139+ qcMapped.initialLayout );
140+ findAndSWAP (gate.target , q1, qcMapped.initialLayout );
141+ findAndSWAP (static_cast <qc::Qubit>(gate.control ), q0,
142+ qcMapped.outputPermutation );
143+ findAndSWAP (gate.target , q1, qcMapped.outputPermutation );
128144 break ;
129145 }
130146 }
@@ -137,8 +153,8 @@ void HeuristicMapper::staticInitialMapping() {
137153 if (qubits.at (j) == DEFAULT_POSITION ) {
138154 locations.at (i) = static_cast <std::int16_t >(j);
139155 qubits.at (j) = static_cast <std::int16_t >(i);
140- qcMapped.initialLayout . at (j) = i ;
141- qcMapped.outputPermutation . at (j) = i ;
156+ findAndSWAP (i, j, qcMapped.initialLayout ) ;
157+ findAndSWAP (i, j, qcMapped.outputPermutation ) ;
142158 break ;
143159 }
144160 }
@@ -194,20 +210,6 @@ void HeuristicMapper::createInitialMapping() {
194210 }
195211}
196212
197- namespace {
198- // search for current position of target value in map and afterward exchange
199- // it with the value at new position
200- void findAndSWAP (const qc::Qubit targetValue, const qc::Qubit newPosition,
201- qc::Permutation& map) {
202- for (const auto & q : map) {
203- if (q.second == targetValue) {
204- std::swap (map.at (newPosition), map.at (q.first ));
205- break ;
206- }
207- }
208- }
209- } // namespace
210-
211213void HeuristicMapper::mapUnmappedGates (std::size_t layer) {
212214 if (fidelityAwareHeur) {
213215 for (std::size_t q = 0 ; q < singleQubitMultiplicities.at (layer).size ();
@@ -223,6 +225,10 @@ void HeuristicMapper::mapUnmappedGates(std::size_t layer) {
223225 if (qubits.at (physQbit) == -1 ) {
224226 locations.at (q) = static_cast <std::int16_t >(physQbit);
225227 qubits.at (physQbit) = static_cast <std::int16_t >(q);
228+ findAndSWAP (static_cast <qc::Qubit>(q), physQbit,
229+ qcMapped.initialLayout );
230+ findAndSWAP (static_cast <qc::Qubit>(q), physQbit,
231+ qcMapped.outputPermutation );
226232 break ;
227233 }
228234 }
@@ -498,7 +504,7 @@ void HeuristicMapper::routeCircuit() {
498504 locations.at (target) = static_cast <std::int16_t >(loc);
499505 qubits.at (loc) = static_cast <std::int16_t >(target);
500506 op->setTargets ({static_cast <qc::Qubit>(loc)});
501- qcMapped.initialLayout . at (loc) = target ;
507+ findAndSWAP (target, loc, qcMapped.initialLayout ) ;
502508 qcMapped.outputPermutation [static_cast <qc::Qubit>(loc)] = target;
503509 } else {
504510 op->setTargets ({static_cast <qc::Qubit>(targetLocation)});
0 commit comments