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

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

Open
MattePalte opened this issue Jan 31, 2024 · 2 comments

Comments

@MattePalte
Copy link

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

@MattePalte
Copy link
Author

@MattePalte
Copy link
Author

A similar one in:

ansatz.compose(init_state, front=True)

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

No branches or pull requests

1 participant