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

Add UCCSD Initialization #1209

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This code is part of Qiskit.

Check failure on line 1 in qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py

View workflow job for this annotation

GitHub Actions / Checks (ubuntu-latest, 3.8)

would reformat qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py
#
# (C) Copyright IBM 2021, 2023.
#
Expand All @@ -22,9 +22,45 @@


class UCCSD(UCC):
"""The UCCSD Ansatz.

This is a convenience subclass of the UCC ansatz. For more information refer to :class:`UCC`.
r"""The UCCSD Ansatz. This is a convenience subclass of the UCC ansatz. For more information refer to :class:`UCC`.

Check warning on line 26 in qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py

View workflow job for this annotation

GitHub Actions / Nature (ubuntu-latest, 3.7)

C0301: Line too long (119/105) (line-too-long)

This method constructs the requested excitations based on a
:class:`~qiskit_nature.second_q.circuit.library.HartreeFock` reference state as compared to the
default random initial point. First we setup our ansatz and :class:`~qiskit.algorithms.minimum_eigensolvers.VQE`.

Check warning on line 30 in qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py

View workflow job for this annotation

GitHub Actions / Nature (ubuntu-latest, 3.7)

C0301: Line too long (118/105) (line-too-long)

.. code-block:: python

qubit_mapper = JordanWignerMapper()
uccsd = UCCSD(problem.num_spatial_orbitals,
problem.num_particles,
qubit_mapper,
initial_state=HartreeFock(problem.num_spatial_orbitals,
problem.num_particles,
qubit_mapper)
)
vqe = VQE(Estimator(), uccsd, SLSQP())

Since we picked the :class:`~qiskit_nature.second_q.circuit.library.HartreeFock` initial state before, in order to

Check warning on line 44 in qiskit_nature/second_q/circuit/library/ansatzes/uccsd.py

View workflow job for this annotation

GitHub Actions / Nature (ubuntu-latest, 3.7)

C0301: Line too long (118/105) (line-too-long)
ensure we start from that, we need to initialize our ``initial_point`` with all-zero parameters.
We use :class:`~qiskit_nature.second_q.algorithms.initial_points.HFInitialPoint` like so:

.. code-block:: python

initial_point = HFInitialPoint()
initial_point.ansatz = uccsd
initial_point.problem = problem
vqe.initial_point = initial_point.to_numpy_array()

Keep in mind, that in all of the examples above we have not set any of the following keyword
arguments, which must be specified before the ansatz becomes usable:

- ``num_particles``
- ``num_spatial_orbitals``

If you are using this ansatz with a Qiskit Nature algorithm, these arguments will be set for
you, depending on the rest of the stack.

"""

@deprecate_arguments(
Expand Down
Loading