Why python doesn't see the members of quantumCircuit class qiskit

…衆ロ難τιáo~ 提交于 2019-12-25 19:07:51

问题


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

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

What shoud I do?

The code:

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

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


回答1:


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. Check the docs, code, etc. to make absolutely sure the code that you've written is right (i.e. verify that the linter result is a false positive)
  2. Tell the linter that you know what you're doing and it should ignore the false positive

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

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


来源:https://stackoverflow.com/questions/54717852/why-python-doesnt-see-the-members-of-quantumcircuit-class-qiskit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!