'Qiskit QAOA compile error , EvolvedOp object has no attribute 'broadcast_arguments
Nowadays, I am studying quantum computing. when I did follow this code, I got an error. I don't know why I got this error.
I just searched to solve this problem. In the below, the MinimumEigenOptimizer.solve() input is QuadraticProgram. MinimumEigenOptimizer.solve(problem)
The parameter of the function, MinimumEigenOptimizer.solve(), is QuadraticProgram.
In the below code, I followed the rule of the parameter.
# generate qiskit's cost function
qiskit_cost_function = QuadraticProgram()
The error is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\Users\Public\Documents\ESTsoft\CreatorTemp/ipykernel_12164/1668192560.py in <module>
8 results = []
9 # solve quadratic program
---> 10 result = optimizer_qaoa.solve(qiskit_cost_function)
11 print(result)
12
~\anaconda3\lib\site-packages\qiskit\optimization\algorithms\minimum_eigen_optimizer.py
in solve(self, problem)
194
195 # approximate ground state of operator using min eigen solver
--> 196 eigen_result =
self._min_eigen_solver.compute_minimum_eigenvalue(operator)
197
198 # analyze results
~\anaconda3\lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\vqe.py in
compute_minimum_eigenvalue(self, operator, aux_operators)
495 # this sets the size of the ansatz, so it must be called before the initial point
496 # validation
--> 497 self._check_operator_ansatz(operator)
498
499 # set an expectation for this algorithm run (will be reset to None at
the end)
~\anaconda3\lib\site-packages\qiskit\algorithms\minimum_eigen_solvers\qaoa.py in
_check_operator_ansatz(self, operator)
131 if operator != self._cost_operator:
132 self._cost_operator = operator
--> 133 self.ansatz = QAOAAnsatz(
134 operator, self._reps, initial_state=self._initial_state,
mixer_operator=self._mixer
135 ).decompose() # TODO remove decompose once #6674 is fixed
~\anaconda3\lib\site-packages\qiskit\circuit\library\blueprintcircuit.py in
decompose(self, gates_to_decompose)
100 def decompose(self, gates_to_decompose=None):
101 if self._data is None:
--> 102 self._build()
103 return super().decompose(gates_to_decompose)
104
~\anaconda3\lib\site-packages\qiskit\circuit\library\n_local\qaoa_ansatz.py in
_build(self)
257 return
258
--> 259 super()._build()
260
261 # keep old parameter order: first cost operator, then mixer operators
~\anaconda3\lib\site-packages\qiskit\circuit\library\evolved_operator_ansatz.py in
_build(self)
172
173 evolved_op = self.evolution.convert((coeff *
op).exp_i()).reduce()
--> 174 circuits.append(evolved_op.to_circuit())
175
176 self.rotation_blocks = []
~\anaconda3\lib\site-packages\qiskit\aqua\operators\primitive_ops\primitive_op.py in
to_circuit(self)
259 """ Returns a ``QuantumCircuit`` equivalent to this Operator. """
260 qc = QuantumCircuit(self.num_qubits)
--> 261 qc.append(self.to_instruction(), qargs=range(self.primitive.num_qubits))
# type: ignore
262 return qc.decompose()
263
~\anaconda3\lib\site-packages\qiskit\circuit\quantumcircuit.py in append(self,
instruction, qargs, cargs)
1228 requester = self._resolve_classical_resource
1229 instructions = InstructionSet(resource_requester=requester)
-> 1230 for qarg, carg in instruction.broadcast_arguments(expanded_qargs,
expanded_cargs):
1231 instructions.add(appender(instruction, qarg, carg), qarg, carg)
1232 return instructions
AttributeError: 'EvolvedOp' object has no attribute 'broadcast_arguments'
Could you give me a hand? help me please!! I am very very beginner.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|