Maestro 0.3.11
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
RoutingGateInfo.h
Go to the documentation of this file.
1#pragma once
2#include "QuantumGate.h"
3#include <Eigen/SVD>
4#include <algorithm>
5#include <cmath>
6
7namespace Simulators
8{
9// Effective operator Schmidt rank of a two-qubit unitary: the participation
10// ratio (sum s^2)^2 / sum s^4 of its operator Schmidt coefficients s. It is 1
11// for a product of one-qubit gates, 2 for CX or CZ and 4 for SWAP, and it falls
12// smoothly to 1 as a rotation angle goes to 0. Routing uses it as the factor by
13// which a gate can grow the bond it acts on. Local one-qubit gates on either
14// side leave it unchanged.
15inline double EffectiveSchmidtRank(const Eigen::MatrixXcd &u)
16{
17 if (u.rows() != 4 || u.cols() != 4 || !u.allFinite())
18 return 4.;
19 // Realign: rows pair one qubit's output and input index, columns the other's.
20 Eigen::Matrix4cd r;
21 for (int a = 0; a < 2; ++a)
22 for (int b = 0; b < 2; ++b)
23 for (int c = 0; c < 2; ++c)
24 for (int d = 0; d < 2; ++d)
25 r(2 * a + c, 2 * b + d) = u(2 * a + b, 2 * c + d);
26 const Eigen::Vector4d s = Eigen::JacobiSVD<Eigen::Matrix4cd>(r).singularValues();
27 const double s2 = s.squaredNorm(), s4 = s.array().pow(4).sum();
28 return s4 > 0. ? std::clamp(s2 * s2 / s4, 1., 4.) : 4.;
29}
30
31// A controlled-U gate has operator Schmidt coefficients s^2 = 2 +- |tr U|.
32inline double ControlledSchmidtRank(double traceAbs)
33{
34 return 8. / (4. + traceAbs * traceAbs);
35}
36
37// Closed forms for named gates; matrix() is only called for the others.
38// angle is the gate's first parameter (ignored by unparameterized gates).
39template <class MatrixFn> double RoutingSchmidtRank(Circuits::QuantumGateType type, double angle, MatrixFn &&matrix)
40{
41 switch (type)
42 {
44 return 4.;
49 return 2.;
52 return ControlledSchmidtRank(std::sqrt(2.)); // |tr SX| = |1 + i|
53 case Circuits::QuantumGateType::kCPGateType: // |1 + exp(i angle)|
54 case Circuits::QuantumGateType::kCRxGateType: // |tr Rx(angle)|, likewise Ry, Rz
57 return ControlledSchmidtRank(2. * std::abs(std::cos(angle / 2.)));
58 default:
59 return EffectiveSchmidtRank(matrix());
60 }
61}
62
83
84// Metadata for non-executable routing operations emitted by gate fusion.
86{
87 virtual ~RoutingGateInfo() = default;
88 double schmidtRank = 4; // Effective state-vector rank; the MPO model squares it.
89 bool isSwap = false;
90};
91} // namespace Simulators
QuantumGateType
The type of quantum gates.
Bounded online routing based on current physical bond dimensions.
double RoutingSchmidtRank(Circuits::QuantumGateType type, double angle, MatrixFn &&matrix)
bool IsControlledRoutingGate(Circuits::QuantumGateType type)
double EffectiveSchmidtRank(const Eigen::MatrixXcd &u)
double ControlledSchmidtRank(double traceAbs)
virtual ~RoutingGateInfo()=default