Skip to content

Ignored Initial State in VQE Ansatz due to Non-Reassigned compose Call #2

@MattePalte

Description

@MattePalte

Environment

  • qiskit.version: 0.25.1
  • Python version: 3.8.0
  • Operating system: Ubuntu 20.04

What is happening?

In the Python file neoh2evo.py, the ansatz.compose(init_state, front=True) call is effectively ignored because the returned value is not reassigned and the argument inplace is not used. As a result, there is no initial state in the ansatz passed to the VQE.

How can we reproduce the issue?

Run the following code in the Python file:

...
# setup the initial state for the ansatz
from qiskit_mod.qiskit_nat import NeoHartreeFock

init_state = NeoHartreeFock(2*num_spin_orbitals, mixnum_particles, converter)

# setup the ansatz for VQE
from qiskit.circuit.library import TwoLocal

ansatz = TwoLocal(2*num_spin_orbitals, ['ry', 'rz'], 'cz',reps=2)

# add the initial state
ansatz.compose(init_state, front=True)

ansatz.draw()  # <-- this will not include the initial state

What should happen?

I would have expected the initial state to be included in the ansatz passed to the VQE.

Any Suggestions?

The ansatz.compose(init_state, front=True) call should be reassigned to ansatz or the inplace=True argument should be used to ensure the initial state is included in the ansatz passed to the VQE. Here is the suggested version:

# add the initial state
ansatz = ansatz.compose(init_state, front=True)

or

# add the initial state
ansatz.compose(init_state, front=True, inplace=True)

Thanks in advance, I wish you a happy and productive day

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions