hqs_quantum_solver.spinless_fermions#

Operators for spinless fermions.

Functions

annihilation(*[, site, coef])

Annihilation operator for a spinless fermions system.

anomalous_pairing(coef)

The spinless fermion anomalous pairing term.

creation(*[, site, coef])

Creation operator for a spinless fermions system.

hopping(coef)

The spinless fermion hopping term.

interaction(coef)

The spinless fermion interaction term.

lattice_terms(lattice)

Returns the terms corresonding to a Lattice Builder configuration or instance.

Classes

HamiltonianExpression(coef_hopping, ...)

Defines a Hamiltonian of a spinless fermion system.

Operator(*args, **kwargs)

Operator acting on a space representing spinless fermions.

OperatorExpression()

Expression for constructing operators.

OperatorFromFunction(fun, dtype)

Create an operator expression from an add_triplets function.

OperatorInfo(*, domain, codomain, dtype)

The properties of an operator excluding the matrix elements.

OperatorScaling(scalar, op)

Expression representing a scaled operator.

OperatorSum(op_a, op_b)

Expression representing the sum of two operators.

VectorSpace(*, sites, particle_numbers)

The vector space for spinless fermions.

class Operator(*args, **kwargs)#

Operator acting on a space representing spinless fermions.

Creates the operator.

property H#

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns:

A_H – Hermitian adjoint of self.

Return type:

LinearOperator

property T#

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

__init__(expression: OperatorExpression, *, domain: VectorSpace, codomain: VectorSpace | None = None, dtype: DTypeLike | None = None, operator_type: OperatorFactory | None = None) None#

Creates the operator.

adjoint()#

Hermitian adjoint.

Returns the Hermitian adjoint of self, aka the Hermitian conjugate or Hermitian transpose. For a complex matrix, the Hermitian adjoint is equal to the conjugate transpose.

Can be abbreviated self.H instead of self.adjoint().

Returns:

A_H – Hermitian adjoint of self.

Return type:

LinearOperator

property codomain: VectorSpace#

The codomain of the operator.

property domain: VectorSpace#

The domain of the operator.

dot(x: ndarray, out: ndarray | None = None) ndarray#

Compute the dot product of operator with array; optional out to avoid reallocation.

When represented by NumPy this operation would be A @ x.

Parameters:
  • x (np.ndarray) – The vector/array to dot product with.

  • out (Optional[np.ndarray]) – Optional array to store results and avoid reallocation.

Returns:

The result of the dot product, A @ x.

Return type:

np.ndarray

dot_add(x: ndarray, out: ndarray, z: float | complex = 1.0) None#

Compute the dot product of operator with array and add it to out array.

When represented by NumPy this operation would be out += z * (A @ x).

Parameters:
  • x (np.ndarray) – The vector/array to dot product with.

  • out (np.ndarray) – The array to which the outcome will be added.

  • z (complex) – scalar prefactor before addition, defaults to unity.

dot_h(x: ndarray, out: ndarray | None = None) ndarray#

Compute the dot product of operator adjoint with array, allows optional out.

When represented by NumPy this operation would be A.conj().T @ x. Though transpose returns only a view of a matrix, conjugate returns a copy, hence this method.

Parameters:
  • x (np.ndarray) – The vector/array to dot product with.

  • out (Optional[np.ndarray]) – Optional array to store results and avoid reallocation.

Returns:

The result of the dot product, A.conj().T @ x.

Return type:

np.ndarray

property dtype: OperatorDType#

The NumPy dtype.

matmat(X)#

Matrix-matrix multiplication.

Performs the operation y=A*X where A is an MxN linear operator and X dense N*K matrix or ndarray.

Parameters:

X ({matrix, ndarray}) – An array with shape (N,K).

Returns:

Y – A matrix or ndarray with shape (M,K) depending on the type of the X argument.

Return type:

{matrix, ndarray}

Notes

This matmat wraps any user-specified matmat routine or overridden _matmat method to ensure that y has the correct type.

matvec(x)#

Matrix-vector multiplication.

Performs the operation y=A*x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters:

x ({matrix, ndarray}) – An array with shape (N,) or (N,1).

Returns:

y – A matrix or ndarray with shape (M,) or (M,1) depending on the type and shape of the x argument.

Return type:

{matrix, ndarray}

Notes

This matvec wraps the user-specified matvec routine or overridden _matvec method to ensure that y has the correct shape and type.

rdot(x: ndarray) ndarray#

Compute the dot product of array with operator.

When represented by NumPy this operation would be x @ A.

Parameters:

x (np.ndarray) – The vector/array to dot product with.

Returns:

The result of the dot product, x @ A.

Return type:

np.ndarray

rdot_h(x: ndarray) ndarray#

Compute the dot product of array with operator adjoint.

When represented by NumPy this operation would be x @ A.conj().T.

Parameters:

x (np.ndarray) – The vector/array to dot product with.

Returns:

The result of the dot product, x @ A.conj().T.

Return type:

np.ndarray

rmatmat(X)#

Adjoint matrix-matrix multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array, or 2-d array. The default implementation defers to the adjoint.

Parameters:

X ({matrix, ndarray}) – A matrix or 2D array.

Returns:

Y – A matrix or 2D array depending on the type of the input.

Return type:

{matrix, ndarray}

Notes

This rmatmat wraps the user-specified rmatmat routine.

rmatvec(x)#

Adjoint matrix-vector multiplication.

Performs the operation y = A^H * x where A is an MxN linear operator and x is a column vector or 1-d array.

Parameters:

x ({matrix, ndarray}) – An array with shape (M,) or (M,1).

Returns:

y – A matrix or ndarray with shape (N,) or (N,1) depending on the type and shape of the x argument.

Return type:

{matrix, ndarray}

Notes

This rmatvec wraps the user-specified rmatvec routine or overridden _rmatvec method to ensure that y has the correct shape and type.

property shape: tuple[int, int]#

Returns the shape tuple of the class.

Returns:

The tuple containing the dimensions of the class.

Return type:

Tuple[int, …]

todense() ndarray#

Return the operator as a dense matrix.

Returns:

The operator as a dense matrix.

Return type:

np.ndarray

transpose()#

Transpose this linear operator.

Returns a LinearOperator that represents the transpose of this one. Can be abbreviated self.T instead of self.transpose().

class OperatorExpression#

Expression for constructing operators.

abstract add_triplets(info: OperatorInfo, scalar: float | complex, triplet_list: triplets | triplets_c) None#

Add scaled operator entries to the list of matrix entries.

class OperatorFromFunction(fun: Callable[[OperatorInfo, float | complex, triplets | triplets_c], None], dtype: OperatorDType)#

Create an operator expression from an add_triplets function.

Create OperatorFromFunction.

Parameters:
  • fun (Callable[[OperatorInfo, Scalar, TripletList], None]) – The add_triplets function, which adds the triplets representing the scaled operator to the given list.

  • dtype (OperatorDType) – The data type of the underlying vector space.

__init__(fun: Callable[[OperatorInfo, float | complex, triplets | triplets_c], None], dtype: OperatorDType) None#

Create OperatorFromFunction.

Parameters:
  • fun (Callable[[OperatorInfo, Scalar, TripletList], None]) – The add_triplets function, which adds the triplets representing the scaled operator to the given list.

  • dtype (OperatorDType) – The data type of the underlying vector space.

add_triplets(info: OperatorInfo, scalar: float | complex, triplet_list: triplets | triplets_c) None#

Add scaled operator entries to the list of matrix entries.

class VectorSpace(*, sites: int, particle_numbers: Literal['even', 'odd'] | int | tuple[int, int])#

The vector space for spinless fermions.

sites#

The number of sites.

Type:

int

particle_number_offset#

Together with particle_number_stride, defines the set of allowed particle numbers. The allowed particle numbers are particle_number_offset plus any multiple of particle_number_stride.

Type:

int

particle_number_stride#

Together with particle_number_stride, defines the set of allowed particle numbers. The allowed particle numbers are particle_number_offset plus any multiple of particle_number_stride.

Type:

int

dim#

The dimension of the vector space, i.e., the number of elements.

Type:

int

Create VectorSpace.

Parameters:
  • sites (int) – The number of sites.

  • particle_numbers ("even" | "odd" | int | tuple[int, int]) – Set to “even” and “odd” allows for all even and odd particle numbers, respectively. Set to an integer allows only this particular particle number. Set to a tuple, defines particle_number_offset and particle_number_stride.

__init__(*, sites: int, particle_numbers: Literal['even', 'odd'] | int | tuple[int, int]) None#

Create VectorSpace.

Parameters:
  • sites (int) – The number of sites.

  • particle_numbers ("even" | "odd" | int | tuple[int, int]) – Set to “even” and “odd” allows for all even and odd particle numbers, respectively. Set to an integer allows only this particular particle number. Set to a tuple, defines particle_number_offset and particle_number_stride.

copy(*, particle_number_change: int) VectorSpace#

Returns a new vector space with a different value for particles.

Parameters:

particle_number_change (int) – The value to be added to the number of particles. Allowed to be negative.

property dim: int#

The dimension of the vector space.

fock_state(occupation: list[int]) ndarray#

Returns an element of the occupancy number basis.

Parameters:

occupation (list[int]) – The occupation number per site. Must be 0 or 1.

annihilation(*, site: int | None = None, coef: ArrayLike | None = None) OperatorExpression#

Annihilation operator for a spinless fermions system.

Either site or coef needs to be specified.

Parameters:
  • site (int) – When specified return a annihilation operator for a specific site.

  • coef (ArrayLike) – When specified return a linear combination of annihilation operators. The coef array contains the coefficients, where the i-th entry corresponds to the annihilation operator at the i-th site.

anomalous_pairing(coef: ArrayLike) OperatorExpression#

The spinless fermion anomalous pairing term.

Parameters:

coef (ArrayLike) –

The “anomalous pairing” matrix \(D\). To define the pairing part, you should define the upper triangular part of the matrix U. Defining this matrix adds

\[\sum_{j,k=0}^{M-1} D_{jk} \, \hat{c}_j \hat{c}_k + D_{jk}^* \, \hat{c}_k^\dagger \hat{c}_j^\dagger\]

to the Hamiltonian.

creation(*, site: int | None = None, coef: ArrayLike | None = None) OperatorExpression#

Creation operator for a spinless fermions system.

Either site or coef needs to be specified.

Parameters:
  • site (int) – When specified return a creation operator for a specific site.

  • coef (ArrayLike) – When specified return a linear combination of creation operators. The coef array contains the coefficients, where the i-th entry corresponds to the creation operator at the i-th site.

hopping(coef: ArrayLike) OperatorExpression#

The spinless fermion hopping term.

Parameters:

coef (ArrayLike) –

The “hopping” matrix \(h_0\). The diagonal elements of \(h_0\) define the vector \(\varepsilon\) from the HQS Lattice Documentation, and the off-diagonal elements the matrix \(t\). In other words, defining the attribute h0 adds

\[\sum_{j,k=0}^{M-1} (h_0)_{jk} \, \hat{c}_j^\dagger \hat{c}_k = \sum_{j\not=k} (h_0)_{jk} \, \hat{c}_j^\dagger \hat{c}_k + \sum_{j=0}^{M-1} (h_0)_{jj} \, \hat{n}_j\]

to the Hamiltonian to be defined.

interaction(coef: ArrayLike) OperatorExpression#

The spinless fermion interaction term.

Parameters:

coef (ArrayLike) –

The “interaction” matrix \(U\). To define the interaction part, you should define the upper triangular part of the matrix U. Defining U, adds

\[\sum_{j,k=0}^{M-1} U_{jk}\, \left(\hat{n}_j - \tfrac12\middle) \middle(\hat{n}_k - \tfrac12\right)\]

to the Hamiltonian to be defined.

Note

The cofficient matrix must be real-valued.

lattice_terms(lattice: dict[str, Any] | lb.models.LatticeBuilderInputSpinless | lb.Builder) OperatorExpression#

Returns the terms corresonding to a Lattice Builder configuration or instance.