mindquantum.core.operators.PolynomialTensor
- class mindquantum.core.operators.PolynomialTensor(n_body_tensors=None)[source]
Class to store the coefficient of the fermionic ladder operators in a tensor form.
For instance, in a molecular Hamiltonian (degree 4 polynomial) which conserves particle number, there are only three kinds of terms, namely constant term, single excitation
and double excitation terms , and their corresponding coefficients can be stored in an scalar, matrix and matrix. Note that each tensor must have an even number of dimensions due to the parity conservation. Much of the functionality of this class is similar to that of FermionOperator.- Parameters
n_body_tensors (dict) – A dictionary storing the tensors describing n-body interactions. The keys are tuples that indicate the type of tensor. For instance, n_body_tensors[()] would return a constant, while a n_body_tensors[(1, 0)] would be an
numpy array, and n_body_tensors[(1,1,0,0)] would return a numpy array and those constant and array represent the coefficients of terms of the form identity, , , respectively. Default:None
.
Note
Here '1' represents
, while '0' represent .Examples
>>> import numpy as np >>> from mindquantum.core.operators import PolynomialTensor >>> constant = 1 >>> one_body_term = np.array([[1,0],[0,1]]) >>> two_body_term = two_body_term = np.array([[[[1,0],[0,1]],[[1,0],[0,1]]],[[[1,0],[0,1]],[[1,0],[0,1]]]]) >>> n_body_tensors = {(): 1, (1,0): one_body_term,(1,1,0,0):two_body_term} >>> poly_op = PolynomialTensor(n_body_tensors) >>> poly_op () 1 ((0, 1), (0, 0)) 1 ((1, 1), (1, 0)) 1 ((0, 1), (0, 1), (0, 0), (0, 0)) 1 ((0, 1), (0, 1), (1, 0), (1, 0)) 1 ((0, 1), (1, 1), (0, 0), (0, 0)) 1 ((0, 1), (1, 1), (1, 0), (1, 0)) 1 ((1, 1), (0, 1), (0, 0), (0, 0)) 1 ((1, 1), (0, 1), (1, 0), (1, 0)) 1 ((1, 1), (1, 1), (0, 0), (0, 0)) 1 ((1, 1), (1, 1), (1, 0), (1, 0)) 1 >>> # get the constant >>> poly_op.constant 1 >>> # set the constant >>> poly_op.constant = 2 >>> poly_op.constant 2 >>> poly_op.n_qubits 2 >>> poly_op.one_body_tensor array([[1, 0], [0, 1]]) >>> poly_op.two_body_tensor array([[[[1, 0], [0, 1]], [[1, 0], [0, 1]]], [[[1, 0], [0, 1]], [[1, 0], [0, 1]]]])
- property constant
Get the value of the identity term.
- property one_body_tensor
Get the one-body term.
- property two_body_tensor
Get the two-body term.