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

Does not work with QASM Simulator #2

Open
cryotheta opened this issue Jun 6, 2022 · 0 comments
Open

Does not work with QASM Simulator #2

cryotheta opened this issue Jun 6, 2022 · 0 comments

Comments

@cryotheta
Copy link

Hi, the code does not seem to work when qasm_simulator is chosen. And leads to the following error:

backend = Aer.get_backend('qasm_simulator')  # use this for QASM simulator


QiskitError Traceback (most recent call last)
Input In [13], in <cell line: 5>()
5 for alpha in alphas:
6 objectives[alpha] = Objective(var_form, H, offset, alpha, backend, optimal=optimal_value)
----> 7 optimizer.optimize(m, objectives[alpha].evaluate, initial_point=initial_point)

File ~\Anaconda3\lib\site-packages\qiskit\algorithms\optimizers\scipy_optimizer.py:158, in SciPyOptimizer.optimize(self, num_vars, objective_function, gradient_function, variable_bounds, initial_point)
147 def optimize(
148 self,
149 num_vars,
(...)
153 initial_point=None,
154 ):
155 super().optimize(
156 num_vars, objective_function, gradient_function, variable_bounds, initial_point
157 )
--> 158 result = self.minimize(
159 objective_function, initial_point, gradient_function, variable_bounds
160 )
161 return result.x, result.fun, result.nfev

File ~\Anaconda3\lib\site-packages\qiskit\algorithms\optimizers\scipy_optimizer.py:129, in SciPyOptimizer.minimize(self, fun, x0, jac, bounds)
126 if jac is not None and self._method == "l-bfgs-b":
127 jac = self._wrap_gradient(jac)
--> 129 raw_result = minimize(
130 fun=fun,
131 x0=x0,
132 method=self._method,
133 jac=jac,
134 bounds=bounds,
135 options=self._options,
136 **self._kwargs,
137 )
138 result = OptimizerResult()
139 result.x = raw_result.x

File ~\Anaconda3\lib\site-packages\scipy\optimize_minimize.py:629, in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
626 return _minimize_tnc(fun, x0, args, jac, bounds, callback=callback,
627 **options)
628 elif meth == 'cobyla':
--> 629 return _minimize_cobyla(fun, x0, args, constraints, **options)
630 elif meth == 'slsqp':
631 return _minimize_slsqp(fun, x0, args, jac, bounds,
632 constraints, callback=callback, **options)

File ~\Anaconda3\lib\site-packages\scipy\optimize\cobyla.py:34, in synchronized..wrapper(*args, **kwargs)
31 @functools.wraps(func)
32 def wrapper(*args, **kwargs):
33 with _module_lock:
---> 34 return func(*args, **kwargs)

File ~\Anaconda3\lib\site-packages\scipy\optimize\cobyla.py:260, in _minimize_cobyla(fun, x0, args, constraints, rhobeg, tol, maxiter, disp, catol, **unknown_options)
257 return f
259 info = np.zeros(4, np.float64)
--> 260 xopt, info = _cobyla.minimize(calcfc, m=m, x=np.copy(x0), rhobeg=rhobeg,
261 rhoend=rhoend, iprint=iprint, maxfun=maxfun,
262 dinfo=info)
264 if info[3] > catol:
265 # Check constraint violation
266 info[0] = 4

File ~\Anaconda3\lib\site-packages\scipy\optimize\cobyla.py:252, in _minimize_cobyla..calcfc(x, con)
251 def calcfc(x, con):
--> 252 f = fun(np.copy(x), *args)
253 i = 0
254 for size, c in izip(cons_lengths, constraints):

Input In [12], in Objective.evaluate(self, thetas)
20 job = execute(qc, self.backend)
21 result = job.result()
---> 22 counts = result.get_counts()
24 # evaluate counts
25 probabilities = np.zeros(len(counts))

File ~\Anaconda3\lib\site-packages\qiskit\result\result.py:300, in Result.get_counts(self, experiment)
298 dict_list.append(statevector.Statevector(vec).probabilities_dict(decimals=15))
299 else:
--> 300 raise QiskitError(f'No counts for experiment "{repr(key)}"')
302 # Return first item of dict_list if size is 1
303 if len(dict_list) == 1:

QiskitError: 'No counts for experiment "0"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant