pub fn apply_pauli_hamil(
    in_qureg: &mut Qureg<'_>,
    hamil: &PauliHamil,
    out_qureg: &mut Qureg<'_>
) -> Result<(), QuestError>
Expand description

Apply Hamiltonian PauliHamil.

Modifies out_qureg to be the result of applying PauliHamil (a Hermitian but not necessarily unitary operator) to in_qureg.

In theory, in_qureg is unchanged though its state is temporarily modified and is reverted by re-applying Paulis (XX=YY=ZZ=I), so may see a change by small numerical errors. The initial state in out_qureg is not used.

Examples

use PauliOpType::{
    PAULI_I,
    PAULI_X,
};

let env = QuestEnv::new();
let mut in_qureg =
    Qureg::try_new(2, &env).expect("cannot allocate memory for Qureg");
let mut out_qureg =
    Qureg::try_new(2, &env).expect("cannot allocate memory for Qureg");

let hamil = &mut PauliHamil::try_new(2, 2).unwrap();
let coeffs = &[SQRT_2.recip(), SQRT_2.recip()];
let codes = &[PAULI_I, PAULI_X, PAULI_X, PAULI_I];
init_pauli_hamil(hamil, coeffs, codes).unwrap();

apply_pauli_hamil(&mut in_qureg, hamil, &mut out_qureg).unwrap();

// out_qureg is now in `|01> + |10>` state:
let qb1 = out_qureg.measure(0).unwrap();
let qb2 = out_qureg.measure(1).unwrap();
assert!(qb1 != qb2);

See QuEST API for more information.