为什么python看不到QuantumCircuit类qiskit的成员 [英] Why python doesn't see the members of quantumCircuit class qiskit

查看:248
本文介绍了为什么python看不到QuantumCircuit类qiskit的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习量子计算机上的编程. 我已经在VS Code中安装了qiskit(在VS Code市场中可以使用所有qiskit扩展),python编译器(来自VS Code市场"Python"和"VSCode的Python").我已经设置了qikit API以使其正常工作

I`m trying to learn the programming on quantum computers. I have installed qiskit in VS Code (all qiskit extentions available in VS Code market) , python compilator (from Vs Code market "Python" and "Python for VSCode"). I have set up my qikit API for correct working

运行示例时出现错误:'QuantumCircuit'的实例没有'h'成员"

When I run the exemple I get erros: "Instance of 'QuantumCircuit' has no 'h' member"

我该怎么办?

代码:

from qiskit import ClassicalRegister, QuantumRegister
from qiskit import QuantumCircuit, execute

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q)
qc.h(q[0]) 
qc.cx(q[0], q[1])
qc.measure(q, c)

job_sim = execute(qc, 'local_qasm_simulator')

sim_result = job_sim.result()

print(sim_result.get_counts(qc))

======================== 添加注释# pylint: disable=no-member

======================== The same error after adding comment # pylint: disable=no-member

推荐答案

有问题的错误是来自lint皮林特,而不是python本身.尽管pylint非常聪明,但某些构造(尤其是那些涉及动态添加属性的构造)超出了它的理解能力.当您遇到这种情况时,最好的做法是双重的:

The errors in question are coming from pylint, a linter, not from python itself. While pylint is pretty clever, some constructs (particularly those involving dynamically-added properties) are beyond its ability to understand. When you encounter situations like this, the best course of action is twofold:

  1. 检查文档,代码等,以确保您编写的代码正确无误(即,验证短绒结果是否为假阳性)
  2. 告诉短毛猫你知道自己在做什么,它应该忽略误报

user2357112处理了上面注释中的第一步,表明该属性是由库的另一部分动态设置的.

user2357112 took care of the first step in the comments above, demonstrating that the property gets dynamically set by another part of the library.

对于pylint,可以通过在每个有问题的行之后添加一个注释,告诉它为该特定行打开该特定检查的方式来完成pylint的第二步:

The second step can be accomplished for pylint by adding a comment after each of the offending lines telling it to turn of that particular check for that particular line:

qc.h(q[0])  # pylint: disable=no-member

这篇关于为什么python看不到QuantumCircuit类qiskit的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆