1
$\begingroup$

I am using Qiskit to implement QAOA for a max-cut problem. I am using inbuilt qiskit implemetation of QAOA and, the MinimuEigenOptimizer. The MinimuEigenOptimizer.solve() throws the warning.

AttributeError: 'SparsePauliOp' object has no attribute 'primitive_strings'

I am new to Qiskit, any help will be appreciated!

Below is the code:

from qiskit.algorithms import QAOA
from qiskit_optimization.algorithms import MinimumEigenOptimizer
backend = Aer.get_backend('statevector_simulator')
qaoa = QAOA(optimizer = ADAM(), quantum_instance = backend, reps=1, initial_point=[0.1,0.1])
eigen_optimizer = MinimumEigenOptimizer(min_eigen_solver = qaoa)
quadratic_program = quadratic_program_from_graph(graphs['custom'])
result = eigen_optimizer.solve(quadratic_program)
print(result)

the deprecation warning: The class qiskit.algorithms.minimum_eigen_solvers.qaoa.QAOA is deprecated as of qiskit-terra 0.24.0. It will be removed no earlier than 3 months after the release date. Instead, use the class qiskit.algorithms.minimum_eigensolvers.QAOA. See https://qisk.it/algo_migration for a migration guide.

and the warning:

AttributeError                            Traceback (most recent call last) 
Cell In[59], line 7
      5 eigen_optimizer = MinimumEigenOptimizer(min_eigen_solver = qaoa)
      6 quadratic_program = quadratic_program_from_graph(graphs['custom'])
----> 7 result = eigen_optimizer.solve(quadratic_program)
      8 print(result)

File ~\anaconda3\envs\QAlgobase\Lib\site-  packages\qiskit_optimization\algorithms\minimum_eigen_optimizer.py:205, in     MinimumEigenOptimizer.solve(self, problem)
    202 # construct operator and offset
    203 operator, offset = problem_.to_ising()
--> 205 return self._solve_internal(operator, offset, problem_, problem)

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit_optimization\algorithms\minimum_eigen_optimizer.py:218, in MinimumEigenOptimizer._solve_internal(self, operator, offset, converted_problem, original_problem)
    215 eigen_result: Optional[MinimumEigensolverResult] = None
    216 if operator.num_qubits > 0:
    217     # approximate ground state of operator using min eigen solver
--> 218     eigen_result = self._min_eigen_solver.compute_minimum_eigenvalue(operator)
    219     # analyze results
    220     raw_samples = None

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\vqe.py:536, in VQE.compute_minimum_eigenvalue(self, operator, aux_operators)
    533     gradient = self._gradient
    535 self._eval_count = 0
--> 536 energy_evaluation, expectation = self.get_energy_evaluation(
    537     operator, return_expectation=True
    538 )
    540 start_time = time()
    542 if callable(self.optimizer):

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\vqe.py:613, in VQE.get_energy_evaluation(self, operator, return_expectation)
    610     raise RuntimeError("The ansatz must be parameterized, but has 0 free parameters.")
    612 ansatz_params = self.ansatz.parameters
--> 613 expect_op, expectation = self.construct_expectation(
    614     ansatz_params, operator, return_expectation=True
    615 )
    617 def energy_evaluation(parameters):
    618     parameter_sets = np.reshape(parameters, (-1, num_parameters))

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\vqe.py:431, in VQE.construct_expectation(self, parameter, operator, return_expectation)
    429 # if expectation was never created, try to create one
    430 if self.expectation is None:
--> 431     expectation = ExpectationFactory.build(
    432         operator=operator,
    433         backend=self.quantum_instance,
    434         include_custom=self._include_custom,
    435     )
    436 else:
    437     expectation = self.expectation

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit\utils\deprecation.py:96, in deprecate_func.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
     93 @functools.wraps(func)
     94 def wrapper(*args, **kwargs):
     95     warnings.warn(msg, category=category, stacklevel=2)
---> 96     return func(*args, **kwargs)

File ~\anaconda3\envs\QAlgobase\Lib\site-packages\qiskit\opflow\expectations\expectation_factory.py:74, in ExpectationFactory.build(operator, backend, include_custom)
     71 backend_to_check = backend.backend if isinstance(backend, QuantumInstance) else backend
     73 # pylint: disable=cyclic-import
---> 74 primitives = operator.primitive_strings()
     75 if primitives in ({"Pauli"}, {"SparsePauliOp"}):
     77     if backend_to_check is None:
     78         # If user has Aer but didn't specify a backend, use the Aer fast expectation

AttributeError: 'SparsePauliOp' object has no attribute 'primitive_strings' '''
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.