Formatting and drawing

This document explains how to format and draw a compiled circuit in Python.

Formatting

To convert your compiled circuit into its textual representation, use the str function:

str(circuit)

If you just want to see the output on your terminal, you can directly print it as well:

print(circuit)

Drawing

To draw your compiled circuit, use the draw method:

drawing = circuit.draw()

This method draws the circuit, saves it as a temporary PNG file and returns the file path.

You can display the drawing in a Jupyter notebook:

from PIL import Image
drawing = Image.open(circuit.draw())
drawing.show()
drawing.close()

Alternatively, you can use the show option of the draw method to display the drawing with matplotlib:

circuit.draw(show=True)

Lastly, to save the drawing to a specific path, use the save_to option:

destination = "/tmp/path/of/your/choice.png"
drawing = circuit.draw(save_to=destination)
assert drawing == destination

Last updated

Was this helpful?