1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()
}
}