qiboteam / qibo

A full-stack framework for quantum computing.
https://qibo.science
Apache License 2.0
297 stars 61 forks source link

The max index of qubits in gates.CU1 is out ranged in qibo/src/qibo/models /hep.py #1497

Open Landau1908 opened 1 month ago

Landau1908 commented 1 month ago

Describe the bug A minimun example: if nqubits =even number, it works, otherwise, it doesn't work.

from qibo.ui import plot_circuit
from qibo.models.hep import qPDF

ansatz = 'Weighted'
multi_output = True
layers = 3
nqubits = 7

mypdf = qPDF(ansatz, layers, nqubits, multi_output=multi_output)
plot_circuit(mypdf.circuit, scale = 0.8, cluster_gates = True, style="quantumspain")

Ouputs:

Traceback (most recent call last):

  Cell In[7], line 1
    plot_circuit(mypdf.circuit, scale = 0.8, cluster_gates = True, style="quantumspain")

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:729 in plot_circuit
    ax = _plot_quantum_schedule(gates_cluster, inits, params, labels, scale=scale)

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:59 in _plot_quantum_schedule
    return _plot_quantum_circuit(

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:120 in _plot_quantum_circuit
    _draw_gates(

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:180 in _draw_gates
    _draw_controls(

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:198 in _draw_controls
    control_indices = _get_flipped_indices(controls, labels)

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:472 in _get_flipped_indices
    return [_get_flipped_index(t, labels) for t in targets]

  File E:\ProgramData\Lib\site-packages\qibo\ui\mpldrawer.py:445 in _get_flipped_index
    i = labels.index(target)

ValueError: 'q_7' is not in list

Expected behavior After reading the code (qibo/src/qibo/models /hep.py), this error is induced by this line

for q in range(1, qubits + 1, 2):

which should be corrected to

for q in range(1, qubits + 0, 2):

There are total 4 lines should be corrected: Line163,193,237,260

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

MatteoRobbiati commented 1 month ago

Thanks for opening this @Landau1908! I just checked if the dedicated Qibo qPDF example works and I can confirm everything is fine from that side.

Could you please complete the Describe the bug section pasting the source code which is generating the error?