SymbolicHamiltonian
as a callback leading to mismatched circuit sizes
#1418
Labels
bug
Something isn't working
Describe the bug
Facing an issue when using a SymbolicHamiltonian as a callback for a circuit. The issue occurs because SymbolicHamiltonian is assumes that it acts on the highest qubit number that any of its terms acts on, and there is no way to override this behavior. I will demonstrate:
To Reproduce
results in the following error:
[Qibo 0.2.10|ERROR|2024-08-08 11:50:52]: Cannot multiply Hamiltonian on 1 qubits to state of 6 qubits. ERROR:qibo.config:Cannot multiply Hamiltonian on 1 qubits to state of 6 qubits.
This can be 'fixed' by modifying the definition of P by artificially adding a term that acts on the final qubit. So replacing this line:
P.terms = [hamiltonians.terms.HamiltonianTerm(matrices.Z, 0)]
with this:
P.terms = [hamiltonians.terms.HamiltonianTerm(matrices.Z, 0), hamiltonians.terms.HamiltonianTerm(0.0*matrices.I,L-1)]
This is quite inelegant in my opinion. Maybe there should be an optional parameter in SymbolicHamiltonian where I can specify how many qubits it acts on.
The text was updated successfully, but these errors were encountered: