diff --git a/pytket/binders/circuit_library.cpp b/pytket/binders/circuit_library.cpp index 8914230a96..2b85619e48 100644 --- a/pytket/binders/circuit_library.cpp +++ b/pytket/binders/circuit_library.cpp @@ -297,277 +297,5 @@ PYBIND11_MODULE(circuit_library, library_m) { library_m.def( "TK1_to_TK1", &CircPool::tk1_to_tk1, "A circuit of a single tk1 gate with given parameters"); - library_m.def( - "_BRIDGE_using_CX_1", &CircPool::BRIDGE_using_CX_1, - "Equivalent to BRIDGE, using four CX, first CX has control on qubit 1"); - library_m.def( - "_CX_using_TK2", &CircPool::CX_using_TK2, - "Equivalent to CX, using a TK2 and single-qubit gates"); - library_m.def( - "_TK2_using_CX", &CircPool::TK2_using_CX, - "Given expressions α, β and γ, return circuit equivalent to " - "TK2(α, β, γ) using up to 3 CX and single-qubit gates.\n\n" - "The decomposition minimizes the number of CX gates."); - library_m.def( - "_TK2_using_CX_and_swap", &CircPool::TK2_using_CX_and_swap, - "Given expressions α, β and γ, return circuit equivalent to " - "TK2(α, β, γ), up to a wire swap that is encoded in the implicit " - "qubit permutation of the Circuit, using up to 3 CX and single-qubit " - "gates.\n\n" - "The decomposition minimizes the number of CX gates."); - library_m.def( - "_approx_TK2_using_1xCX", &CircPool::approx_TK2_using_1xCX, - "Best approximation of TK2 using 1 CX gate and single-qubit gates, using " - "squared trace fidelity metric. " - "No parameter is required for this approximation. The returned circuit " - "will be equivalent to TK2(0.5, 0, 0)."); - library_m.def( - "_approx_TK2_using_2xCX", &CircPool::approx_TK2_using_2xCX, - "Best approximation of TK2 using 2 CX gates and single-qubit gates, " - "using squared trace fidelity metric. " - "Given expressions α and β, with 0.5 ≥ α ≥ β ≥ 0, return a circuit " - "equivalent to TK2(α, β, 0)."); - library_m.def( - "_TK2_using_3xCX", &CircPool::TK2_using_3xCX, - "Given expressions α, β and γ, return circuit equivalent to " - "TK2(α, β, γ) using 3 CX and single-qubit gates.\n\n" - "Prefer using `_TK2_using_CX` unless you wish to explicitly use 3 CX or " - "if α, β and γ are not normalised to the Weyl chamber."); - library_m.def( - "_CX_using_flipped_CX", &CircPool::CX_using_flipped_CX, - "Equivalent to CX[0,1], using a CX[1,0] and four H gates"); - library_m.def( - "_CX_using_ECR", &CircPool::CX_using_ECR, - "Equivalent to CX, using only ECR, Rx and U3 gates"); - library_m.def( - "_CX_using_ZZMax", &CircPool::CX_using_ZZMax, - "Equivalent to CX, using only ZZMax, Rx and Rz gates"); - library_m.def( - "_CX_using_ZZPhase", &CircPool::CX_using_ZZPhase, - "Equivalent to CX, using only ZZPhase, Rx and Rz gates"); - library_m.def( - "_CX_using_XXPhase_0", &CircPool::CX_using_XXPhase_0, - "Equivalent to CX, using only XXPhase, Rx, Ry and Rz gates"); - - library_m.def( - "_CX_using_XXPhase_1", &CircPool::CX_using_XXPhase_1, - "Equivalent to CX, using only XXPhase, Rx, Ry and Rz gates"); - library_m.def( - "_CX_VS_CX_reduced", &CircPool::CX_VS_CX_reduced, - "CX-reduced form of CX/V,S/CX"); - library_m.def( - "_CX_V_CX_reduced", &CircPool::CX_V_CX_reduced, - "CX-reduced form of CX/V,-/CX"); - library_m.def( - "_CX_S_CX_reduced", &CircPool::CX_S_CX_reduced, - "CX-reduced form of CX/-,S/CX (= ZZMax)"); - library_m.def( - "_CX_V_S_XC_reduced", &CircPool::CX_V_S_XC_reduced, - "CX-reduced form of CX/V,-/S,-/XC"); - library_m.def( - "_CX_S_V_XC_reduced", &CircPool::CX_S_V_XC_reduced, - "CX-reduced form of CX/-,S/-,V/XC"); - library_m.def( - "_CX_XC_reduced", &CircPool::CX_XC_reduced, "CX-reduced form of CX/XC"); - library_m.def( - "_SWAP_using_CX_0", &CircPool::SWAP_using_CX_0, - "Equivalent to SWAP, using three CX, outer CX have control on qubit 0"); - library_m.def( - "_SWAP_using_CX_1", &CircPool::SWAP_using_CX_1, - "Equivalent to SWAP, using three CX, outer CX have control on qubit 1"); - library_m.def( - "_two_Rz1", &CircPool::two_Rz1, - "A two-qubit circuit with an Rz(1) on each qubit"); - library_m.def("_X1_CX", &CircPool::X1_CX, "X[1]; CX[0,1]"); - library_m.def("_Z0_CX", &CircPool::Z0_CX, "Z[0]; CX[0,1] "); - - library_m.def( - "_CCX_modulo_phase_shift", &CircPool::CCX_modulo_phase_shift, - "Equivalent to CCX up to phase shift, using three CX. Warning: this is " - "not equivalent to CCX up to global phase so cannot be used as a direct " - "substitution except when the phase reversal can be cancelled. Its " - "unitary representation is like CCX but with a -1 at the (5,5) " - "position."); - library_m.def( - "_CCX_normal_decomp", &CircPool::CCX_normal_decomp, - "Equivalent to CCX, using 6 CX"); - library_m.def( - "_C3X_normal_decomp", &CircPool::C3X_normal_decomp, - "Equivalent to CCCX, using 14 CX"); - library_m.def( - "_C4X_normal_decomp", &CircPool::C4X_normal_decomp, - "Equivalent to CCCCX, using 36 CX "); - library_m.def( - "_ladder_down", &CircPool::ladder_down, "CX[0,1]; CX[2,0]; CCX[0,1,2]"); - library_m.def( - "_ladder_down_2", &CircPool::ladder_down_2, - "CX[0,1]; X[0]; X[2]; CCX[0,1,2]"); - library_m.def( - "_ladder_up", &CircPool::ladder_up, "CCX[0,1,2]; CX[2,0]; CX[2,1]"); - library_m.def("_X", &CircPool::X, "Just an X gate"); - library_m.def("_CX", &CircPool::CX, "Just a CX[0,1] gate"); - library_m.def("_CCX", &CircPool::CCX, "Just a CCX[0,1,2] gate"); - library_m.def("_BRIDGE", &CircPool::BRIDGE, "Just a BRIDGE[0,1,2] gate"); - library_m.def("_H_CZ_H", &CircPool::H_CZ_H, "H[1]; CZ[0,1]; H[1] "); - library_m.def( - "_CZ_using_CX", &CircPool::CZ_using_CX, - "Equivalent to CZ, using CX and single-qubit gates"); - library_m.def( - "_CY_using_CX", &CircPool::CY_using_CX, - "Equivalent to CY, using CX and single-qubit gates"); - library_m.def( - "_CH_using_CX", &CircPool::CH_using_CX, - "Equivalent to CH, using CX and single-qubit gates"); - library_m.def( - "_CV_using_CX", &CircPool::CV_using_CX, - "Equivalent to CV, using CX and single-qubit gates "); - library_m.def( - "_CVdg_using_CX", &CircPool::CVdg_using_CX, - "Equivalent to CVdg, using CX and single-qubit gates"); - library_m.def( - "_CSX_using_CX", &CircPool::CSX_using_CX, - "Equivalent to CSX, using CX and single-qubit gates"); - library_m.def( - "_CSXdg_using_CX", &CircPool::CSXdg_using_CX, - "Equivalent to CSXdg, using CX and single-qubit gates"); - library_m.def( - "_CS_using_CX", &CircPool::CS_using_CX, - "Equivalent to CS, using CX and single-qubit gates"); - library_m.def( - "_CSdg_using_CX", &CircPool::CSdg_using_CX, - "Equivalent to CSdg, using CX and single-qubit gates"); - library_m.def( - "_CSWAP_using_CX", &CircPool::CSWAP_using_CX, - "Equivalent to CSWAP, using CX and single-qubit gates "); - library_m.def( - "_ECR_using_CX", &CircPool::ECR_using_CX, - "Equivalent to ECR, using CX, Rx and U3 gates "); - library_m.def( - "_ZZMax_using_CX", &CircPool::ZZMax_using_CX, - "Equivalent to ZZMax, using CX, Rz and U3 gates "); - library_m.def( - "_CRz_using_TK2", &CircPool::CRz_using_TK2, - "Equivalent to CRz, using a TK2 and TK1 gates"); - library_m.def( - "_CRz_using_CX", &CircPool::CRz_using_CX, - "Equivalent to CRz, using CX and Rz gates"); - library_m.def( - "_CRx_using_TK2", &CircPool::CRx_using_TK2, - "Equivalent to CRx, using a TK2 and TK1 gates"); - library_m.def( - "_CRx_using_CX", &CircPool::CRx_using_CX, - "Equivalent to CRx, using CX, H and Rx gates"); - library_m.def( - "_CRy_using_TK2", &CircPool::CRy_using_TK2, - "Equivalent to CRy, using a TK2 and TK1 gates"); - library_m.def( - "_CRy_using_CX", &CircPool::CRy_using_CX, - "Equivalent to CRy, using CX and Ry gates"); - library_m.def( - "_CU1_using_TK2", &CircPool::CU1_using_TK2, - "Equivalent to CU1, using a TK2 and TK1 gates"); - library_m.def( - "_CU1_using_CX", &CircPool::CU1_using_CX, - "Equivalent to CU1, using CX and U1 gates"); - library_m.def( - "_CU3_using_CX", &CircPool::CU3_using_CX, - "Equivalent to CU1, using CX, U1 and U3 gates"); - library_m.def( - "_ISWAP_using_TK2", &CircPool::ISWAP_using_TK2, - "Equivalent to ISWAP, using a TK2 gate"); - library_m.def( - "_ISWAP_using_CX", &CircPool::ISWAP_using_CX, - "Equivalent to ISWAP, using CX, U3 and Rz gates"); - library_m.def( - "_XXPhase_using_TK2", &CircPool::XXPhase_using_TK2, - "Equivalent to XXPhase, using a TK2 gate"); - library_m.def( - "_XXPhase_using_CX", &CircPool::XXPhase_using_CX, - "Equivalent to XXPhase, using CX and U3 gates "); - library_m.def( - "_YYPhase_using_TK2", &CircPool::YYPhase_using_TK2, - "Equivalent to YYPhase, using a TK2 gate"); - library_m.def( - "_YYPhase_using_CX", &CircPool::YYPhase_using_CX, - "Equivalent to YYPhase, using two CX gates and one Ry, one Sdg and one S " - "gate."); - library_m.def( - "_ZZPhase_using_TK2", &CircPool::ZZPhase_using_TK2, - "Equivalent to ZZPhase, using a TK2 gate"); - library_m.def( - "_ZZPhase_using_CX", &CircPool::ZZPhase_using_CX, - "Equivalent to ZZPhase, using CX and Rz gates"); - library_m.def( - "_TK2_using_ZZPhase", &CircPool::TK2_using_ZZPhase, - "Equivalent to TK2, using 3 ZZPhase gates"); - library_m.def( - "_TK2_using_ZZPhase_and_swap", &CircPool::TK2_using_ZZPhase_and_swap, - "Equivalent to TK2, up to a wire swap that is encoded in the implicit " - "qubit permutation of the Circuit, using up to 3 ZZPhase gates."); - library_m.def( - "_TK2_using_TK2_or_swap", &CircPool::TK2_using_TK2_or_swap, - "Either the exact TK2, or a wire swap encoded in the implicit qubit " - "permutation of the Circuit and single qubit gates."); - library_m.def( - "_approx_TK2_using_1xZZPhase", &CircPool::approx_TK2_using_1xZZPhase, - "Approximate equivalent to TK2, using 1 ZZPhase gate and single-qubit " - "gates. Only requires the first angle of the TK2 gate."); - library_m.def( - "_approx_TK2_using_2xZZPhase", &CircPool::approx_TK2_using_2xZZPhase, - "Approximate equivalent to TK2, using 2 ZZPhase gates and single-qubit " - "gates. Only requires the first two angles of the TK2 gate."); - library_m.def( - "_TK2_using_ZZMax", &CircPool::TK2_using_ZZMax, - "Equivalent to TK2, using up to 3 ZZMax gates."); - library_m.def( - "_TK2_using_ZZMax_and_swap", &CircPool::TK2_using_ZZMax_and_swap, - "Equivalent to TK2, up to a wire swap that is encoded in the implicit " - "qubit permutation of the Circuit, using up to 3 ZZMax gates."); - library_m.def( - "_XXPhase3_using_TK2", &CircPool::XXPhase3_using_TK2, - "Equivalent to XXPhase3, using three TK2 gates"); - library_m.def( - "_XXPhase3_using_CX", &CircPool::XXPhase3_using_CX, - "Equivalent to 3-qubit MS interaction, using CX and U3 gates"); - library_m.def( - "_ESWAP_using_TK2", &CircPool::ESWAP_using_TK2, - "Equivalent to ESWAP, using a TK2 and (Clifford) TK1 gates"); - library_m.def( - "_ESWAP_using_CX", &CircPool::XXPhase3_using_CX, - "Equivalent to ESWAP, using CX, X, S, Ry and U1 gates"); - library_m.def( - "_FSim_using_TK2", &CircPool::FSim_using_TK2, - "Equivalent to FSim, using a TK2 and TK1 gates"); - library_m.def( - "_FSim_using_CX", &CircPool::FSim_using_CX, - "Equivalent to Fsim, using CX, X, S, U1 and U3 gates "); - library_m.def( - "_PhasedISWAP_using_TK2", &CircPool::PhasedISWAP_using_TK2, - "Equivalent to PhasedISWAP, using a TK2 and Rz gates"); - library_m.def( - "_PhasedISWAP_using_CX", &CircPool::PhasedISWAP_using_CX, - "Equivalent to PhasedISWAP, using CX, U3 and Rz gates"); - library_m.def( - "_NPhasedX_using_PhasedX", &CircPool::NPhasedX_using_PhasedX, - "Unwrap NPhasedX, into number_of_qubits PhasedX gates"); - library_m.def( - "_TK2_using_normalised_TK2", &CircPool::TK2_using_normalised_TK2, - "TK2(a, b, c)-equivalent circuit, using a single normalised TK2 " - "and single-qb gates"); - library_m.def( - "_TK1_to_PhasedXRz", &CircPool::tk1_to_PhasedXRz, - "A tk1 equivalent circuit given tk1 parameters in terms of PhasedX, Rz"); - library_m.def( - "_TK1_to_RzRx", &CircPool::tk1_to_rzrx, - "A tk1 equivalent circuit given tk1 parameters in terms of Rz, Rx"); - library_m.def( - "_TK1_to_RzH", &CircPool::tk1_to_rzh, - "A tk1 equivalent circuit given tk1 parameters in terms of Rz, H"); - library_m.def( - "_TK1_to_RzSX", &CircPool::tk1_to_rzsx, - "A tk1 equivalent circuit given tk1 parameters in terms of Rz, Sx"); - library_m.def( - "_TK1_to_TK1", &CircPool::tk1_to_tk1, - "A circuit of a single tk1 gate with given parameters"); } } // namespace tket diff --git a/pytket/pytket/_tket/circuit_library.pyi b/pytket/pytket/_tket/circuit_library.pyi index 4224fa6173..46fc68d76b 100644 --- a/pytket/pytket/_tket/circuit_library.pyi +++ b/pytket/pytket/_tket/circuit_library.pyi @@ -329,360 +329,6 @@ def ZZPhase_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: """ Equivalent to ZZPhase, using a TK2 gate """ -def _BRIDGE() -> pytket._tket.circuit.Circuit: - """ - Just a BRIDGE[0,1,2] gate - """ -def _BRIDGE_using_CX_1() -> pytket._tket.circuit.Circuit: - """ - Equivalent to BRIDGE, using four CX, first CX has control on qubit 1 - """ -def _C3X_normal_decomp() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CCCX, using 14 CX - """ -def _C4X_normal_decomp() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CCCCX, using 36 CX - """ -def _CCX() -> pytket._tket.circuit.Circuit: - """ - Just a CCX[0,1,2] gate - """ -def _CCX_modulo_phase_shift() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CCX up to phase shift, using three CX. Warning: this is not equivalent to CCX up to global phase so cannot be used as a direct substitution except when the phase reversal can be cancelled. Its unitary representation is like CCX but with a -1 at the (5,5) position. - """ -def _CCX_normal_decomp() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CCX, using 6 CX - """ -def _CH_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CH, using CX and single-qubit gates - """ -def _CRx_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRx, using CX, H and Rx gates - """ -def _CRx_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRx, using a TK2 and TK1 gates - """ -def _CRy_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRy, using CX and Ry gates - """ -def _CRy_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRy, using a TK2 and TK1 gates - """ -def _CRz_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRz, using CX and Rz gates - """ -def _CRz_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CRz, using a TK2 and TK1 gates - """ -def _CSWAP_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CSWAP, using CX and single-qubit gates - """ -def _CSX_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CSX, using CX and single-qubit gates - """ -def _CSXdg_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CSXdg, using CX and single-qubit gates - """ -def _CS_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CS, using CX and single-qubit gates - """ -def _CSdg_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CSdg, using CX and single-qubit gates - """ -def _CU1_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CU1, using CX and U1 gates - """ -def _CU1_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CU1, using a TK2 and TK1 gates - """ -def _CU3_using_CX(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to CU1, using CX, U1 and U3 gates - """ -def _CV_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CV, using CX and single-qubit gates - """ -def _CVdg_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CVdg, using CX and single-qubit gates - """ -def _CX() -> pytket._tket.circuit.Circuit: - """ - Just a CX[0,1] gate - """ -def _CX_S_CX_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/-,S/CX (= ZZMax) - """ -def _CX_S_V_XC_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/-,S/-,V/XC - """ -def _CX_VS_CX_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/V,S/CX - """ -def _CX_V_CX_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/V,-/CX - """ -def _CX_V_S_XC_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/V,-/S,-/XC - """ -def _CX_XC_reduced() -> pytket._tket.circuit.Circuit: - """ - CX-reduced form of CX/XC - """ -def _CX_using_ECR() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using only ECR, Rx and U3 gates - """ -def _CX_using_TK2() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using a TK2 and single-qubit gates - """ -def _CX_using_XXPhase_0() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using only XXPhase, Rx, Ry and Rz gates - """ -def _CX_using_XXPhase_1() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using only XXPhase, Rx, Ry and Rz gates - """ -def _CX_using_ZZMax() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using only ZZMax, Rx and Rz gates - """ -def _CX_using_ZZPhase() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX, using only ZZPhase, Rx and Rz gates - """ -def _CX_using_flipped_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CX[0,1], using a CX[1,0] and four H gates - """ -def _CY_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CY, using CX and single-qubit gates - """ -def _CZ_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to CZ, using CX and single-qubit gates - """ -def _ECR_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to ECR, using CX, Rx and U3 gates - """ -def _ESWAP_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ESWAP, using CX, X, S, Ry and U1 gates - """ -def _ESWAP_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ESWAP, using a TK2 and (Clifford) TK1 gates - """ -def _FSim_using_CX(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to Fsim, using CX, X, S, U1 and U3 gates - """ -def _FSim_using_TK2(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to FSim, using a TK2 and TK1 gates - """ -def _H_CZ_H() -> pytket._tket.circuit.Circuit: - """ - H[1]; CZ[0,1]; H[1] - """ -def _ISWAP_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ISWAP, using CX, U3 and Rz gates - """ -def _ISWAP_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ISWAP, using a TK2 gate - """ -def _NPhasedX_using_PhasedX(arg0: int, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Unwrap NPhasedX, into number_of_qubits PhasedX gates - """ -def _PhasedISWAP_using_CX(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to PhasedISWAP, using CX, U3 and Rz gates - """ -def _PhasedISWAP_using_TK2(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to PhasedISWAP, using a TK2 and Rz gates - """ -def _SWAP_using_CX_0() -> pytket._tket.circuit.Circuit: - """ - Equivalent to SWAP, using three CX, outer CX have control on qubit 0 - """ -def _SWAP_using_CX_1() -> pytket._tket.circuit.Circuit: - """ - Equivalent to SWAP, using three CX, outer CX have control on qubit 1 - """ -def _TK1_to_PhasedXRz(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - A tk1 equivalent circuit given tk1 parameters in terms of PhasedX, Rz - """ -def _TK1_to_RzH(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - A tk1 equivalent circuit given tk1 parameters in terms of Rz, H - """ -def _TK1_to_RzRx(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - A tk1 equivalent circuit given tk1 parameters in terms of Rz, Rx - """ -def _TK1_to_RzSX(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - A tk1 equivalent circuit given tk1 parameters in terms of Rz, Sx - """ -def _TK1_to_TK1(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - A circuit of a single tk1 gate with given parameters - """ -def _TK2_using_3xCX(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Given expressions α, β and γ, return circuit equivalent to TK2(α, β, γ) using 3 CX and single-qubit gates. - - Prefer using `_TK2_using_CX` unless you wish to explicitly use 3 CX or if α, β and γ are not normalised to the Weyl chamber. - """ -def _TK2_using_CX(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Given expressions α, β and γ, return circuit equivalent to TK2(α, β, γ) using up to 3 CX and single-qubit gates. - - The decomposition minimizes the number of CX gates. - """ -def _TK2_using_CX_and_swap(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Given expressions α, β and γ, return circuit equivalent to TK2(α, β, γ), up to a wire swap that is encoded in the implicit qubit permutation of the Circuit, using up to 3 CX and single-qubit gates. - - The decomposition minimizes the number of CX gates. - """ -def _TK2_using_TK2_or_swap(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Either the exact TK2, or a wire swap encoded in the implicit qubit permutation of the Circuit and single qubit gates. - """ -def _TK2_using_ZZMax(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to TK2, using up to 3 ZZMax gates. - """ -def _TK2_using_ZZMax_and_swap(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to TK2, up to a wire swap that is encoded in the implicit qubit permutation of the Circuit, using up to 3 ZZMax gates. - """ -def _TK2_using_ZZPhase(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to TK2, using 3 ZZPhase gates - """ -def _TK2_using_ZZPhase_and_swap(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to TK2, up to a wire swap that is encoded in the implicit qubit permutation of the Circuit, using up to 3 ZZPhase gates. - """ -def _TK2_using_normalised_TK2(arg0: sympy.Expr | float, arg1: sympy.Expr | float, arg2: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - TK2(a, b, c)-equivalent circuit, using a single normalised TK2 and single-qb gates - """ -def _X() -> pytket._tket.circuit.Circuit: - """ - Just an X gate - """ -def _X1_CX() -> pytket._tket.circuit.Circuit: - """ - X[1]; CX[0,1] - """ -def _XXPhase3_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to 3-qubit MS interaction, using CX and U3 gates - """ -def _XXPhase3_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to XXPhase3, using three TK2 gates - """ -def _XXPhase_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to XXPhase, using CX and U3 gates - """ -def _XXPhase_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to XXPhase, using a TK2 gate - """ -def _YYPhase_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to YYPhase, using two CX gates and one Ry, one Sdg and one S gate. - """ -def _YYPhase_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to YYPhase, using a TK2 gate - """ -def _Z0_CX() -> pytket._tket.circuit.Circuit: - """ - Z[0]; CX[0,1] - """ -def _ZZMax_using_CX() -> pytket._tket.circuit.Circuit: - """ - Equivalent to ZZMax, using CX, Rz and U3 gates - """ -def _ZZPhase_using_CX(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ZZPhase, using CX and Rz gates - """ -def _ZZPhase_using_TK2(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Equivalent to ZZPhase, using a TK2 gate - """ -def _approx_TK2_using_1xCX() -> pytket._tket.circuit.Circuit: - """ - Best approximation of TK2 using 1 CX gate and single-qubit gates, using squared trace fidelity metric. No parameter is required for this approximation. The returned circuit will be equivalent to TK2(0.5, 0, 0). - """ -def _approx_TK2_using_1xZZPhase(arg0: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Approximate equivalent to TK2, using 1 ZZPhase gate and single-qubit gates. Only requires the first angle of the TK2 gate. - """ -def _approx_TK2_using_2xCX(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Best approximation of TK2 using 2 CX gates and single-qubit gates, using squared trace fidelity metric. Given expressions α and β, with 0.5 ≥ α ≥ β ≥ 0, return a circuit equivalent to TK2(α, β, 0). - """ -def _approx_TK2_using_2xZZPhase(arg0: sympy.Expr | float, arg1: sympy.Expr | float) -> pytket._tket.circuit.Circuit: - """ - Approximate equivalent to TK2, using 2 ZZPhase gates and single-qubit gates. Only requires the first two angles of the TK2 gate. - """ -def _ladder_down() -> pytket._tket.circuit.Circuit: - """ - CX[0,1]; CX[2,0]; CCX[0,1,2] - """ -def _ladder_down_2() -> pytket._tket.circuit.Circuit: - """ - CX[0,1]; X[0]; X[2]; CCX[0,1,2] - """ -def _ladder_up() -> pytket._tket.circuit.Circuit: - """ - CCX[0,1,2]; CX[2,0]; CX[2,1] - """ -def _two_Rz1() -> pytket._tket.circuit.Circuit: - """ - A two-qubit circuit with an Rz(1) on each qubit - """ def approx_TK2_using_1xCX() -> pytket._tket.circuit.Circuit: """ Best approximation of TK2 using 1 CX gate and single-qubit gates, using squared trace fidelity metric. No parameter is required for this approximation. The returned circuit will be equivalent to TK2(0.5, 0, 0). diff --git a/pytket/pytket/circuit_library/__init__.py b/pytket/pytket/circuit_library/__init__.py index 81868ba880..fc5871c58a 100644 --- a/pytket/pytket/circuit_library/__init__.py +++ b/pytket/pytket/circuit_library/__init__.py @@ -101,89 +101,4 @@ TK1_to_RzH, TK1_to_RzSX, TK1_to_TK1, - _BRIDGE_using_CX_1, - _CX_using_TK2, - _TK2_using_CX, - _TK2_using_CX_and_swap, - _approx_TK2_using_1xCX, - _approx_TK2_using_2xCX, - _TK2_using_3xCX, - _CX_using_flipped_CX, - _CX_using_ECR, - _CX_using_ZZMax, - _CX_using_ZZPhase, - _CX_using_XXPhase_0, - _CX_using_XXPhase_1, - _CX_VS_CX_reduced, - _CX_V_CX_reduced, - _CX_S_CX_reduced, - _CX_V_S_XC_reduced, - _CX_S_V_XC_reduced, - _CX_XC_reduced, - _SWAP_using_CX_0, - _SWAP_using_CX_1, - _two_Rz1, - _X1_CX, - _Z0_CX, - _CCX_modulo_phase_shift, - _CCX_normal_decomp, - _C3X_normal_decomp, - _C4X_normal_decomp, - _ladder_down, - _ladder_down_2, - _ladder_up, - _X, - _CX, - _CCX, - _BRIDGE, - _H_CZ_H, - _CZ_using_CX, - _CY_using_CX, - _CH_using_CX, - _CV_using_CX, - _CVdg_using_CX, - _CSX_using_CX, - _CSXdg_using_CX, - _CSWAP_using_CX, - _ECR_using_CX, - _ZZMax_using_CX, - _CRz_using_TK2, - _CRz_using_CX, - _CRx_using_TK2, - _CRx_using_CX, - _CRy_using_TK2, - _CRy_using_CX, - _CU1_using_TK2, - _CU1_using_CX, - _CU3_using_CX, - _ISWAP_using_TK2, - _ISWAP_using_CX, - _XXPhase_using_TK2, - _XXPhase_using_CX, - _YYPhase_using_TK2, - _YYPhase_using_CX, - _ZZPhase_using_TK2, - _ZZPhase_using_CX, - _TK2_using_ZZPhase, - _TK2_using_ZZPhase_and_swap, - _TK2_using_TK2_or_swap, - _approx_TK2_using_1xZZPhase, - _approx_TK2_using_2xZZPhase, - _TK2_using_ZZMax, - _TK2_using_ZZMax_and_swap, - _XXPhase3_using_TK2, - _XXPhase3_using_CX, - _ESWAP_using_TK2, - _ESWAP_using_CX, - _FSim_using_TK2, - _FSim_using_CX, - _PhasedISWAP_using_TK2, - _PhasedISWAP_using_CX, - _NPhasedX_using_PhasedX, - _TK2_using_normalised_TK2, - _TK1_to_PhasedXRz, - _TK1_to_RzRx, - _TK1_to_RzH, - _TK1_to_RzSX, - _TK1_to_TK1, ) diff --git a/pytket/pytket/passes/auto_rebase.py b/pytket/pytket/passes/auto_rebase.py index 95574f5ac3..6af5c690c6 100644 --- a/pytket/pytket/passes/auto_rebase.py +++ b/pytket/pytket/passes/auto_rebase.py @@ -26,11 +26,11 @@ class NoAutoRebase(Exception): _CX_CIRCS: Dict[OpType, Callable[[], "Circuit"]] = { - OpType.CX: _library._CX, - OpType.ZZMax: _library._CX_using_ZZMax, - OpType.XXPhase: _library._CX_using_XXPhase_0, - OpType.ECR: _library._CX_using_ECR, - OpType.CZ: _library._H_CZ_H, + OpType.CX: _library.CX, + OpType.ZZMax: _library.CX_using_ZZMax, + OpType.XXPhase: _library.CX_using_XXPhase_0, + OpType.ECR: _library.CX_using_ECR, + OpType.CZ: _library.H_CZ_H, } @@ -40,16 +40,16 @@ def _TK2_using_TK2(a: Param, b: Param, c: Param) -> Circuit: _TK2_CIRCS: Dict[OpType, Callable[[Param, Param, Param], "Circuit"]] = { OpType.TK2: _TK2_using_TK2, - OpType.ZZPhase: _library._TK2_using_ZZPhase, - OpType.CX: _library._TK2_using_CX, - OpType.ZZMax: _library._TK2_using_ZZMax, + OpType.ZZPhase: _library.TK2_using_ZZPhase, + OpType.CX: _library.TK2_using_CX, + OpType.ZZMax: _library.TK2_using_ZZMax, } _TK2_CIRCS_WIRE_SWAP: Dict[OpType, Callable[[Param, Param, Param], "Circuit"]] = { - OpType.TK2: _library._TK2_using_TK2_or_swap, - OpType.ZZPhase: _library._TK2_using_ZZPhase_and_swap, - OpType.CX: _library._TK2_using_CX_and_swap, - OpType.ZZMax: _library._TK2_using_ZZMax_and_swap, + OpType.TK2: _library.TK2_using_TK2_or_swap, + OpType.ZZPhase: _library.TK2_using_ZZPhase_and_swap, + OpType.CX: _library.TK2_using_CX_and_swap, + OpType.ZZMax: _library.TK2_using_ZZMax_and_swap, } @@ -92,14 +92,14 @@ def get_tk2_decomposition( _TK1_circs: Dict[FrozenSet[OpType], Callable[[Param, Param, Param], "Circuit"]] = { - frozenset({OpType.TK1}): _library._TK1_to_TK1, - frozenset({OpType.PhasedX, OpType.Rz}): _library._TK1_to_PhasedXRz, - frozenset({OpType.Rx, OpType.Rz}): _library._TK1_to_RzRx, + frozenset({OpType.TK1}): _library.TK1_to_TK1, + frozenset({OpType.PhasedX, OpType.Rz}): _library.TK1_to_PhasedXRz, + frozenset({OpType.Rx, OpType.Rz}): _library.TK1_to_RzRx, frozenset({OpType.Ry, OpType.Rx}): _TK1_to_RxRy, - frozenset({OpType.Rz, OpType.H}): _library._TK1_to_RzH, + frozenset({OpType.Rz, OpType.H}): _library.TK1_to_RzH, frozenset({OpType.Rz, OpType.SX, OpType.X}): _TK1_to_X_SX_Rz, frozenset({OpType.Rz, OpType.SX}): _TK1_to_X_SX_Rz, - frozenset({OpType.Rz, OpType.SX}): _library._TK1_to_RzSX, + frozenset({OpType.Rz, OpType.SX}): _library.TK1_to_RzSX, frozenset({OpType.U3}): _TK1_to_U, } @@ -144,7 +144,7 @@ def auto_rebase_pass(gateset: Set[OpType], allow_swaps: bool = False) -> BasePas # if the gateset has CX but not TK2, and implicit wire swaps not allowed: # rebase via CX if OpType.CX in gateset and OpType.TK2 not in gateset and not allow_swaps: - return RebaseCustom(gateset, _library._CX(), tk1) + return RebaseCustom(gateset, _library.CX(), tk1) # in other cases, try to rebase via TK2 first try: return RebaseCustom(gateset, get_tk2_decomposition(gateset, allow_swaps), tk1) diff --git a/pytket/tests/passes_serialisation_test.py b/pytket/tests/passes_serialisation_test.py index 9c29262d1c..45f54f5129 100644 --- a/pytket/tests/passes_serialisation_test.py +++ b/pytket/tests/passes_serialisation_test.py @@ -589,7 +589,7 @@ def sq(a: ParamType, b: ParamType, c: ParamType) -> Circuit: cx = Circuit(2) cx.CX(0, 1) pz_rebase = RebaseCustom( - {OpType.CX, OpType.PhasedX, OpType.Rz}, cx, _library._TK1_to_TK1 + {OpType.CX, OpType.PhasedX, OpType.Rz}, cx, _library.TK1_to_TK1 ) assert pz_rebase.to_dict()["StandardPass"]["name"] == "RebaseCustom" assert set(pz_rebase.to_dict()["StandardPass"]["basis_allowed"]) == { diff --git a/pytket/tests/transform_test.py b/pytket/tests/transform_test.py index 47fc70addf..d773c86a08 100644 --- a/pytket/tests/transform_test.py +++ b/pytket/tests/transform_test.py @@ -1048,31 +1048,31 @@ def test_CXMappingPass_terminates() -> None: def test_auto_rebase() -> None: pass_params = [ - ({OpType.CX, OpType.Rz, OpType.Rx}, _library._CX(), _library._TK1_to_RzRx), + ({OpType.CX, OpType.Rz, OpType.Rx}, _library.CX(), _library.TK1_to_RzRx), ( {OpType.CZ, OpType.Rz, OpType.SX, OpType.ZZPhase}, _CX_CIRCS[OpType.CZ](), - _library._TK1_to_RzSX, + _library.TK1_to_RzSX, ), ( {OpType.ZZMax, OpType.T, OpType.Rz, OpType.H}, - _library._CX_using_ZZMax(), - _library._TK1_to_RzH, + _library.CX_using_ZZMax(), + _library.TK1_to_RzH, ), ( {OpType.XXPhase, OpType.T, OpType.Rz, OpType.H}, - _library._CX_using_XXPhase_0(), - _library._TK1_to_RzH, + _library.CX_using_XXPhase_0(), + _library.TK1_to_RzH, ), ( {OpType.ECR, OpType.PhasedX, OpType.Rz, OpType.CnX}, - _library._CX_using_ECR(), - _library._TK1_to_PhasedXRz, + _library.CX_using_ECR(), + _library.TK1_to_PhasedXRz, ), ( {OpType.CX, OpType.TK1, OpType.U3, OpType.CnX}, - _library._CX(), - _library._TK1_to_TK1, + _library.CX(), + _library.TK1_to_TK1, ), ] @@ -1114,26 +1114,26 @@ def test_auto_rebase() -> None: def test_auto_squash() -> None: pass_params = [ - ({OpType.Rz, OpType.Rx}, _library._TK1_to_RzRx), + ({OpType.Rz, OpType.Rx}, _library.TK1_to_RzRx), ( {OpType.Rz, OpType.SX}, - _library._TK1_to_RzSX, + _library.TK1_to_RzSX, ), ( {OpType.T, OpType.Rz, OpType.H}, - _library._TK1_to_RzH, + _library.TK1_to_RzH, ), ( {OpType.T, OpType.Rz, OpType.H}, - _library._TK1_to_RzH, + _library.TK1_to_RzH, ), ( {OpType.PhasedX, OpType.Rz}, - _library._TK1_to_PhasedXRz, + _library.TK1_to_PhasedXRz, ), ( {OpType.TK1, OpType.U3}, - _library._TK1_to_TK1, + _library.TK1_to_TK1, ), ]