Qiskit QAOA编译错误,Evolvedop对象没有属性' broadcast_arguments

发布于 2025-01-19 18:46:28 字数 3876 浏览 0 评论 0原文

如今,我正在研究量子计算。 当我确实遵循此代码时,我会遇到错误。 我不知道为什么会有这个错误。

我刚刚搜索解决这个问题。 在下面,miniMumeGenopTimizer.solve()输入是四边形的。 miniMumeMumeGenopTimizer.Solve(问题)

函数的参数miniMumeMumeigenOptimizer.solve(),是四边形的。

在以下代码中,我遵循参数的规则。

# generate qiskit's cost function
qiskit_cost_function = QuadraticProgram()

错误是:

---------------------------------------------------------------------------
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'

你能给我一只手吗?请帮我! 我非常非常初学者。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文