-1

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?

enter image description here

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

v0rt3x
  • 83
  • 1
  • 6
  • Those are pylint messages, not actual errors. Pylint doesn't think the code for `QuantumCircuit` would produce an `h` attribute. (Looking at the [code](https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/circuit/quantumcircuit.py) myself, I'm not seeing where an `h` attribute would come from either, but the docs say it's supposed to work.) – user2357112 Feb 15 '19 at 22:31
  • [Apparently it's monkey-patched on in a completely different file.](https://github.com/Qiskit/qiskit-terra/blob/0.7.0/qiskit/extensions/standard/h.py#L72) – user2357112 Feb 15 '19 at 22:34
  • Sorry for so much questinos, but I have never write anything on pyhon (I know C++ and Java). And yes, there is not `h` member in `QuantumCircuit` Do I have to do some changes in the core qiskit files? – v0rt3x Feb 15 '19 at 22:49
  • I have opened the `QuantumCircuit` file and there is no `h` member. How can I add there the `h` function? – v0rt3x Feb 15 '19 at 22:55

1 Answers1

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
manveti
  • 1,691
  • 2
  • 13
  • 16
  • Thank you for explaining it. I have found those libraries. And after adding comment pylint doesn`t see those functions anytime. I get something like that: see image at the end of the post – v0rt3x Feb 16 '19 at 20:19