tensorcircuit.vis#
Visualization on circuits
- tensorcircuit.vis.gate_name_trans(gate_name: str) Tuple[int, str] [source]#
Translating from the gate name to gate information including the number of control qubits and the reduced gate name.
- Example
>>> string = r'ccnot' >>> tc.vis.gate_name_trans(string) 2 'not'
- Parameters
gate_name (str) – String of gate name
- Returns
# of control qubits, reduced gate name
- Return type
Tuple[int, str]
- tensorcircuit.vis.qir2tex(qir: List[Dict[str, Any]], n: int, init: Optional[List[str]] = None, measure: Optional[List[str]] = None, rcompress: bool = False, lcompress: bool = False, standalone: bool = False, return_string_table: bool = False) Union[str, Tuple[str, List[List[str]]]] [source]#
Generate Tex code from ‘qir’ string to illustrate the circuit structure. This visualization is based on quantikz package.
- Example
>>> qir=[{'index': [0], 'name': 'h'}, {'index': [1], 'name': 'phase'}] >>> tc.vis.qir2tex(qir,2) '\\begin{quantikz}\n\ ... \n\\end{quantikz}'
- Parameters
qir (List[Dict[str, Any]]) – The quantum intermediate representation of a circuit in tensorcircuit.
n (int) – # of qubits
init (Optional[List[str]]) – Initial state, default is an all zero state ‘000…000’.
measure (Optional[List[str]]) – Measurement Basis, default is None which means no measurement in the end of the circuit.
rcompress – If true, a right compression of the circuit will be conducted. A right compression means we will try to shift gates from right to left if possible.
Default is false. :type rcompress: bool :param lcompress: If true, a left compression of the circuit will be conducted.
A left compression means we will try to shift gates from left to right if possible. Default is false.
- Parameters
standalone (bool) – If true, the tex code will be designed to generate a standalone document. Default is false which means the generated tex code is just a quantikz code block.
return_string_table (bool) – If true, a string table of tex code will also be returned. Default is false.
- Returns
Tex code of circuit visualization based on quantikz package. If return_string_table is true, a string table of tex code will also be returned.
- Return type
Union[str, Tuple[str, List[List[str]]]]
- tensorcircuit.vis.render_pdf(texcode: str, filename: Optional[str] = None, latex: Optional[str] = None, filepath: Optional[str] = None, notebook: bool = False) Any [source]#
Generate the PDF file with given latex string and filename. Latex command and file path can be specified. When notebook is True, convert the output PDF file to image and return a Image object.
- Example
>>> string = r'''\documentclass[a4paper,12pt]{article} ... \begin{document} ... \title{Hello TensorCircuit!} ... \end{document}''' >>> tc.vis.render_pdf(string, "test.pdf", notebook=False) >>> os.listdir() ['test.aux', 'test.log', 'test.pdf', 'test.tex']
- Parameters
texcode (str) – String of latex content
filename (Optional[str], optional) – File name, defaults to random UUID str(uuid4())
latex (Optional[str], optional) – Executable Latex command, defaults to pdflatex
filepath (Optional[str], optional) – File path, defaults to current working place os.getcwd()
notebook (bool, optional) – [description], defaults to False
- Returns
if notebook is True, return Image object; otherwise return None
- Return type
Optional[Image], defaults to None