12 using Backend::configuration;
13 using Backend::nrQubits;
14 using Backend::RefreshRoutingCallback;
15 using Backend::upcomingGateIndex;
16 using Backend::upcomingGates;
26 for (Eigen::Index row = 0; row < 4; ++row)
27 for (Eigen::Index col = 0; col < 4; ++col)
29 const Eigen::Index swapped = ((col & 1) << 1) | (col >> 1);
30 if (gate(row, col) != std::complex<double>(row == swapped ? 1. : 0., 0.))
57 RefreshRoutingCallback();
81 dummySim->setGrowthFactorSwap(factor);
88 dummySim->setGrowthFactorGate(factor);
99 return operatorChain && configuration.IsSet(
"matrix_product_operator_max_bond_dimension") ?
"matrix_product_operator_max_bond_dimension"
100 :
"matrix_product_state_max_bond_dimension";
191 if (map.size() != nrQubits || bonds.size() + 1 != nrQubits)
194 dummySim->SetCurrentBondDimensions(bonds);
201 nrQubits <= 1 || count + 1 != nrQubits || upcomingGateIndex < 0 ||
static_cast<size_t>(upcomingGateIndex) >= upcomingGates.size())
203 const auto &op = upcomingGates[upcomingGateIndex];
206 const auto qubits = op->AffectedQubits();
207 if (qubits.size() != 2 || qubits[0] >= nrQubits || qubits[1] >= nrQubits || qubits[0] == qubits[1])
210 if (map.size() != nrQubits)
213 std::vector<double> estimates(bonds, bonds + count);
216 const auto &previous =
dummySim->getCurrentBondDimensions();
217 for (
size_t i = 0; i < count; ++i)
219 estimates[i] = std::max(estimates[i], previous[i]);
222 dummySim->SetCurrentBondDimensions(estimates);
225 double bestCost = std::numeric_limits<double>::infinity();
226 const auto position =
228 if (position < std::min(map[qubits[0]], map[qubits[1]]) || position >= std::max(map[qubits[0]], map[qubits[1]]))
231 dummySim->SwapQubitsToPosition(qubits[0], qubits[1], position);
251 if (q0 >= nrQubits || q1 >= nrQubits || q0 == q1)
254 if (map.size() != nrQubits)
262 if (
dummySim->getQubitsMap() != map)
266 if (std::abs(map[q0] - map[q1]) != 1)
270 const auto &predicted =
dummySim->getQubitsMap();
271 const auto position = std::min(map[q0], map[q1]);
272 if (std::abs(predicted[q0] - predicted[q1]) > 1 && position >= std::min(predicted[q0], predicted[q1]) &&
273 position < std::max(predicted[q0], predicted[q1]))
274 dummySim->SwapQubitsToPosition(q0, q1, position);
277 if (
dummySim->getQubitsMap() != map)
281 dummySim->RecordAdjacentTwoQubitGate(position, isSwap, schmidtRank);
301 if (map.size() != nrQubits)
304 dummySim->SetCurrentBondDimensions(bonds);
324 if (map.size() != nrQubits)
347 ++owner.decompositionDepth;
353 if (notificationsEnabled)
357 --owner.decompositionDepth;
362 const bool notificationsEnabled;
static IndexType EffectiveLookaheadMaxBondDimension(size_t nrQubits, bool operatorChain, IndexType cap)
DecompositionScope(TensorChainRouting &owner)
double getGrowthFactorSwap() const override
void SeedDummyHistory(const std::vector< long long > &map)
void ClearDummySimulator()
void SetLookaheadDepth(int depth) override
static double NativeGateSchmidtRank(const Gate &gate)
void RecordExecutedTwoQubitGate(Types::qubit_t q0, Types::qubit_t q1, bool isSwap, double schmidtRank) noexcept
bool useOptimalMeetingPosition
void setGrowthFactorSwap(double factor) override
virtual std::vector< long long > CurrentRoutingMap() const =0
bool SwapGatesRelabelQubits() const override
MPSDummySimulator::IndexType physicalBondCap
bool swapGatesRelabelQubits
void SetLookaheadDepthWithHeuristic(int depth) override
unsigned decompositionDepth
std::vector< double > savedDummyBondDims
virtual std::vector< double > CurrentBondDimensions() const =0
int lookaheadDepthWithHeuristic
long long PlanMeetingPosition(const Bond *bonds, size_t count)
double getGrowthFactorGate() const override
void EnsureDummySimulator(size_t nQ)
MPSDummySimulator::IndexType EffectiveLookaheadMaxBondDimension(size_t nQ, MPSDummySimulator::IndexType cap) const
const char * MaxBondDimensionConfigKey() const
bool ShouldTrackVirtualBonds() const
void setGrowthFactorGate(double factor) override
TensorChainRouting(bool isOperatorChain, bool relabelSwaps=false)
void SetSwapGatesRelabelQubits(bool enabled)
static bool IsExactSwapMatrix(const Eigen::Matrix4cd &gate)
std::unique_ptr< MPSDummySimulator > dummySim
void RestoreDummyHistory(const std::vector< double > &bonds)
void RefreshRoutingSettings()
size_t GetCurrentMaxBondDimension() const override
std::vector< double > CaptureDummyHistory() const
bool IsRoutingLookaheadEnabled() const override
MPSDummySimulator::IndexType EffectiveLookaheadMaxBondDimension(size_t nQ) const
void ValidateDummyHistoryMap() noexcept
void ResetDummySimulator()
void InvalidateDummyHistory() noexcept
@ kGate
the usual quantum gate, result stays in simulator's state
bool VirtualBondsEnabled(const Config &config)
double TruncationWeight(const Config &config)
double EffectiveSchmidtRank(const Eigen::MatrixXcd &u)
uint_fast64_t qubit_t
The type of a qubit.