Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fermi-Hubbard Model block/interleaved inconsistency #1224

Open
ialsina opened this issue Aug 22, 2023 · 1 comment · May be fixed by #1245
Open

Fermi-Hubbard Model block/interleaved inconsistency #1224

ialsina opened this issue Aug 22, 2023 · 1 comment · May be fixed by #1245
Assignees
Labels

Comments

@ialsina
Copy link

ialsina commented Aug 22, 2023

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!

@mrossinek
Copy link
Member

I think unifying the behavior of the FermiHubbardModel with the block-ordering of the ElectronicEnergy class is a good idea! Please go ahead and open a PR as you had suggested 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants