Prev Tutorial: Quantum Intermediate Compiler
Next Tutorial: Operator
Quantum Program Drawing Tutorial
This document provides a guide on how to use the draw_qprog function to generate a graphical representation of a quantum program object (QProg
).
Function Overview
The draw_qprog function generates a graphical representation of a given quantum program. It allows customization of the drawing format and options for detailed visualization.
- Note
- expend_map: A map used to control drawing expansion options.Default: { {"all", 1} } (expands all subprograms). The key represents the name of the circuit to be unfolded,Values can be selected from 0, 1, 2. 0 represents not expanding, 1 represents expanding the current circuit without expanding its sub circuits, and 2 represents expanding all circuits.
- param_show: Indicates whether to show parameters in the drawing.Default: false.
Example Usage
Here’s a basic example of how to use the draw_qprog
function:
Python
prog = QProg()
prog << H(1)<< H(0)
circuit = QCircuit()
circuit << CNOT(1,2) << CNOT(2,3)
prog << circuit
print(draw_qprog(circuit))
print(draw_qprog(prog))
print(draw_qprog(prog, expend_map={}))
The result output of the program is as follows:
q_1: |0>────*── ──────
┌──┴─┐
q_2: |0>─┤CNOT├ ───*──
└────┘ ┌──┴─┐
q_3: |0>─────── ┤CNOT├
└────┘
c : / ═
┌─┐
q_0: |0>─┤H├ ────── ──────
├─┤
q_1: |0>─┤H├ ───*── ──────
└─┘ ┌──┴─┐
q_2: |0>──── ┤CNOT├ ───*──
└────┘ ┌──┴─┐
q_3: |0>──── ────── ┤CNOT├
└────┘
c : / ═
┌─┐
q_0: |0>─┤H├ ────────────────
├─┤ ┌──────────────┐
q_1: |0>─┤H├ ┤0 ├
└─┘ │ │
q_2: |0>──── ┤1 QCircuit_0 ├
│ │
q_3: |0>──── ┤2 ├
└──────────────┘
c : / ═