Closed andrew-koren closed 4 months ago
I have a poor-mans solution, I changed the QubitHamiltonian class
@property
def n_qubits(self):
return len(self.qubits)
to
@property
def n_qubits(self):
self.qubits[-1]+1
Which selects the value of the largest qubit number and adds 1 for 0-indexing. This allowed the binary hamiltonian to be made without error and function correctly for my purposes.
Hi,
Thanks for reporting the bug. The issue should be resolved with the latest pull request to the devel
branch. This fix will soon be available in the master branch/PyPI release, providing a reliable solution to the problem you encountered.
In the meantime you can upgrade with
pip install --upgrade git+https://github.com/tequilahub/tequila.git@devel
If the problem persists please let us know again.
I couldn't use the proposed fix as this would break the package in other instances. Overall, the contention is that .n_qubits
always gives back the number of qubits where non-trivial actions occur. Tequila is then able to map to smaller qubit systems before simulating (an application where this often pays off is adapt-vqe calculations, where in the beginning, the circuit is not acting on all the qubits).
Example:
if you are initializing
U = tq.gates.H(target=10) + tq.gates.X(target=15, control=10)
H = tq.paulis.X(10) + tq.paulis.Y(15) + tq.paulis.Z(200)
E = tq.ExpextationValue(H=H, U=U)
result= tq.simulate(E)
before compiling to the simulation backend tequila will map the circuit to a 2-qubit circuit, send this circuit to the simulator, and will afterwards map the result back. The Pauli-Z in the Hamiltonian will be traced out in the preprocessing.
Describe the bug An error occurs when trying to initialize a binary hamiltonian from qubit hamiltonian when the qubit hamiltoian has identity in it.
To Reproduce Steps to reproduce the behavior: Ideally an executable code snipped like
Expected behavior Should create Binary Hamiltonian without throwing error
Computer (please complete the following information):