mindquantum.core.operators.PolynomialTensor

View Source On Gitee
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 \(a^\dagger_p a_q\) and double excitation terms \(a^\dagger_p a^\dagger_q a_r a_s\), and their corresponding coefficients can be stored in an scalar, \(n_\text{qubits}\times n_\text{qubits}\) matrix and \(n_\text{qubits}\times n_\text{qubits}\times n_\text{qubits}\times n_\text{qubits}\) 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 \(n_\text{qubits}\times n_\text{qubits}\) numpy array, and n_body_tensors[(1,1,0,0)] would return a \(n_\text{qubits}\times n_\text{qubits} n_\text{qubits}\times n_\text{qubits}\) numpy array and those constant and array represent the coefficients of terms of the form identity, \(a^\dagger_p a_q\), \(a^\dagger_p a^\dagger_q a_r a_s\), respectively. Default: None.

Note

Here ‘1’ represents \(a^\dagger\), while ‘0’ represent \(a\).

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.