pyqpanda.Visualization.circuit_composer ======================================= .. py:module:: pyqpanda.Visualization.circuit_composer Classes ------- .. autoapisummary:: pyqpanda.Visualization.circuit_composer.CircuitComposer Module Contents --------------- .. py:class:: CircuitComposer(n_qubits: int) Bases: :py:obj:`pyqpanda.QCircuit` CircuitComposer for representing quantum circuit using ascii art. Args ---------- n_qubits: int Number of qubits of quantum circuit. circuit_layers : List[List[str]] List of each layer of quantum circuit, each layer of a list of string, representing each line of ascii art. Examples -------- >>> n_qubits = 6 >>> qvm = pq.CPUQVM() >>> qvm.init_qvm() >>> q = qvm.qAlloc_many(n_qubits) >>> circ1 = CircuitComposer(n_qubits) >>> circuit = pq.QCircuit() >>> circuit << pq.H(q[0]) << pq.CNOT(q[0], q[1]) << pq.CNOT(q[1], q[2]) >>> circ1.append(circuit) >>> circ1 << pq.BARRIER(q) >>> circ1.append(pq.QFT(q[4:]), "QFT") >>> print(circ1) ┌─┐ ! q_0: |0>─ ┤H├ ───■── ────── ────! ──────── └─┘ ┌──┴─┐ ! q_1: |0>─ ─── ┤CNOT├ ───■── ────! ──────── └────┘ ┌──┴─┐ ! q_2: |0>─ ─── ────── ┤CNOT├ ────! ──────── └────┘ ! q_3: |0>─ ─── ────── ────── ────! ──────── ! ┌──────┐ q_4: |0>─ ─── ────── ────── ────! ┤4 ├ ! │ QFT │ q_5: |0>─ ─── ────── ────── ────! ┤5 ├ ! └──────┘ >>> print(circ1.circuit) ┌─┐ ! q_0: |0>─┤H├ ───■── ────── ────! ─── ────────────── ─── ─ └─┘ ┌──┴─┐ ! q_1: |0>──── ┤CNOT├ ───■── ────! ─── ────────────── ─── ─ └────┘ ┌──┴─┐ ! q_2: |0>──── ────── ┤CNOT├ ────! ─── ────────────── ─── ─ └────┘ ! q_3: |0>──── ────── ────── ────! ─── ────────────── ─── ─ ! ┌─┐ q_4: |0>──── ────── ────── ────! ─── ───────■────── ┤H├ X ! ┌─┐ ┌──────┴─────┐ └─┘ │ q_5: |0>──── ────── ────── ────! ┤H├ ┤CR(1.570796)├ ─── X ! └─┘ └────────────┘ .. py:attribute:: n_qubits .. py:attribute:: circuit_layers .. py:attribute:: circuit_latex_layers :value: [] .. py:attribute:: circuit_pic_layers :value: [] .. py:method:: append(circ: pyqpanda.QCircuit, name: str = '') -> None Append a quantum circuit. Args ---------- circ : pq.QCircuit Quantum circuit to be appended. name : str, optional Name of the appended quantum circuit, by default None Notes ----- If `name` is empty string, then append the circuit with its string representation not boxed. The name must be in full English and cannot contain numbers or symbols Even when a circuit is appended with a name, the composed circuit string can be get by using `circuit` property. Examples -------- >>> circ = CircuitComposer(2) >>> circuit = pq.QCircuit() >>> circuit << pq.H(qubits[0]) << pq.CNOT(qubits[0], qubits[1]) >>> circ.append(circuit) >>> print(circ) ┌─┐ q_0: |0>─ ┤H├ ───■── └─┘ ┌──┴─┐ q_1: |0>─ ─── ┤CNOT├ └────┘ >>> circ.append(circuit, "GHZ") >>> print(circ) ┌─┐ ┌──────┐ q_0: |0>─ ┤H├ ───■── ┤0 ├ └─┘ ┌──┴─┐ │ GHZ │ q_1: |0>─ ─── ┤CNOT├ ┤1 ├ └────┘ └──────┘ >>> print(circ.circuit) ┌─┐ ┌─┐ q_0: |0>─┤H├ ───■── ┤H├ ───■── └─┘ ┌──┴─┐ └─┘ ┌──┴─┐ q_1: |0>──── ┤CNOT├ ─── ┤CNOT├ └────┘ └────┘ .. py:method:: insert(circ: pyqpanda.QCircuit) .. py:method:: draw_circuit(output=None, filename=None) -> str draw a quantum circuit. Parameters ---------- output : str,Output type: text、latex、pic filename : str, optional When the output type is pic, this parameter can be used to specify the path to save the picture Returns ------- str, if 'text' return ASII of circuit, if 'latex' return latex of circuit, if 'pic' return picture save path of circuit, Notes ----- If `output` is empty string, use text if filename is empty string,use 'QCircuit_pic.png' .. py:property:: circuit Return original quantum circuit representation.