英文:
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 barrier
s to align the gates:
使用 `barrier` 来对齐门操作:
英文:
You can use barrier
s 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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论