MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / getSVGstring

Function getSVGstring

python/cudaq/display/display_trace.py:12–24  ·  view source on GitHub ↗
(kernel, *args)

Source from the content-addressed store, hash-verified

10
11
12def getSVGstring(kernel, *args):
13 from subprocess import check_output, STDOUT
14 from tempfile import TemporaryDirectory
15
16 latex_string = cudaq.draw("latex", kernel, *args)
17 with TemporaryDirectory() as tmpdirname:
18 with open(tmpdirname + "/cudaq-trace.tex", "w") as f:
19 f.write(latex_string)
20 # this needs `latex` and `quantikz` to be installed, e.g. through `apt install texlive-latex-extra`
21 check_output(["latex", "cudaq-trace"], cwd=tmpdirname, stderr=STDOUT)
22 check_output(["dvisvgm", "cudaq-trace"], cwd=tmpdirname, stderr=STDOUT)
23 with open(tmpdirname + "/cudaq-trace.svg", "rb") as f:
24 return str(f.read(), encoding="utf-8")
25
26
27def displaySVG(kernel, *args):

Callers 2

_repr_svg_Method · 0.90
displaySVGFunction · 0.85

Calls 3

drawMethod · 0.45
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected