stabilizer-ch-form-rust 0.1.0

A Rust library implementing CH form representation of stabilizer states for quantum computing simulations.
Documentation
use crate::StabilizerCHForm;
use crate::error::{Error, Result};
use crate::form::types::Scalar;

impl StabilizerCHForm {
    /// Computes the amplitude <0...0|φ> for the stabilizer state φ.
    ///
    /// NOTE: The amplitude includes the phase factor, but not ω.
    /// See around eq.(55) of arXiv:1808.00128 for details.
    pub(crate) fn amplitude_at_zero(&self) -> Result<Scalar> {
        for j in 0..self.n {
            if !self.vec_v[j] && self.vec_s[j] {
                return Ok(Scalar::Zero);
            }
        }
        let weight_v = self.vec_v.iter().filter(|&&x| x).count();

        Ok(Scalar::NonZero {
            phase: self.phase_factor,
            r: weight_v,
        })
    }

    /// Computes the amplitude <s|φ> for the stabilizer state φ and bitstring state s.
    ///
    /// NOTE: The amplitude includes the phase factor, but not the global phase ω.
    /// NOTE: This implementation might be inefficient.
    pub(crate) fn amplitude_at_computational_basis(
        &self,
        s: &ndarray::Array1<bool>,
    ) -> Result<Scalar> {
        if s.len() != self.num_qubits() {
            return Err(Error::InvalidQubitStateLength(s.len(), self.num_qubits()));
        }

        let mut ch_form_clone = self.clone();
        for (i, &bit) in s.iter().enumerate() {
            if bit {
                ch_form_clone.left_multiply_x(i)?;
            }
        }

        ch_form_clone.amplitude_at_zero()
    }
}