使用 DAGCircuit 访问量子位
我目前正在尝试制作自己的 TransformationPass,以便在为特定硬件编译 QuantumCircuit 时使用,但我正在努力让传递给 run(self, dag) 的 DAGCircuit 工作起来
被重写的方法。我目前的主要问题是试图找出图中每个节点实际运行的量子位。我可以访问每个节点的线路,但从那里访问量子位索引会引发 DeprecationWarning。
我可以简单地忽略这个警告,但它给我的印象是我应该以另一种方式解决这个问题。
是否有一种正式的方法来访问给定 DAG 的量子位(对象或简单的索引)?
I'm currently trying to make my own TransformationPass to use when compiling a QuantumCircuit for specific hardware, but I'm struggling to get things to work with the DAGCircuit that gets passed to the run(self, dag)
method that gets overridden. My main issue at the moment is trying to figure out which qubits each node in the graph actually operates on. I can access the wire for each node, but accessing the qubit index from there raises a DeprecationWarning.
I can simply ignore the warning, but it gives me the impression that I should be going about this another way.
Is there a formal method for accessing the qubit (either object or simply its index) given the DAG?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 DAGCircuit 目前还没有一个很好的答案。
.index
属性已被弃用,就像电路上独立位对象的情况一样,如果它们位于寄存器中,则可能不会产生您期望的结果(它将是寄存器索引而不是索引)必然在电路上)。我通常通过以下方法来做到这一点:
然后我可以通过字典查找来获取索引,例如:
在 QuantumCircuit 类上有一个 .find_bit() 轻松执行此操作的方法: https://qiskit.org/documentation/stubs/qiskit. Circuit.QuantumCircuit.find_bit.html
所以你可以这样做:
但是 DAGCircuit 类仍然需要等效的 API。
For
DAGCircuit
right now there isn't a great answer for this. The.index
attribute is deprecated as in the case of standalone bit objects on the circuit if they're in a register it might not yield the result you expect (it'll be the register index not the index on the circuit necessarily).I typically do this by having something like:
and then I can get the index with a dict look up, something like:
On the
QuantumCircuit
class there is a.find_bit()
method which does this easily: https://qiskit.org/documentation/stubs/qiskit.circuit.QuantumCircuit.find_bit.htmlso you can do:
But an equivalent API is still needed for the DAGCircuit class.