Skip to content

Commit

Permalink
[Stable] Prepare 0.1.4 release (#265)
Browse files Browse the repository at this point in the history
* Prepare 0.1.4 release

* Deprecated Location: Improve Windows compatibility (pathlib) for psi4 (#266)

* Update AdaptVQE to new, stateless VQE (#222)

* fix AdaptVQE

which previously used the (now deleted) internal method _evaluate_energy of the VQE

* add reno

Co-authored-by: Steve Wood <[email protected]>

* Bump Terra min. requirement

Co-authored-by: Julien Gacon <[email protected]>
Co-authored-by: Steve Wood <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2021
1 parent c513477 commit db87b4c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion qiskit_nature/VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.3
0.1.4
6 changes: 2 additions & 4 deletions qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ def _compute_gradients(self,
self._ansatz.operators = self._excitation_list + [exc]
# set the current ansatz
vqe.ansatz = self._ansatz
ansatz_params = vqe.ansatz._parameter_table.keys()
# construct the expectation operator of the VQE
vqe._expect_op = vqe.construct_expectation(ansatz_params, self._main_operator)
# evaluate energies
parameter_sets = theta + [-self._delta] + theta + [self._delta]
energy_results = vqe._energy_evaluation(np.asarray(parameter_sets))
energy_evaluation = vqe.get_energy_evaluation(self._main_operator)
energy_results = energy_evaluation(np.asarray(parameter_sets))
# compute gradient
gradient = (energy_results[0] - energy_results[1]) / (2 * self._delta)
res.append((np.abs(gradient), exc))
Expand Down
27 changes: 17 additions & 10 deletions qiskit_nature/drivers/psi4d/psi4driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import subprocess
import sys
import tempfile
from pathlib import Path
from shutil import which
from typing import Union, List, Optional

Expand Down Expand Up @@ -105,19 +106,25 @@ def run(self) -> QMolecule:
else:
cfg = self._config

psi4d_directory = os.path.dirname(os.path.realpath(__file__))
template_file = psi4d_directory + '/_template.txt'
qiskit_chemistry_directory = os.path.abspath(os.path.join(psi4d_directory, '../..'))
psi4d_directory = Path(__file__).resolve().parent
template_file = psi4d_directory.joinpath("_template.txt")
qiskit_nature_directory = psi4d_directory.parent.parent

molecule = QMolecule()

input_text = cfg + '\n'
input_text += 'import sys\n'
syspath = '[\'' + qiskit_chemistry_directory + '\',\'' + '\',\''.join(sys.path) + '\']'

input_text += 'sys.path = ' + syspath + ' + sys.path\n'
input_text += 'from qiskit_nature.drivers.qmolecule import QMolecule\n'
input_text += '_q_molecule = QMolecule("{0}")\n'.format(molecule.filename)
input_text = cfg + "\n"
input_text += "import sys\n"
syspath = (
"['"
+ qiskit_nature_directory.as_posix()
+ "','"
+ "','".join(Path(p).as_posix() for p in sys.path)
+ "']"
)

input_text += "sys.path = " + syspath + " + sys.path\n"
input_text += "from qiskit_nature.drivers.qmolecule import QMolecule\n"
input_text += '_q_molecule = QMolecule("{0}")\n'.format(Path(molecule.filename).as_posix())

with open(template_file, 'r') as file:
input_text += file.read()
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix-adapt-vqe-c9df0c06ea352b91.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
Fix :class:`~qiskit_nature.algorithms.AdaptVQE` after the update of
:class:`~qiskit.algorithms.VQE` which deleted the internal ``_energy_evaluation``
method that Adapt-VQE was relying on.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
qiskit-terra>=0.17.0
qiskit-terra>=0.18.0
scipy>=1.4
numpy>=1.17
psutil>=5
Expand Down

0 comments on commit db87b4c

Please sign in to comment.