mindquantum.algorithm.nisq.SGAnsatz2D
- class mindquantum.algorithm.nisq.SGAnsatz2D(nqubits, k, line_set=None, nlayers=1, prefix='', suffix='')[source]
- SG ansatz for 2D quantum systems. - The SG ansatz consists of multiple variational quantum circuit blocks, each of which is a parametrized quantum circuit applied to several adjacent qubits. With such a structure, the SG ansatz naturally adapts to quantum many-body problems. - Specifically, for 1D quantum systems, the SG ansatz can efficiently generate any matrix product states with a fixed bond dimension. For 2D systems, the SG ansatz can generate string-bond states. - For more detail, please refers A sequentially generated variational quantum circuit with polynomial complexity. - Parameters
- nqubits (int) – Number of qubits in the ansatz. 
- k (int) – log(R) + 1, where R is the fixed bond dimension. 
- line_set (list, optional) – A list set of qubits' lines to generate a specific type of string-bond state. If None, will be generated automatically as a 1×N grid where N equals to nqubits. Default: - None.
- nlayers (int) – Number of layers in each block. Default: - 1.
- prefix (str) – The prefix of parameters. Default: - ''.
- suffix (str) – The suffix of parameters. Default: - ''.
 
 - Examples - >>> from mindquantum.algorithm import SGAnsatz2D >>> # Method 1: Create from 2D grid (recommended) >>> sg = SGAnsatz2D.from_grid(nrow=2, ncol=3, k=2) >>> print(len(sg.circuit)) # Number of quantum gates in the ansatz 32 >>> # Method 2: Create with custom line set >>> line_set = SGAnsatz2D.generate_line_set(2, 3) # [[0,3,4,1,2,5], [0,1,2,5,4,3]] >>> sg = SGAnsatz2D(nqubits=6, k=2, line_set=line_set) - classmethod from_grid(nrow, ncol, k, nlayers=1, prefix='', suffix='')[source]
- Create SGAnsatz2D from a 2D grid configuration. - This is the recommended way to create a SGAnsatz2D instance for 2D quantum systems. It automatically generates the appropriate line set based on the grid dimensions. - Parameters
- nrow (int) – Number of rows in the 2D grid 
- ncol (int) – Number of columns in the 2D grid 
- k (int) – log(R) + 1, where R is the fixed bond dimension 
- nlayers (int) – Number of layers in each block. Default: 1 
- prefix (str) – The prefix of parameters. Default: '' 
- suffix (str) – The suffix of parameters. Default: '' 
 
- Returns
- A new instance configured for the specified 2D grid 
- Return type
 - Examples - >>> from mindquantum.algorithm import SGAnsatz2D >>> sg = SGAnsatz2D.from_grid(nrow=2, ncol=3, k=2) >>> print(len(sg.circuit)) # Number of quantum gates in the ansatz 32 
 - classmethod generate_line_set(nrow, ncol)[source]
- Generate snake-like traversal patterns for 2D quantum systems. - This method generates two different traversal paths for a 2D quantum system: 1. Column-wise snake pattern: traverses each column alternating between up and down 2. Row-wise snake pattern: traverses each row alternating between left and right - Parameters
- Returns
- A list containing two traversal paths, where each path is a list of qubit indices.
- The first path is column-wise, the second is row-wise. 
 
- Return type
 - Examples - >>> # For a 2x3 grid with qubits numbered as: >>> # 0 1 2 >>> # 3 4 5 >>> line_set = SGAnsatz2D.generate_line_set(2, 3) >>> print(line_set) >>> # Output: [[0,3,4,1,2,5], [0,1,2,5,4,3]]