为什么python看不到QuantumCircuit类qiskit的成员

编程入门 行业动态 更新时间:2024-10-25 04:26:22
本文介绍了为什么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:

  • 检查文档,代码等,以确保您编写的代码正确无误(即,验证短绒结果是否为假阳性)
  • 告诉短毛猫你知道自己在做什么,它应该忽略误报
  • 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的成员

    本文发布于:2023-10-16 05:24:32,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1496630.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:成员   python   QuantumCircuit   qiskit

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!