qiboteam / qibo

A framework for quantum computing
https://qibo.science
Apache License 2.0
288 stars 56 forks source link

Cyclic dependence of gate `M` and `MeasurementResult` #1433

Open BrunoLiegiBastonLiegi opened 2 weeks ago

BrunoLiegiBastonLiegi commented 2 weeks ago

Currently the gate M and the MeasurementResult object cyclically depend on each other: https://github.com/qiboteam/qibo/blob/f20f4330fe62ce7bc022b687cf6559f2fbc1b50c/src/qibo/gates/measurements.py#L59 https://github.com/qiboteam/qibo/blob/f20f4330fe62ce7bc022b687cf6559f2fbc1b50c/src/qibo/measurements.py#L83

I would argue that this is not really necessary and introduces unneeded complications. The MeasurementResult, indeed, appears to be using the .measurement_gate just to retrieve the qubits (.measurement_gate.target_qubits). For this reason, I would propose to remove this dependence and, for instance, build a MeasurementResult object just starting from the measured qubit indices, rather than the whole measurement gate (as discussed in #1431 already).

alecandido commented 2 weeks ago

build a MeasurementResult object just starting from the measured qubit indices, rather than the whole measurement gate

In principle, you could even avoid storing indices in there, since they are already in the gate (it would be redundant information). For methods that require that (which actually only require the number of measured qubits) you could even get it as an argument, or, even better, infer from the shots shape (since they are the results for a single gate, and the number of qubits to which the gate is applied should match one of the dimensions of the shots shape).