Skip to content
This repository has been archived by the owner on Dec 7, 2021. It is now read-only.

Added time prints of VQE to the log #798

Merged
merged 2 commits into from
Jan 30, 2020
Merged
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
14 changes: 13 additions & 1 deletion qiskit/aqua/algorithms/adaptive/vqe/vqe.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Optional, List, Callable
import logging
import functools
from time import time

import numpy as np
from qiskit import ClassicalRegister, QuantumCircuit
Expand Down Expand Up @@ -333,6 +334,7 @@ def _build_parameterized_circuits():
circuits.append(circuit)
to_be_simulated_circuits = functools.reduce(lambda x, y: x + y, circuits)

start_time = time()
result = self._quantum_instance.execute(to_be_simulated_circuits,
self._parameterized_circuits is not None)

Expand All @@ -341,12 +343,22 @@ def _build_parameterized_circuits():
result=result, statevector_mode=self._quantum_instance.is_statevector,
use_simulator_snapshot_mode=self._use_simulator_snapshot_mode,
circuit_name_prefix=str(idx))
end_time = time()
mean_energy.append(np.real(mean))
std_energy.append(np.real(std))
self._eval_count += 1
if self._callback is not None:
self._callback(self._eval_count, parameter_sets[idx], np.real(mean), np.real(std))
logger.info('Energy evaluation %s returned %s', self._eval_count, np.real(mean))

# If there is more than one parameter set then the calculation of the
# evaluation time has to be done more carefully,
# therefore we do not calculate it
if len(parameter_sets) == 1:
logger.info('Energy evaluation %s returned %s - %.5f (ms)',
self._eval_count, np.real(mean), (end_time - start_time) * 1000)
else:
logger.info('Energy evaluation %s returned %s',
self._eval_count, np.real(mean))

return mean_energy if len(mean_energy) > 1 else mean_energy[0]

Expand Down