CQCL / tket2

Version 2 of the TKET quantum compiler
http://crates.io/crates/tket2
Apache License 2.0
30 stars 6 forks source link

lowering for CX -> hseries is wrong #619

Closed doug-q closed 1 month ago

doug-q commented 1 month ago

Current lowering:

    fn build_cx(&mut self, c: Wire, t: Wire) -> Result<[Wire; 2], BuildError> {
        let pi = pi_mul_f64(self, 1.0);
        let pi_2 = pi_mul_f64(self, 0.5);
        let pi_minus_2 = pi_mul_f64(self, -0.5);

        let t = self.add_phased_x(t, pi_minus_2, pi_2)?; // should be pi_2,pi_2
        let [c, t] = self.add_zz_max(c, t)?;
        let c = self.add_rz(c, pi_minus_2)?; // should be pi_2
        let t = self.add_phased_x(t, pi_2, pi)?; // should be pi/2 0. I think this together with the previous op are equivalent to the other implementation though
        let t = self.add_rz(t, pi_minus_2)?;

        Ok([c, t])
    }

Correct lowering:

    def cx(self, control: int, target: int):
        """
        Apply a controlled-X gate to the given qubits.
        """
        self.rxy(target, pi/2, pi/2);
        self.rzz(control, target, pi/2);
        self.rz(control, pi/2);
        self.rxy(target, pi/2, 0.);
        self.rz(target, -pi/2);
cqc-alec commented 1 month ago

I believe these are equivalent up to global phase, and both correct.

doug-q commented 1 month ago

Thanks Alec