如何手动分组门(以使电路更易阅读)?

huangapple go评论60阅读模式
英文:

How to group gates manually (and make circuit more readable)?

问题

我正在尝试让我的电路看起来更可读,但是在Qiskit QuantumCircuit中,门会自动排列在左侧。
例如,来自qiskit文档的图像:

如何手动分组门(以使电路更易阅读)?

将辅助X门放在第一列,Hadamard门放在第二列,控制门放在第三-第五列,最后的Hadamard门放在第六列会更好。

可以在Quirk中实现这样的结果如何手动分组门(以使电路更易阅读)?

在Qiskit QuantumCircuit(或其他类)中是否有设置量子门的显式列数的方法?

英文:

I'm trying to make my circuit look readable, but the gates auto-order in Qiskit QuantumCircuit shifts all gates to the left side.
For example an image from qiskit documentation:

如何手动分组门(以使电路更易阅读)?

It would be much better to put ancilla X gate into the first column, Hadamard gats into the second, controlled gates into the third-fourth-fifth, and last Hadamard into the sixth column.

Such a result may be achieved in Quirk 如何手动分组门(以使电路更易阅读)?

Is there a way to set up an explicit column number for the quantum gate in the Qiskit QuantumCircuit (or other class)?

答案1

得分: 1

You can use barriers to align the gates:

使用 `barrier` 来对齐门操作
英文:

You can use barriers to align the gates:

from qiskit import QuantumCircuit
circuit = QuantumCircuit(4)
circuit.x(3)
circuit.barrier()
circuit.h(range(4))
circuit.cx([0,1,2], 3)
circuit.h(range(3))
circuit.measure_all()
circuit.draw('mpl')

如何手动分组门(以使电路更易阅读)?

If you want to remove them from the plot:

circuit.draw('mpl', plot_barriers=False)

如何手动分组门(以使电路更易阅读)?

huangapple
  • 本文由 发表于 2023年4月17日 17:26:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定