-
Notifications
You must be signed in to change notification settings - Fork 226
Open
Labels
Description
Environment
- Qiskit Nature version: 343d290
- Python version: 3.9.16
- Operating system: RHEL 8.8
What is happening?
Since the introduction of InterleavedQubitMapper (#1046) the FermiHubbardModel class doesn't behave consistently with this feature, producing an interleaved-encoded hamiltonian when used together with JordanWignerMapper, and a block-encoded hamiltonian when used together with InterleavedQubitMapper.
How can we reproduce the issue?
>>> from qiskit_nature import settings
>>> from qiskit_nature.second_q.hamiltonians import FermiHubbardModel
>>> from qiskit_nature.second_q.hamiltonians.lattices import LineLattice
>>> from qiskit_nature.second_q.mappers import JordanWignerMapper, InterleavedQubitMapper
>>> settings.use_pauli_sum_op = False
>>> lattice = LineLattice(2)
>>> model = FermiHubbardModel(
lattice.uniform_parameters(
uniform_interaction=-1.,
uniform_onsite_potential=0.
),
onsite_interaction=1.
)
>>> hamiltonian = model.second_q_op().simplify()
>>> print(hamiltonian)
FermionicOp({'+_0 -_2': (-1+0j), '-_0 +_2': (1+0j), '+_1 -_3': (-1+0j), '-_1 +_3': (1+0j), '+_0 -_0 +_1 -_1': (1+0j), '+_2 -_2 +_3 -_3': (1+0j)}, num_spin_orbitals=4, )
>>> mapper = JordanWignerMapper()
>>> print(mapper.map(hamiltonian)) # Block encoding
SparsePauliOp(['IYZY', 'IXZX', 'YZYI', 'XZXI', 'IIII', 'IIZI', 'IIIZ', 'IIZZ', 'ZIII', 'IZII', 'ZZII'],
coeffs=[-0.5 +0.j, -0.5 +0.j, -0.5 +0.j, -0.5 +0.j, 0.5 +0.j, -0.25+0.j,
-0.25+0.j, 0.25+0.j, -0.25+0.j, -0.25+0.j, 0.25+0.j])
>>> interleaved_mapper = InterleavedQubitMapper(mapper)
>>> print(interleaved_mapper.map(hamiltonian)) # Interleaved encoding
SparsePauliOp(['IIYY', 'IIXX', 'YYII', 'XXII', 'IIII', 'IZII', 'IIIZ', 'IZIZ', 'ZIII', 'IIZI', 'ZIZI'],
coeffs=[-0.5 +0.j, -0.5 +0.j, -0.5 +0.j, -0.5 +0.j, 0.5 +0.j, -0.25+0.j,
-0.25+0.j, 0.25+0.j, -0.25+0.j, -0.25+0.j, 0.25+0.j])
What should happen?
For consistency with the other uses of JordanWignerMapper and InterleavedQubitMapper, the outcomes of the prints should be:
>>> hamiltonian = model.second_q_op().simplify()
>>> print(hamiltonian)
FermionicOp({'+_0 -_1': (-1+0j), '-_0 +_1': (1+0j), '+_2 -_3': (-1+0j), '-_2 +_3': (1+0j), '+_0 -_0 +_2 -_2': (1+0j), '+_1 -_1 +_3 -_3': (1+0j)}, num_spin_orbitals=4, )
>>> mapper = JordanWignerMapper()
>>> print(mapper.map(hamiltonian)) # Block encoding
SparsePauliOp(['IIYY', 'IIXX', 'YYII', 'XXII', 'IIII', 'IZII', 'IIIZ', 'IZIZ', 'ZIII', 'IIZI', 'ZIZI'],
coeffs=[-0.5 +0.j, -0.5 +0.j, -0.5 +0.j, -0.5 +0.j, 0.5 +0.j, -0.25+0.j,
-0.25+0.j, 0.25+0.j, -0.25+0.j, -0.25+0.j, 0.25+0.j])
>>> interleaved_mapper = InterleavedQubitMapper(mapper)
>>> print(interleaved_mapper.map(hamiltonian)) # Interleaved encoding
SparsePauliOp(['IYZY', 'IXZX', 'YZYI', 'XZXI', 'IIII', 'IIZI', 'IIIZ', 'IIZZ', 'ZIII', 'IZII', 'ZZII'],
coeffs=[-0.5 +0.j, -0.5 +0.j, -0.5 +0.j, -0.5 +0.j, 0.5 +0.j, -0.25+0.j,
-0.25+0.j, 0.25+0.j, -0.25+0.j, -0.25+0.j, 0.25+0.j])
Any suggestions?
In qiskit_nature/second_q/hamiltonians/fermi_hubbard_model.py, change the "index" variables everywhere from index = 2 * node + spin to index = node + spin * num_nodes. I am happy to open a PR with this change!