def test_annotating_probs(self, wires): with AnnotatedQueue() as q: probs(wires) assert len(q.queue) == 1 meas_proc = q.queue[0] assert isinstance(meas_proc, MeasurementProcess) assert meas_proc.return_type == Probability
def test_annotating_obs_return_type(self, stat_func, return_type, op): """Test that the return_type related info is updated for a measurement""" with AnnotatedQueue() as q: A = op(0) stat_func(A) assert q.queue[:-1] == [A] meas_proc = q.queue[-1] assert isinstance(meas_proc, MeasurementProcess) assert meas_proc.return_type == return_type assert q._get_info(A) == {"owner": meas_proc} assert q._get_info(meas_proc) == {"owns": (A)}
def test_annotating_tensor_hermitian(self, stat_func, return_type): """Test that the return_type related info is updated for a measurement when called for an Hermitian observable""" mx = np.array([[1, 0], [0, 1]]) with AnnotatedQueue() as q: Herm = qml.Hermitian(mx, wires=[1]) stat_func(Herm) assert q.queue[:-1] == [Herm] meas_proc = q.queue[-1] assert isinstance(meas_proc, MeasurementProcess) assert meas_proc.return_type == return_type assert q._get_info(Herm) == {"owner": meas_proc} assert q._get_info(meas_proc) == {"owns": (Herm)}
def test_annotating_tensor_return_type(self, op1, op2, stat_func, return_type): """Test that the return_type related info is updated for a measurement when called for an Tensor observable""" with AnnotatedQueue() as q: A = op1(0) B = op2(1) tensor_op = A @ B stat_func(tensor_op) assert q.queue[:-1] == [A, B, tensor_op] meas_proc = q.queue[-1] assert isinstance(meas_proc, MeasurementProcess) assert meas_proc.return_type == return_type assert q._get_info(A) == {"owner": tensor_op} assert q._get_info(B) == {"owner": tensor_op} assert q._get_info(tensor_op) == {"owns": (A, B), "owner": meas_proc}