Function quest_bind::calc_expec_diagonal_op
source · pub fn calc_expec_diagonal_op(
qureg: &Qureg<'_>,
op: &DiagonalOp<'_>
) -> Result<Qcomplex, QuestError>
Expand description
Computes the expected value of the diagonal operator op
.
Since op
is not necessarily Hermitian, the expected value may be a complex
number.
Examples
let env = &QuestEnv::new();
let qureg =
&mut Qureg::try_new(2, &env).expect("cannot allocate memory for Qureg");
let op = &mut DiagonalOp::try_new(2, env).unwrap();
init_diagonal_op(op, &[1., 2., 3., 4.], &[5., 6., 7., 8.]).unwrap();
let expec_val = calc_expec_diagonal_op(qureg, op).unwrap();
assert!((expec_val.re - 1.).abs() < EPSILON);
assert!((expec_val.im - 5.).abs() < EPSILON);
See QuEST API for more information.