Skip to main content

ppvm_traits/traits/branch/
rot1.rs

1// SPDX-FileCopyrightText: 2026 The PPVM Authors
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::char::Pauli;
5use crate::config::Config;
6
7/// Single-qubit Pauli rotations `exp(-i θ/2 · P)`.
8pub trait RotationOne<T: Config> {
9    /// Rotate about `axis` (one of `X`, `Y`, `Z`) by angle `theta`.
10    fn rotate_1(&mut self, axis: Pauli, addr0: usize, theta: T::Coeff);
11    /// `RX(θ)` on one qubit.
12    fn rx(&mut self, addr0: usize, theta: impl Into<T::Coeff>) {
13        self.rotate_1(Pauli::X, addr0, theta.into())
14    }
15    /// `RY(θ)` on one qubit.
16    fn ry(&mut self, addr0: usize, theta: impl Into<T::Coeff>) {
17        self.rotate_1(Pauli::Y, addr0, theta.into())
18    }
19    /// `RZ(θ)` on one qubit.
20    fn rz(&mut self, addr0: usize, theta: impl Into<T::Coeff>) {
21        self.rotate_1(Pauli::Z, addr0, theta.into())
22    }
23
24    /// Explicit batched `RX(θ)`.
25    fn rx_many(&mut self, targets: &[usize], theta: impl Into<T::Coeff>) {
26        let theta = theta.into();
27        for &q in targets {
28            self.rx(q, theta.clone())
29        }
30    }
31    /// Explicit batched `RY(θ)`.
32    fn ry_many(&mut self, targets: &[usize], theta: impl Into<T::Coeff>) {
33        let theta = theta.into();
34        for &q in targets {
35            self.ry(q, theta.clone())
36        }
37    }
38    /// Explicit batched `RZ(θ)`.
39    fn rz_many(&mut self, targets: &[usize], theta: impl Into<T::Coeff>) {
40        let theta = theta.into();
41        for &q in targets {
42            self.rz(q, theta.clone())
43        }
44    }
45}
46
47/// Rotation about an axis in the x/y plane:
48/// `R(axis_angle, θ) = exp(-i θ/2 · (cos(axis_angle)·X + sin(axis_angle)·Y))`.
49///
50/// The in-plane axis is `X` rotated about `Z` by `axis_angle`, so
51/// `R(axis_angle, θ) = RZ(axis_angle)·RX(θ)·RZ(−axis_angle)`.
52pub trait RotXY<T: Config> {
53    /// `R(axis_angle, θ)` on qubit `addr0`.
54    fn r(&mut self, addr0: usize, axis_angle: T::Coeff, theta: T::Coeff);
55}