tensorcircuit.templates.blocks#

Shortcuts for measurement patterns on circuit

tensorcircuit.templates.blocks.Bell_pair_block(c: Any, links: Optional[Sequence[Tuple[int, int]]] = None) → Any[source]#

For each pair in links, the input product state |00> is transformed as (01>-|10>)

Parameters
  • c (Circuit) – Circuit in

  • links (Optional[Sequence[Tuple[int, int]]], optional) – pairs indices for Bell pairs, defaults to None, corresponds to neighbor links

Returns

Circuit out

Return type

Circuit

tensorcircuit.templates.blocks.Grid2D_entangling(c: Any, coord: tensorcircuit.templates.graphs.Grid2DCoord, unitary: Any, params: Any, **kws: Any) → Any[source]#
tensorcircuit.templates.blocks.QAOA_block(c: Any, g: Any, paramzz: Any, paramx: Any, **kws: Any) → Any[source]#
tensorcircuit.templates.blocks.example_block(c: Any, param: Any, nlayers: int = 2, is_split: bool = False) → Any[source]#

The circuit ansatz is firstly one layer of Hadamard gates and then we have nlayers blocks of \(e^{i\theta Z_iZ_{i+1}}\) two-qubit gate in ladder layout, following rx gate.

Parameters
  • c (Circuit) – The circuit

  • param (Tensor) – paramter tensor with 2*nlayer*n elements

  • nlayers (int, optional) – number of ZZ+RX blocks, defaults to 2

  • is_split (bool, optional) – whether use SVD split to reduce ZZ gate bond dimension, defaults to False

Returns

The circuit with example ansatz attached

Return type

Circuit

tensorcircuit.templates.blocks.qft(c: Any, *index: int, do_swaps: bool = True, inverse: bool = False, insert_barriers: bool = False) → Any[source]#

This function applies quantum fourier transformation (QFT) to the selected circuit lines

Parameters
  • c (Circuit) – Circuit in

  • *index –

    the indices of the circuit lines to apply QFT

  • do_swaps (bool) – Whether to include the final swaps in the QFT

  • inverse (bool) – If True, the inverse Fourier transform is constructed

  • insert_barriers (bool) – If True, barriers are inserted as visualization improvement

Returns

Circuit c

Return type

Circuit

tensorcircuit.templates.blocks.state_centric(f: Callable[[...], Any]) → Callable[[...], Any][source]#

Function decorator wraps the function with the first input and output in the format of circuit, the wrapped function has the first input and the output as the state tensor.

Parameters

f (Callable[..., Circuit]) – Function with the fist input and the output as Circuit object.

Returns

Wrapped function with the first input and the output as the state tensor correspondingly.

Return type

Callable[…, Tensor]