horqrux icon indicating copy to clipboard operation
horqrux copied to clipboard

[Discussion] How to handle multiple observations

Open atiyo opened this issue 6 months ago • 1 comments

TLDR: Currently when we ask for observables = [Z(0), Z(1)], in an expectation, we get something like <state|Z(0) Z(1)|state>, but I think it'd be more useful if we returned [<state|Z(0)|state>, <state|Z(1)|state> ] and so this issue is to discuss this potentially breaking change.


As it currently stands, when we provide a list of observables to an expectation, the observables are applied sequentially before a measurement is taken. i.e.

https://github.com/pasqal-io/horqrux/blob/2824f4b3fc44285694158c8d6bd1ea77672f7e98/horqrux/api.py#L54-L63

A GateSequence can be thought of as a list[Primitive] above. So passing something like observable = [Z(0), Z(1)] yields something like <gates| Z(0) Z(1) | gates>, with an abuse of notation.

This feels a little off (to me) for two reasons:

  • We are not providing the ability to take multiple observations per shot. In the case of exact expectations, we can
  • The composition of Hermitian matrices is not (generally) Hermitian, so the current implementation of allowing compositions of observables does not seem like it'd be useful for end users.

Presumably we would like to make it easier to sample multiple observations per shot in an easy way. The main question is what this should look like?

My preferred solution is to repurpose the interpretation of observable so that we return an expectation for each element in observable, while respecting the correlations between different observables.

However, this is a breaking change and fundamentally changes the behaviour of functions in API. Hence, I thought it good to open a discussion on this.

Any thoughts? @jpmoutinho @Roland-djee @gvelikova

atiyo avatar Jul 29 '24 13:07 atiyo