Qaqarot / qaqarot

Quantum Computer Library for Everyone
Apache License 2.0
371 stars 53 forks source link

[VQE] When Hamiltonian is constant, ValueError is raised #89

Closed gyu-don closed 4 years ago

gyu-don commented 4 years ago

Code:

from blueqat.pauli import I
from blueqat import Circuit
from blueqat.vqe import *

h = 3 * I
runner = Vqe(QaoaAnsatz(h.to_expr()))
runner.run()

Error:

Traceback (most recent call last):
  File "bug_constant_hamiltonian.py", line 6, in <module>
    runner = Vqe(QaoaAnsatz(h.to_expr()))
  File "/home/penguin/blueqat/blueqat/vqe.py", line 64, in __init__
    super().__init__(hamiltonian, step * 2)
  File "/home/penguin/blueqat/blueqat/vqe.py", line 30, in __init__
    self.n_qubits = self.hamiltonian.max_n() + 1
  File "/home/penguin/blueqat/blueqat/pauli.py", line 709, in max_n
    return max(term.max_n() for term in self.terms if term.ops)
ValueError: max() arg is an empty sequence
gyu-don commented 4 years ago

This bug is solved in #97.