diff --git a/tangelo/linq/target/backend.py b/tangelo/linq/target/backend.py index 0de69fd7e..fc446bee1 100644 --- a/tangelo/linq/target/backend.py +++ b/tangelo/linq/target/backend.py @@ -314,8 +314,10 @@ def get_expectation_value(self, qubit_operator, state_prep_circuit, initial_stat qb_op_real.terms[term], qb_op_imag.terms[term] = coef.real, coef.imag qb_op_real.compress() qb_op_imag.compress() - exp_real = self.get_expectation_value(qb_op_real, state_prep_circuit, initial_statevector=initial_statevector) - exp_imag = self.get_expectation_value(qb_op_imag, state_prep_circuit, initial_statevector=initial_statevector) + exp_real = self.get_expectation_value(qb_op_real, state_prep_circuit, initial_statevector=initial_statevector, + desired_meas_result=desired_meas_result) + exp_imag = self.get_expectation_value(qb_op_imag, state_prep_circuit, initial_statevector=initial_statevector, + desired_meas_result=desired_meas_result) return exp_real if (exp_imag == 0.) else exp_real + 1.0j * exp_imag def get_variance(self, qubit_operator, state_prep_circuit, initial_statevector=None, desired_meas_result=None): diff --git a/tangelo/linq/tests/test_simulator.py b/tangelo/linq/tests/test_simulator.py index 62b84f2f2..8aaacaab5 100644 --- a/tangelo/linq/tests/test_simulator.py +++ b/tangelo/linq/tests/test_simulator.py @@ -420,7 +420,7 @@ def test_get_exp_value_from_statevector_with_shots_h2(self): def test_get_exp_value_mixed_state_desired_measurement_with_shots(self): """ Get expectation value of mixed state by post-selecting on desired measurement.""" - qubit_operator = QubitOperator("X0 X1") + QubitOperator("Y0 Y1") + QubitOperator("Z0 Z1") + qubit_operator = QubitOperator("X0 X1") + QubitOperator("Y0 Y1") + QubitOperator("Z0 Z1") + QubitOperator("X0 Y1", 1j) ham = get_sparse_operator(qubit_operator).toarray() exact_sv = np.array([0.+0.j, 0.+0.j, 0.87758256+0.j, -0.47942554+0.j])