# expectation value of a noisy system

I'm trying to find the expectation value of an operator using a noisy circuit and this is the code I found:

obs = Observable(PauliString("Z"))

prob_1 = 0.005

prob_2 = 0.01

error_1 = noise.depolarizing_error(prob_1, 1)

noise_model = noise.NoiseModel()

def sim_noise(qc, obs : npt.NDArray[np.complex64])-> float:
return execute_with_shots_and_noise(qc, obs, noise_model , 4096)

def sim(qc, obs : npt.NDArray[np.complex64])-> float:
return execute_with_shots(qc, obs, 4096)

ideal_measurement = obs.expectation(get_circuit(), sim_noise).real.


I keep getting this error:

ValueError: Executor and observable are not compatible. Executors
returning expectation values as float must be used with
observable=None.


I couldn't figure out how to fix it.

New contributor
user184655 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.