cqlib-core 0.1.0-beta.7

The high-performance core foundation for the CQLib quantum computing ecosystem.
Documentation
// This code is part of Cqlib.
//
// (C) Copyright China Telecom Quantum Group 2026
//
// This code is licensed under the Apache License, Version 2.0. You may
// obtain a copy of this license in the LICENSE.txt file in the root directory
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

// Controlled Pauli decomposition rules.
//
// These rules own CX/CY/CZ interconversion.

rule decompose_cx_to_cz {
    match { CX 0 1 }
    rewrite { H 1, CZ 0 1, H 1 }
}

rule decompose_cx_to_crx {
    match { CX 0 1 }
    rewrite { S 0, CRX(π) 0 1 }
}

rule decompose_cz_to_cx {
    match { CZ 0 1 }
    rewrite { H 1, CX 0 1, H 1 }
}

rule decompose_cz_to_crz {
    match { CZ 0 1 }
    rewrite { S 0, CRZ(π) 0 1 }
}

rule decompose_cx_to_cy {
    match { CX 0 1 }
    rewrite { S 1, CY 0 1, SDG 1 }
}

rule decompose_cy_to_cx {
    match { CY 0 1 }
    rewrite { SDG 1, CX 0 1, S 1 }
}

rule decompose_cy_to_cry {
    match { CY 0 1 }
    rewrite { S 0, CRY(π) 0 1 }
}

rule decompose_cy_to_rx_ry_rzz {
    match { CY 0 1 }
    rewrite { RX(-π/2) 1, RY(-π/2) 1, RX(π/2) 1, RY(π/2) 1, RX(π) 1, RX(-π/2) 0, RY(π/2) 0, RX(π/2) 0, RX(-π/2) 1, RY(π/2) 1, RX(π/2) 1, RZZ(-π/2) 0 1, RY(π/2) 1, RX(π) 1, RX(-π/2) 1, RY(π/2) 1, RX(π/2) 1, GPhase(5π/4) }
}

rule decompose_cy_direction_flip {
    match { CY 0 1 }
    rewrite { SDG 1, H 0, H 1, S 0, CY 1 0, SDG 0, H 0, H 1, S 1 }
}

rule decompose_cy_to_cz {
    match { CY 0 1 }
    rewrite { SDG 1, H 1, CZ 0 1, H 1, S 1 }
}

rule decompose_cz_to_cy {
    match { CZ 0 1 }
    rewrite { H 1, S 1, CY 0 1, SDG 1, H 1 }
}