rustiq_core/structures/
pauli_like.rs

1use super::clifford_circuit::{CliffordCircuit, CliffordGate};
2
3/// This trait should be implemented by any struct that can be conjugated by a Clifford gate/circuit
4pub trait PauliLike {
5    /// Conjugate the PauliLike object via a H gate
6    fn h(&mut self, i: usize);
7    /// Conjugate the PauliLike object via a S gate
8    fn s(&mut self, i: usize);
9    /// Conjugate the PauliLike object via a S dagger gate
10    fn sd(&mut self, i: usize);
11    /// Conjugate the PauliLike object via a SQRT_X gate
12    fn sqrt_x(&mut self, i: usize);
13    /// Conjugate the PauliLike object via a SQRT_X dagger gate
14    fn sqrt_xd(&mut self, i: usize);
15    /// Conjugate the PauliLike object via a CNOT gate
16    fn cnot(&mut self, i: usize, j: usize);
17    // Conjugate the PauliLike object via a CZ gate
18    fn cz(&mut self, i: usize, j: usize) {
19        self.h(j);
20        self.cnot(i, j);
21        self.h(j);
22    }
23    /// Conjugate the PauliLike object via a Gate
24    fn conjugate_with_gate(&mut self, gate: &CliffordGate) {
25        match gate {
26            CliffordGate::CNOT(i, j) => self.cnot(*i, *j),
27            CliffordGate::CZ(i, j) => self.cz(*i, *j),
28            CliffordGate::H(i) => self.h(*i),
29            CliffordGate::S(i) => self.s(*i),
30            CliffordGate::Sd(i) => self.sd(*i),
31            CliffordGate::SqrtX(i) => self.sqrt_x(*i),
32            CliffordGate::SqrtXd(i) => self.sqrt_xd(*i),
33        }
34    }
35    /// Conjugate the PauliLike object via a Circuit
36    fn conjugate_with_circuit(&mut self, circuit: &CliffordCircuit) {
37        for gate in circuit.gates.iter() {
38            self.conjugate_with_gate(gate);
39        }
40    }
41}