tensorcircuit.templates.blocksΒΆ
Shortcut building blocks that compose common circuit structures (Bell pairs, grid entangling layers, QAOA layers, QFT, etc.) on a given circuit.
- tensorcircuit.templates.blocks.Bell_pair_block(c: Any, links: Sequence[Tuple[int, int]] | None = None) Any[source]ΒΆ
For each pair in links, the input product state |00> is transformed as (01>-|10>)
- tensorcircuit.templates.blocks.Grid2D_entangling(c: Any, coord: Grid2DCoord, unitary: Any, params: Any, **kws: Any) Any[source]ΒΆ
Apply a parametrized two-qubit entangling gate (
exp1) along every row and column edge of the 2D gridcoord.- Parameters:
c (Circuit) β circuit to append gates onto
coord (Grid2DCoord) β 2D grid coordinate object defining the row/column edges
unitary (Tensor) β two-qubit unitary generator used by
exp1params (Tensor) β 1D tensor of rotation angles, ordered row-edges then column-edges
- Returns:
the same circuit with entangling layers appended
- Return type:
- tensorcircuit.templates.blocks.QAOA_block(c: Any, g: Any, paramzz: Any, paramx: Any, **kws: Any) Any[source]ΒΆ
Append one QAOA layer (cost + mixer) onto
cfor the graphg.The cost layer applies
exp1(..., _zz_matrix, paramzz)on each edge (scaled by the edge weight ifparamzzis scalar), and the mixer layer appliesrx(paramx)on each node.- Parameters:
c (Circuit) β circuit to append the QAOA layer onto
g (Graph) β problem graph whose edges/nodes define the cost and mixer terms
paramzz (Tensor) β ZZ rotation angle(s); scalar (broadcast) or per-edge vector
paramx (Tensor) β RX rotation angle(s); scalar (broadcast) or per-node vector
- Returns:
the same circuit with the QAOA layer appended
- Return type:
- 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
nlayersblocks 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:
- 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:
- 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
Circuitobject.- Returns:
Wrapped function with the first input and the output as the state tensor correspondingly.
- Return type:
Callable[β¦, Tensor]