tensorcircuit.vis#

Visualization on circuits

tensorcircuit.vis.gate_name_trans(gate_name: str) Tuple[int, str][源代码]#

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'
参数

gate_name (str) -- String of gate name

返回

# of control qubits, reduced gate name

返回类型

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]]]][源代码]#

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}'
参数
  • 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.

参数
  • 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.

返回

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.

返回类型

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[源代码]#

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']
参数
  • 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

返回

if notebook is True, return Image object; otherwise return None

返回类型

Optional[Image], defaults to None