I made an svg diagram from a stim circuit:
import stim
circuit = stim.Circuit("""
H 0
CX 0 1
M 0 1
""")
diagram = circuit.diagram("timeline-svg")
display(diagram)
I tried to write the diagram to a file, but I got an error:
with open('diagram.svg', 'w') as f:
f.write(diagram)
TypeError: write() argument must be str, not stim._DiagramHelper
How do I save the diagram to an SVG image file?