Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated execution #34

Open
alecandido opened this issue Jun 18, 2024 · 4 comments
Open

Repeated execution #34

alecandido opened this issue Jun 18, 2024 · 4 comments

Comments

@alecandido
Copy link
Member

We should reconsider how repeated execution is being triggered, and when it is possible to enable it automatically.

The extreme option is to have a single execute_circuit function with no flag at all, just decide whether to execute

  • state vector simulation
  • density matrix simulation
  • shots execution

just based on the content of the Circuit and the initial_state.

Cf.:

@renatomello
Copy link
Collaborator

renatomello commented Jun 18, 2024 via email

@alecandido
Copy link
Member Author

What I mean is not avoiding being explicit, but just avoiding duplicated features (even now, execute_circuit might trigger execute_repeated_circuits)
https://github.com/qiboteam/qibo/blob/70901d598ad77ca43abf1d9b3673608206cc6099/src/qibo/backends/numpy.py#L404-L406
and the need for manually removing portions of "phase space" (through error raising)
https://github.com/qiboteam/qibo/blob/70901d598ad77ca43abf1d9b3673608206cc6099/src/qibo/backends/numpy.py#L407-L410

If there is an error, it means that there is an invalid combination of inputs. It'd be better if most of the inputs' combinations are valid, preserving at the same time the meaning of the parameters (avoiding the usage of weird combinations, leading to poor understanding by users), and if there were only one way of doing things (cf. PEP 20), and not many different combinations of invocations leading to the same result.

The proposal in the comments was along the line:

  • to trigger a density matrix simulation, you need an explicit density matrix initial state (flagged by shape or type) - in that case, and only in that case, a density matrix simulation is always run
  • if the circuit is unitary, a state vector simulation is run, being the initial state a state vector or None
  • if the circuit is non-unitary (because it contains channels, or collapsing measurements), repeated execution is triggered

This should reproduce the behavior of the current Qibo (more or less, since it extracts more information from the initial_state parameter) but with a single public function, and just two parameters.

@renatomello
Copy link
Collaborator

renatomello commented Jun 19, 2024

What I mean is not avoiding being explicit, but just avoiding duplicated features (even now, execute_circuit might trigger execute_repeated_circuits) https://github.com/qiboteam/qibo/blob/70901d598ad77ca43abf1d9b3673608206cc6099/src/qibo/backends/numpy.py#L404-L406 and the need for manually removing portions of "phase space" (through error raising) https://github.com/qiboteam/qibo/blob/70901d598ad77ca43abf1d9b3673608206cc6099/src/qibo/backends/numpy.py#L407-L410

If there is an error, it means that there is an invalid combination of inputs. It'd be better if most of the inputs' combinations are valid, preserving at the same time the meaning of the parameters (avoiding the usage of weird combinations, leading to poor understanding by users), and if there were only one way of doing things (cf. PEP 20), and not many different combinations of invocations leading to the same result.

The proposal in the comments was along the line:

* to trigger a density matrix simulation, you need an explicit density matrix initial state (flagged by shape or type) - in that case, and only in that case, a density matrix simulation is always run

* if the circuit is _unitary_, a state vector simulation is run, being the initial state a state vector or `None`

* if the circuit is _non-unitary_ (because it contains channels, or collapsing measurements), repeated execution is triggered

This should reproduce the behavior of the current Qibo (more or less, since it extracts more information from the initial_state parameter) but with a single public function, and just two parameters.

Maybe we have a nomenclature conflict here.

Repeated execution, as I always understood and as is stated in the Qibo doc here, is about simulating noise models on statevectors probabilistically instead of exact noisy simulation on density matrices. In the limit of infinite samples, the former converges to the latter.
A regular circuit with collapsing measurements do not require "repeated execution" under this definition of repeated execution.

Note that, in principle, "repeated execution" as defined above is independent of the presence of measurement gates in the circuit.
However, its current implementation requires measurements.
Moreover, repeated execution only makes sense for noise channels that are described by a linear combination of unitaries, which is not the case for e.g. a generic ReadoutErrorChannel or a generic KrausChannel.

In any case, I wouldn't advise on defaulting to "repeated execution" if the combination of noise channels and statevector simulation is true. That may lead to misunderstanding because the results wouldn't be exact but could be naively interpreted as such. On the other hand, the current requirements are noise channels + statevector simulation + measurements. But those are not necessary conditions, since measurements are not necessary as I stated above.

Maybe an extra boolean flag is needed, or the triggering of repeated execution also triggers a warning saying that the simulation won't be exact.

@alecandido
Copy link
Member Author

alecandido commented Jun 19, 2024

Maybe an extra boolean flag is needed, or the triggering of repeated execution also triggers a warning saying that the simulation won't be exact.

Even better: instead of raising a warning, we could return an object explicitly telling that is coming from repeated execution (as a result object with a flag set to "not exact").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants