diff --git a/lib/gates_cirq.h b/lib/gates_cirq.h index 5287be4f..72959c9a 100644 --- a/lib/gates_cirq.h +++ b/lib/gates_cirq.h @@ -76,10 +76,9 @@ using Matrix1q = std::array, 2>, 2>; template using Matrix2q = std::array, 4>, 4>; -constexpr double h = 0.5; -constexpr double pi = M_PI; -constexpr double inv_pi = 1.0 / pi; -constexpr double is2 = 0.7071067811865475; +constexpr double h_double = 0.5; +constexpr double pi_double = M_PI; +constexpr double is2_double = 0.7071067811865475; // Gates from cirq/ops/identity.py: @@ -124,6 +123,8 @@ struct XPowGate { static constexpr char name[] = "XPowGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type exponent, fp_type global_shift = 0) { fp_type c = std::cos(pi * exponent * 0.5); @@ -143,6 +144,8 @@ struct YPowGate { static constexpr char name[] = "YPowGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type exponent, fp_type global_shift = 0) { fp_type c = std::cos(pi * exponent * 0.5); @@ -162,6 +165,8 @@ struct ZPowGate { static constexpr char name[] = "ZPowGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type exponent, fp_type global_shift = 0) { fp_type c = std::cos(pi * exponent); @@ -181,6 +186,9 @@ struct HPowGate { static constexpr char name[] = "HPowGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type exponent, fp_type global_shift = 0) { fp_type c = std::cos(pi * exponent * 0.5); @@ -203,6 +211,8 @@ struct CZPowGate { static constexpr char name[] = "CZPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -237,6 +247,8 @@ struct CXPowGate { static constexpr char name[] = "CXPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type c = std::cos(pi * exponent * 0.5); @@ -330,6 +342,8 @@ struct H { static constexpr char name[] = "H"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create(unsigned time, unsigned q0) { return CreateGate, H>( time, q0, {is2, 0, is2, 0, is2, 0, -is2, 0}); @@ -356,6 +370,8 @@ struct T { static constexpr char name[] = "T"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create(unsigned time, unsigned q0) { return CreateGate, T>( time, q0, {1, 0, 0, 0, 0, 0, is2, is2}); @@ -464,6 +480,8 @@ struct PhasedXPowGate { static constexpr char name[] = "PhasedXPowGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type phase_exponent, fp_type exponent = 1, fp_type global_shift = 0) { @@ -494,6 +512,8 @@ struct PhasedXZGate { static constexpr char name[] = "PhasedXZGate"; static constexpr unsigned num_qubits = 1; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, fp_type x_exponent, fp_type z_exponent, fp_type axis_phase_exponent) { @@ -527,6 +547,8 @@ struct XXPowGate { static constexpr char name[] = "XXPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -569,6 +591,8 @@ struct YYPowGate { static constexpr char name[] = "YYPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -611,6 +635,8 @@ struct ZZPowGate { static constexpr char name[] = "ZZPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -717,6 +743,9 @@ struct SwapPowGate { static constexpr char name[] = "SwapPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type h = static_cast(h_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -761,6 +790,9 @@ struct ISwapPowGate { static constexpr char name[] = "ISwapPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type h = static_cast(h_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type exponent, fp_type global_shift = 0) { fp_type gc = std::cos(pi * exponent * global_shift); @@ -803,6 +835,9 @@ struct riswap { static constexpr char name[] = "riswap"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type h = static_cast(h_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type phi) { fp_type c = std::cos(phi); @@ -835,6 +870,8 @@ struct SWAP { static constexpr char name[] = "SWAP"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1) { return CreateGate, SWAP>( time, q0, q1, {1, 0, 0, 0, 0, 0, 0, 0, @@ -860,6 +897,9 @@ struct ISWAP { static constexpr char name[] = "ISWAP"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type h = static_cast(h_double); + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1) { return CreateGate, ISWAP>( time, q0, q1, {1, 0, 0, 0, 0, 0, 0, 0, @@ -886,6 +926,9 @@ struct PhasedISwapPowGate { static constexpr char name[] = "PhasedISwapPowGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type h = static_cast(h_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type phase_exponent = 0.25, fp_type exponent = 1.0) { @@ -927,6 +970,9 @@ struct givens { static constexpr char name[] = "givens"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type pi = static_cast(pi_double); + static constexpr fp_type h = static_cast(h_double); + static GateCirq Create(unsigned time, unsigned q0, unsigned q1, fp_type phi) { fp_type c = std::cos(phi); @@ -961,6 +1007,8 @@ struct FSimGate { static constexpr char name[] = "FSimGate"; static constexpr unsigned num_qubits = 2; + static constexpr fp_type is2 = static_cast(is2_double); + static GateCirq Create( unsigned time, unsigned q0, unsigned q1, fp_type theta, fp_type phi) { if (phi < 0) {