def _text_circuit_drawer(circuit, filename=None, basis="id,u0,u1,u2,u3,x,y,z,h,s,sdg,t,tdg,rx,ry,rz," "cx,cy,cz,ch,crz,cu1,cu3,swap,ccx,cswap", line_length=None, reversebits=False, plotbarriers=True): """ Draws a circuit using ascii art. Args: circuit (QuantumCircuit): Input circuit filename (str): optional filename to write the result basis (str): Optional. Comma-separated list of gate names line_length (int): Optional. Sometimes, your console is too small of the drawing. Give me you maximum line length your console supports. reversebits (bool): Rearrange the bits in reverse order. plotbarriers (bool): Draws the barriers when they are there. Returns: String: The drawing in a loooong string. """ dag_circuit = DAGCircuit.fromQuantumCircuit(circuit, expand_gates=False) json_circuit = transpile_dag(dag_circuit, basis_gates=basis, format='json') text = "\n".join( _text.TextDrawing(json_circuit, reversebits=reversebits, plotbarriers=plotbarriers).lines( line_length)) if filename: with open(filename, mode='w', encoding="utf8") as text_file: text_file.write(text) return text
def _text_circuit_drawer(circuit, filename=None, line_length=None, reversebits=False, plotbarriers=True): """ Draws a circuit using ascii art. Args: circuit (QuantumCircuit): Input circuit filename (str): optional filename to write the result line_length (int): Optional. Breaks the circuit drawing to this length. This useful when the drawing does not fit in the console. If None (default), it will try to guess the console width using shutil.get_terminal_size(). If you don't want pagination at all, set line_length=-1. reversebits (bool): Rearrange the bits in reverse order. plotbarriers (bool): Draws the barriers when they are there. Returns: TextDrawing: An instances that, when printed, draws the circuit in ascii art. """ qregs, cregs, ops = _utils._get_instructions(circuit, reversebits=reversebits) text_drawing = _text.TextDrawing(qregs, cregs, ops) text_drawing.plotbarriers = plotbarriers text_drawing.line_length = line_length if filename: text_drawing.dump(filename) return text_drawing
def _text_circuit_drawer(circuit, filename=None, basis="id,u0,u1,u2,u3,x,y,z,h,s,sdg,t,tdg,rx,ry,rz," "cx,cy,cz,ch,crz,cu1,cu3,swap,ccx,cswap", line_length=None, reversebits=False, plotbarriers=True): """ Draws a circuit using ascii art. Args: circuit (QuantumCircuit): Input circuit filename (str): optional filename to write the result basis (str): Optional. Comma-separated list of gate names line_length (int): Optional. Breaks the circuit drawing to this length. This useful when the drawing does not fit in the console. If None (default), it will try to guess the console width using shutil.get_terminal_size(). If you don't want pagination at all, set line_length=-1. reversebits (bool): Rearrange the bits in reverse order. plotbarriers (bool): Draws the barriers when they are there. Returns: TextDrawing: An instances that, when printed, draws the circuit in ascii art. """ dag_circuit = DAGCircuit.fromQuantumCircuit(circuit, expand_gates=False) json_circuit = transpile_dag(dag_circuit, basis_gates=basis, format='json') text_drawing = _text.TextDrawing(json_circuit, reversebits=reversebits) text_drawing.plotbarriers = plotbarriers text_drawing.line_length = line_length if filename: text_drawing.dump(filename) return text_drawing