diff --git a/qiskit_nature/VERSION.txt b/qiskit_nature/VERSION.txt index b1e80bb248..845639eef2 100644 --- a/qiskit_nature/VERSION.txt +++ b/qiskit_nature/VERSION.txt @@ -1 +1 @@ -0.1.3 +0.1.4 diff --git a/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py b/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py index 56b0b0fc9b..2183642584 100644 --- a/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py +++ b/qiskit_nature/algorithms/ground_state_solvers/adapt_vqe.py @@ -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)) diff --git a/qiskit_nature/drivers/psi4d/psi4driver.py b/qiskit_nature/drivers/psi4d/psi4driver.py index f98c799d10..039e6becfd 100644 --- a/qiskit_nature/drivers/psi4d/psi4driver.py +++ b/qiskit_nature/drivers/psi4d/psi4driver.py @@ -17,6 +17,7 @@ import subprocess import sys import tempfile +from pathlib import Path from shutil import which from typing import Union, List, Optional @@ -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() diff --git a/releasenotes/notes/fix-adapt-vqe-c9df0c06ea352b91.yaml b/releasenotes/notes/fix-adapt-vqe-c9df0c06ea352b91.yaml new file mode 100644 index 0000000000..ef17353356 --- /dev/null +++ b/releasenotes/notes/fix-adapt-vqe-c9df0c06ea352b91.yaml @@ -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. diff --git a/requirements.txt b/requirements.txt index 0ddf250899..87b8b32f52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -qiskit-terra>=0.17.0 +qiskit-terra>=0.18.0 scipy>=1.4 numpy>=1.17 psutil>=5