Esempio n. 1
0
 def get_optimal_vector(self):
     if 'opt_params' not in self._ret:
         raise AquaError("Cannot find optimal vector before running the algorithm to find optimal params.")
     qc = self.get_optimal_circuit()
     if self._quantum_instance.is_statevector:
         ret = self._quantum_instance.execute(qc)
         self._ret['min_vector'] = ret.get_statevector(qc, decimals=16)
     else:
         c = ClassicalRegister(qc.width(), name='c')
         q = find_regs_by_name(qc, 'q')
         qc.add_register(c)
         qc.barrier(q)
         qc.measure(q, c)
         ret = self._quantum_instance.execute(qc)
         self._ret['min_vector'] = ret.get_counts(qc)
     return self._ret['min_vector']
Esempio n. 2
0
 def _solve(self):
     opt_params, opt_val = self.find_minimum_eigenvalue()
     self._ret['eigvals'] = np.asarray([opt_val])
     self._ret['opt_params'] = opt_params
     qc = self._var_form.construct_circuit(self._ret['opt_params'])
     if self._quantum_instance.is_statevector:
         ret = self._quantum_instance.execute(qc)
         self._ret['eigvecs'] = np.asarray([ret.get_statevector(qc)])
     else:
         c = ClassicalRegister(self._operator.num_qubits, name='c')
         q = find_regs_by_name(qc, 'q')
         qc.add_register(c)
         qc.barrier(q)
         qc.measure(q, c)
         ret = self._quantum_instance.execute(qc)
         self._ret['eigvecs'] = np.asarray([ret.get_counts(qc)])