def qasm_widget(circuit: QuantumCircuit) -> wid.VBox: """Generate a QASM widget with header for a quantum circuit. Args: circuit: Input quantum circuit. Returns: Output widget. Raises: MissingOptionalLibraryError: If pygments is not installed """ if not HAS_PYGMENTS: raise MissingOptionalLibraryError( libname="pygments>2.4", name="qasm_widget", pip_install="pip install pygments", ) qasm_code = circuit.qasm() code = pygments.highlight(qasm_code, OpenQASMLexer(), HtmlFormatter()) html_style = HtmlFormatter( style=QasmHTMLStyle).get_style_defs(".highlight") code_style = (""" <style> .highlight { font-family: monospace; font-size: 14px; line-height: 1.7em; } .highlight .err { color: #000000; background-color: #FFFFFF } %s </style> """ % html_style) out = wid.HTML( code_style + code, layout=wid.Layout(max_height="500px", height="auto", overflow="scroll scroll"), ) out_label = wid.HTML( f"<p style='{head_style}'>OpenQASM</p>", layout=wid.Layout(margin="0px 0px 10px 0px"), ) qasm = wid.VBox( children=[out_label, out], layout=wid.Layout(height="auto", max_height="500px", width="60%", margin="0px 0px 0px 20px"), ) qasm._code_length = len(qasm_code.split("\n")) return qasm
def qasm_widget(circuit: QuantumCircuit) -> wid.VBox: """Generate a QASM widget with header for a quantum circuit. Args: circuit: Input quantum circuit. Returns: Output widget. Raises: ImportError: If pygments is not installed """ if not HAS_PYGMENTS: raise ImportError("pygments>2.4 must be installed for to use the qasm " 'widget. To install run "pip install pygments"') qasm_code = circuit.qasm() code = pygments.highlight(qasm_code, OpenQASMLexer(), HtmlFormatter()) html_style = HtmlFormatter( style=QasmHTMLStyle).get_style_defs('.highlight') code_style = """ <style> .highlight { font-family: monospace; font-size: 14px; line-height: 1.7em; } .highlight .err { color: #000000; background-color: #FFFFFF } %s </style> """ % html_style out = wid.HTML(code_style + code, layout=wid.Layout(max_height='500px', height='auto', overflow='scroll scroll')) out_label = wid.HTML("<p style='{}'>OpenQASM</p>".format(head_style), layout=wid.Layout(margin='0px 0px 10px 0px')) qasm = wid.VBox(children=[out_label, out], layout=wid.Layout(height='auto', max_height='500px', width='60%', margin='0px 0px 0px 20px')) qasm._code_length = len(qasm_code.split('\n')) return qasm
def qasm_widget(circuit: QuantumCircuit) -> wid.VBox: """Generate a QASM widget with header for a quantum circuit. Args: circuit: Input quantum circuit. Returns: Output widget. """ qasm_code = circuit.qasm() code = pygments.highlight(qasm_code, OpenQASMLexer(), HtmlFormatter()) html_style = HtmlFormatter( style=QasmHTMLStyle).get_style_defs('.highlight') code_style = """ <style> .highlight { font-family: monospace; font-size: 14px; line-height: 1.7em; } .highlight .err { color: #000000; background-color: #FFFFFF } %s </style> """ % html_style out = wid.HTML(code_style + code, layout=wid.Layout(max_height='500px', height='auto', overflow='hidden scroll')) out_label = wid.HTML("<p style='{}'>Circuit QASM</p>".format(head_style), layout=wid.Layout(margin='0px 0px 10px 0px')) qasm = wid.VBox(children=[out_label, out], layout=wid.Layout(height='auto', max_height='500px', width='70%', margin='0px 0px 0px 20px')) qasm._code_length = len(qasm_code.split('\n')) return qasm