pytket.circuit.display
pytket.circuit.display#
Contains several functions for rendering interactive circuit diagrams.
Note
Rendering circuits with pytket.circuit.display
requires an internet connection. Using the pytket circuit renderer offline can be done by installing the pytket-offline-renderer extension.
pip install pytket-offline-renderer
Display a circuit as html.
- pytket.circuit.display.render_circuit_as_html(circuit: Union[Dict[str, Union[str, float, dict]], pytket.circuit.Circuit], jupyter: bool = False) Optional[str] #
Render a circuit as HTML for inline display.
- Parameters
circuit – the circuit to render.
jupyter – set to true to render generated HTML in cell output.
- pytket.circuit.display.render_circuit_jupyter(circuit: Union[Dict[str, Union[str, float, dict]], pytket.circuit.Circuit]) None #
Render a circuit as jupyter cell output.
- Parameters
circuit – the circuit to render.
- pytket.circuit.display.view_browser(circuit: Union[Dict[str, Union[str, float, dict]], pytket.circuit.Circuit], browser_new: int = 2, sleep: int = 5) None #
Write circuit render html to a tempfile and open in browser.
Waits for some time for browser to load then deletes tempfile.
- Parameters
circuit – the Circuit or serialized Circuit to render.
browser_new –
new
parameter towebbrowser.open
, default 2.sleep – Number of seconds to sleep before deleting file, default 5.
from pytket import Circuit
from pytket.circuit.display import render_circuit_jupyter
circ = Circuit(2) # Define Circuit
circ.H(0).H(1).CX(0, 1).Rz(0.4, 1).CX(0, 1).H(0).H(1)
render_circuit_jupyter(circ) # Render interactive display
This same diagram can be rendered with the offline renderer as follows
from pytket.extensions.offline_display import render_circuit_jupyter render_circuit_jupyter(circ) # Render display as above