qiboteam / qibo

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

Complex numbers in samples and frequencies #1412

Closed marekgluza closed 1 month ago

marekgluza commented 1 month ago

We have been submitting jobs to qw5q_platinum using the latest qibolab release 0.1.8 (module load qibo)

import qibo
c = qibo.Circuit(5)
c.add(qibo.gates.GPI2(0,0))
c.add(qibo.gates.M(0,1,2,3,4))
result = c(nshots=100)
print(result.samples())

when we switch to frequencies it also fails because the results variables are complex

marekgluza commented 1 month ago

probabilities also catches that

Traceback (most recent call last):
  File "/nfs/users/marek.gluza/h.py", line 26, in <module>
    print(result.probabilities())
  File "/nfs/tools/qibo/lib/python3.10/site-packages/qibo/result.py", line 288, in probabilities
    probs[state] = freq / self.nshots
TypeError: list indices must be integers or slices, not complex
stavros11 commented 1 month ago

Thanks @marekgluza for reporting this. I could reproduce.

After a quick investigation it seems to be related to the latest release of qibo (0.2.10). If you create your own environment and force the previous release (pip install qibo==0.2.9) the issue should not appear. I will check the list of PRs in the latest release to see if I can identify which change caused this and update if I find something.

alecandido commented 1 month ago

Thanks @marekgluza for reporting, and @stavros11 for the investigation. I thought for a moment that this could be related to the Rust failures, but unless it's a problem in the dependencies, it should be unrelated (since execute_qasm() should not pass through qibo, unless for just this part: https://github.com/qiboteam/qibolab/blob/4f1459444a88666bad3b360dd728b0b88fa9c366/src/qibolab/backends.py#L74-L75 and the MeasurementOutcome object (which should be just a sterile container).

In any case, @stavros11, if you find anything new, please publish it here (in case of greater issues, I will also take a look at some point).

scarrazza commented 1 month ago

This bug was introduced in https://github.com/qiboteam/qibo/commit/6cc64b3bba26f325e0d8d19558bb11adce8f16fe. Btw, we should include some test to avoid this issue in the future.

renatomello commented 1 month ago

I could not reproduce it, even though I installed qibo from master, tried samples, frequencies, and probabilities, and tried every backend available.

scarrazza commented 1 month ago

@renatomello, you have to try this code with the qibolab backend. In this case we are using qw5q_platinum.