pycommute.loperator

Linear operators in finite-dimensional Hilbert spaces

Elementary spaces

class pycommute.loperator.ElementarySpace

Hilbert space corresponding to one quantum degree of freedom

__eq__(self: pycommute.loperator.ElementarySpace, es2: pycommute.loperator.ElementarySpace) bool
__gt__(self: pycommute.loperator.ElementarySpace, es2: pycommute.loperator.ElementarySpace) bool
__hash__ = None
__lt__(self: pycommute.loperator.ElementarySpace, es2: pycommute.loperator.ElementarySpace) bool
__ne__(self: pycommute.loperator.ElementarySpace, es2: pycommute.loperator.ElementarySpace) bool
property algebra_id

ID of the algebra this elementary space is associated with.

property indices

Indices carried by this elementary space.

property n_bits

The minimal number of binary digits needed to represent any state in this elementary space.

class pycommute.loperator.ESpaceFermion

Bases: ElementarySpace

Elementary space generated by one fermionic degree of freedom

__init__(self: pycommute.loperator.ESpaceFermion, indices: pycommute.expression.Indices) None

Construct a 2-dimensional elementary space a fermionic creation/annihilation operator acts in.

Parameters:

indices – Index sequence of the corresponding creation/annihilation operator.

loperator.make_space_fermion(*args) pycommute.loperator.ESpaceFermion

Make a fermionic elementary space with indices passed as positional arguments.

Parameters:

*args – Indices of the corresponding creation/annihilation operator.

class pycommute.loperator.ESpaceBoson

Bases: ElementarySpace

Truncated \(2^n\)-dimensional elementary space generated by one bosonic degree of freedom

__init__(self: pycommute.loperator.ESpaceBoson, n_bits: int, indices: pycommute.expression.Indices) None

Construct a \(2^\text{n_bits}\)-dimensional elementary space a bosonic creation/annihilation operator acts in.

Parameters:
  • n_bits – Base-2 logarithm of the required space dimension.

  • indices – Index sequence of the creation/annihilation operator.

loperator.make_space_boson(n_bits: int, *args) pycommute.loperator.ESpaceBoson

Make a bosonic elementary space with indices passed as positional arguments.

Parameters:
  • n_bits – Base-2 logarithm of the required space dimension.

  • *args – Indices of the corresponding creation/annihilation operator.

class pycommute.loperator.ESpaceSpin

Bases: ElementarySpace

Elementary space generated by one spin degree of freedom

__init__(self: pycommute.loperator.ESpaceSpin, spin: float, indices: pycommute.expression.Indices) None

Construct an elementary space spin-\(S\) operators act in.

Parameters:
  • spin – Integer or half-integer value of spin \(S\).

  • indices – Index sequence of the corresponding spin operator.

loperator.make_space_spin(spin: float, *args) pycommute.loperator.ESpaceSpin

Make a spin elementary space with indices passed as positional arguments.

Parameters:
  • spin – Integer or half-integer value of spin \(S\).

  • *args – Indices of the corresponding spin operator.

Full Hilbert spaces

class pycommute.loperator.HilbertSpace

Bases: pybind11_object

Hilbert space as a direct product of elementary spaces

__contains__(self: pycommute.loperator.HilbertSpace, es: pycommute.loperator.ElementarySpace) bool

Is a given elementary space part of the direct product?

__copy__(self: pycommute.loperator.HilbertSpace) pycommute.loperator.HilbertSpace
__deepcopy__(self: pycommute.loperator.HilbertSpace, memo: dict) pycommute.loperator.HilbertSpace
__eq__(self: pycommute.loperator.HilbertSpace, hs: pycommute.loperator.HilbertSpace) bool
__hash__ = None
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pycommute.loperator.HilbertSpace) -> None

Construct an empty Hilbert space.

  1. __init__(self: pycommute.loperator.HilbertSpace, elementary_spaces: list[pycommute.loperator.ElementarySpace]) -> None

Construct from a list to elementary spaces.

  1. __init__(self: pycommute.loperator.HilbertSpace, expr: pycommute.expression.ExpressionR, bits_per_boson: int = 1) -> None

Inspect a real polynomial expression and collect elementary spaces associated to every algebra generator found in the expression.

Parameters:
  • expr – Polynomial expression to inspect.

  • bits_per_boson – Base-2 logarithm of the dimension of every bosonic elementary space to be constructed.

  1. __init__(self: pycommute.loperator.HilbertSpace, expr: pycommute.expression.ExpressionC, bits_per_boson: int = 1) -> None

Inspect a complex polynomial expression and collect elementary spaces associated to every algebra generator found in the expression.

Parameters:
  • expr – Polynomial expression to inspect.

  • bits_per_boson – Base-2 logarithm of the dimension of every bosonic elementary space to be constructed.

__len__(self: pycommute.loperator.HilbertSpace) int

Number of elementary spaces in the direct product.

__ne__(self: pycommute.loperator.HilbertSpace, hs: pycommute.loperator.HilbertSpace) bool
add(self: pycommute.loperator.HilbertSpace, es: pycommute.loperator.ElementarySpace) None

Add a new elementary space into the direct product.

Parameters:

es – Elementary space to add.

algebra_bit_range(self: pycommute.loperator.HilbertSpace, algebra_id: int) tuple[int, int]

Bit range spanned by a given algebra ID.

Parameters:

algebra_id – Algebra ID.

basis_state_index(self: pycommute.loperator.HilbertSpace, es: pycommute.loperator.ElementarySpace, n: int) int

Returns index of the product basis state, which decomposes over bases of the elementary spaces as \(|0\rangle |0\rangle \ldots |0\rangle |n\rangle_\text{es} |0\rangle \ldots |0\rangle\).

Parameters:
  • es – Elementary space corresponding to the arbitrary index in the decomposition.

  • n – Index of the basis state within the selected elementary space.

bit_range(self: pycommute.loperator.HilbertSpace, es: pycommute.loperator.ElementarySpace) tuple[int, int]

Bit range spanned by a given elementary space.

Parameters:

es – Elementary space.

property dim

Dimension of this Hilbert space, \(2^\text{total_n_bits}\).

has_algebra(self: pycommute.loperator.HilbertSpace, algebra_id: int) bool

Is an elementary space with a given algebra ID found in this Hilbert space?

Parameters:

algebra_id – Algebra ID.

index(self: pycommute.loperator.HilbertSpace, es: pycommute.loperator.ElementarySpace) int

Position of a given elementary space in the product.

property total_n_bits

The minimal number of binary digits needed to represent any state in this Hilbert space.

loperator.foreach(*args, **kwargs)

Overloaded function.

  1. foreach(hs: pycommute.loperator.HilbertSpace, f: Callable[[int], None]) -> None

Apply a given functor to all basis state indices in a Hilbert space.

Parameters:
  • hs – Hilbert space in question.

  • f – Functor to be applied.

  1. foreach(sp: pycommute.loperator.SpacePartition, f: Callable[[int, int], None]) -> None

Apply a given functor to all basis states in a given space partition. The functor must take two arguments, index of the basis state and index of the subspace this basis state belongs to.

Parameters:
  • sp – Space partition in question.

  • f – Functor to be applied.

Linear operators

class pycommute.loperator.LOperatorR

Real-valued linear operator

__call__(*args, **kwargs)

Overloaded function.

  1. __call__(self: pycommute.loperator.LOperatorR, src: numpy.ndarray[numpy.float64], dst: numpy.ndarray[numpy.float64]) -> None

Act on a real state vector and write the result into another real state vector.

Parameters:
  • src – Source state vector.

  • dst – Destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: numpy.ndarray[numpy.float64], dst: numpy.ndarray[numpy.complex128]) -> None

Act on a real state vector and write the result into another complex state vector.

Parameters:
  • src – Source state vector.

  • dst – Destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: numpy.ndarray[numpy.complex128], dst: numpy.ndarray[numpy.complex128]) -> None

Act on a complex state vector and write the result into another complex state vector.

Parameters:
  • src – Source state vector.

  • dst – Destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.MappedBasisViewR, dst: pycommute.loperator.MappedBasisViewR) -> None

Act on a mapped view of a real state vector and write the result through a view of another real state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.MappedBasisViewR, dst: pycommute.loperator.MappedBasisViewC) -> None

Act on a mapped view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.MappedBasisViewC, dst: pycommute.loperator.MappedBasisViewC) -> None

Act on a mapped view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionSectorViewR, dst: pycommute.loperator.NFermionSectorViewR) -> None

Act on an N-fermion sector view of a real state vector and write the result through a view of another real state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionSectorViewR, dst: pycommute.loperator.NFermionSectorViewC) -> None

Act on an N-fermion sector view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionSectorViewC, dst: pycommute.loperator.NFermionSectorViewC) -> None

Act on an N-fermion sector view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionMultiSectorViewR, dst: pycommute.loperator.NFermionMultiSectorViewR) -> None

Act on an N-fermion multisector view of a real state vector and write the result through a view of another real state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionMultiSectorViewR, dst: pycommute.loperator.NFermionMultiSectorViewC) -> None

Act on an N-fermion multisector view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorR, src: pycommute.loperator.NFermionMultiSectorViewC, dst: pycommute.loperator.NFermionMultiSectorViewC) -> None

Act on an N-fermion multisector view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

__init__(self: pycommute.loperator.LOperatorR, expr: pycommute.expression.ExpressionR, hs: pycommute.loperator.HilbertSpace) None

Construct the linear operator representing action of a given polynomial expression on a Hilbert space.

Parameters:
  • expr – Source polynomial expression.

  • hs – Hilbert space the linear operator acts on.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: pycommute.loperator.LOperatorR, sv: numpy.ndarray[numpy.float64]) -> numpy.ndarray[numpy.float64]

Act on a real state vector and return the resulting vector.

  1. __mul__(self: pycommute.loperator.LOperatorR, sv: numpy.ndarray[numpy.complex128]) -> numpy.ndarray[numpy.complex128]

Act on a complex state vector and return the resulting vector.

class pycommute.loperator.LOperatorC

Complex-valued linear operator

__call__(*args, **kwargs)

Overloaded function.

  1. __call__(self: pycommute.loperator.LOperatorC, src: numpy.ndarray[numpy.float64], dst: numpy.ndarray[numpy.complex128]) -> None

Act on a real state vector and write the result into another complex state vector.

Parameters:
  • src – Source state vector.

  • dst – Destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: numpy.ndarray[numpy.complex128], dst: numpy.ndarray[numpy.complex128]) -> None

Act on a complex state vector and write the result into another complex state vector.

Parameters:
  • src – Source state vector.

  • dst – Destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.MappedBasisViewR, dst: pycommute.loperator.MappedBasisViewC) -> None

Act on a mapped view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.MappedBasisViewC, dst: pycommute.loperator.MappedBasisViewC) -> None

Act on a mapped view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.NFermionSectorViewR, dst: pycommute.loperator.NFermionSectorViewC) -> None

Act on an N-fermion sector view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.NFermionSectorViewC, dst: pycommute.loperator.NFermionSectorViewC) -> None

Act on an N-fermion sector view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.NFermionMultiSectorViewR, dst: pycommute.loperator.NFermionMultiSectorViewC) -> None

Act on an N-fermion multisector view of a real state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

  1. __call__(self: pycommute.loperator.LOperatorC, src: pycommute.loperator.NFermionMultiSectorViewC, dst: pycommute.loperator.NFermionMultiSectorViewC) -> None

Act on an N-fermion multisector view of a complex state vector and write the result through a view of another complex state vector.

Parameters:
  • src – View of the source state vector.

  • dst – View of the destination state vector.

__init__(self: pycommute.loperator.LOperatorC, expr: pycommute.expression.ExpressionC, hs: pycommute.loperator.HilbertSpace) None

Construct the linear operator representing action of a given polynomial expression on a Hilbert space.

Parameters:
  • expr – Source polynomial expression.

  • hs – Hilbert space the linear operator acts on.

__mul__(*args, **kwargs)

Overloaded function.

  1. __mul__(self: pycommute.loperator.LOperatorC, sv: numpy.ndarray[numpy.float64]) -> numpy.ndarray[numpy.complex128]

Act on a real state vector and return the resulting vector.

  1. __mul__(self: pycommute.loperator.LOperatorC, sv: numpy.ndarray[numpy.complex128]) -> numpy.ndarray[numpy.complex128]

Act on a complex state vector and return the resulting vector.

Hilbert space partition

class pycommute.loperator.SpacePartition

Partition of a Hilbert space into a set of disjoint subspaces invariant under action of a given Hermitian operator (Hamiltonian).

For a detailed description of the algorithm see Computer Physics Communications 200, March 2016, 274-284 (section 4.2).

__copy__(self: pycommute.loperator.SpacePartition) pycommute.loperator.SpacePartition
__deepcopy__(self: pycommute.loperator.SpacePartition, memo: dict) pycommute.loperator.SpacePartition
__getitem__(self: pycommute.loperator.SpacePartition, basis_state_index: int) int

Find what invariant subspace a given basis state belongs to.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pycommute.loperator.SpacePartition, h: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace) -> None

Partition a finite-dimensional Hilbert space into a direct sum of invariant subspaces of a Hermitian operator.

Parameters:
  • h – Hermitian operator (Hamiltonian) used to partition the space.

  • hs – Hilbert space to partition.

  1. __init__(self: pycommute.loperator.SpacePartition, h: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace) -> None

Partition a finite-dimensional Hilbert space into a direct sum of invariant subspaces of a Hermitian operator.

Parameters:
  • h – Hermitian operator (Hamiltonian) used to partition the space.

  • hs – Hilbert space to partition.

property dim

Dimension of the original Hilbert space used to construct this partition.

find_connections(*args, **kwargs)

Overloaded function.

  1. find_connections(self: pycommute.loperator.SpacePartition, o: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace) -> set[tuple[int, int]]

Analyze connections between subspaces generated by a given operator \(\hat O\). The connections are returned as a set of pairs of subspace serial numbers, (source subspace, destination subspace).

Parameters:
  • o – Operator \(\hat O\).

  • hs – Hilbert space used to construct the original space partition.

Returns:

A set of (source subspace, destination subspace) index pairs.

  1. find_connections(self: pycommute.loperator.SpacePartition, o: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace) -> set[tuple[int, int]]

Analyze connections between subspaces generated by a given operator \(\hat O\). The connections are returned as a set of pairs of subspace serial numbers, (source subspace, destination subspace).

Parameters:
  • o – Operator \(\hat O\).

  • hs – Hilbert space used to construct the original space partition.

Returns:

A set of (source subspace, destination subspace) index pairs.

merge_subspaces(*args, **kwargs)

Overloaded function.

  1. merge_subspaces(self: pycommute.loperator.SpacePartition, od: pycommute.loperator.LOperatorR, o: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace, store_matrix_elements: bool = True) -> tuple[dict[tuple[int, int], float], dict[tuple[int, int], float]]

Merge some of the invariant subspaces to ensure that a given operator \(\hat O\) and its Hermitian conjugate \(\hat O^\dagger\) generate only one-to-one connections between the subspaces.

This function can optionally collect non-vanishing matrix elements of \(\hat O\) and \(\hat O^\dagger\) and return them in a form of dictionaries {(i, j) : O_ij}.

Parameters:
  • od – Operator \(\hat O^\dagger\).

  • o – Operator \(\hat O\).

  • hs – Hilbert space used to construct the original space partition.

  • store_matrix_elements – Collect the non-vanishing matrix elements of od and o.

Returns:

A tuple containing dictionaries with the collected matrix elements of \(\hat O^\dagger\) and \(\hat O\) (empty dictionaries when store_matrix_elements = False).

  1. merge_subspaces(self: pycommute.loperator.SpacePartition, od: pycommute.loperator.LOperatorC, o: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace, store_matrix_elements: bool = True) -> tuple[dict[tuple[int, int], complex], dict[tuple[int, int], complex]]

Merge some of the invariant subspaces to ensure that a given operator \(\hat O\) and its Hermitian conjugate \(\hat O^\dagger\) generate only one-to-one connections between the subspaces.

This function can optionally collect non-vanishing matrix elements of \(\hat O\) and \(\hat O^\dagger\) and return them in a form of dictionaries {(i, j) : O_ij}.

Parameters:
  • od – Operator \(\hat O^\dagger\).

  • o – Operator \(\hat O\).

  • hs – Hilbert space used to construct the original space partition.

  • store_matrix_elements – Collect the non-vanishing matrix elements of od and o.

Returns:

A tuple containing dictionaries with the collected matrix elements of \(\hat O^\dagger\) and \(\hat O\) (empty dictionaries when store_matrix_elements = False).

property n_subspaces

Number of invariant subspaces in this partition.

subspace_bases(self: pycommute.loperator.SpacePartition) list[list[int]]

Build and return lists of indices of all basis states spanning all invariant subspaces in the partition. The returned lists are disjoint and their union spans the entire Hilbert space.

subspace_basis(self: pycommute.loperator.SpacePartition, index: int) list[int]

Build and return a list of indices of all basis states spanning a given invariant subspace.

Parameters:

index – Index of the invariant subspace.

loperator.make_space_partition(*args, **kwargs)

Overloaded function.

  1. make_space_partition(h: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace, store_matrix_elements: bool = True) -> tuple[pycommute.loperator.SpacePartition, dict[tuple[int, int], float]]

Constructs a partition of a finite-dimensional Hilbert space into a direct sum of invariant subspaces of a given Hermitian operator.

This function can optionally collect non-vanishing matrix elements \(H_{ij}\) of the Hermitian operator and return them in a form of a dictionary {(i, j) : H_ij}.

Parameters:
  • h – Hermitian operator (Hamiltonian) \(\hat H\) used to partition the space.

  • hs – Hilbert space to partition.

  • store_matrix_elements – Collect the non-vanishing matrix elements of h.

Returns:

A tuple containing the constructed SpacePartition object and a dictionary with the collected matrix elements (an empty dictionary when store_matrix_elements = False).

  1. make_space_partition(h: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace, store_matrix_elements: bool = True) -> tuple[pycommute.loperator.SpacePartition, dict[tuple[int, int], complex]]

Constructs a partition of a finite-dimensional Hilbert space into a direct sum of invariant subspaces of a given Hermitian operator.

This function can optionally collect non-vanishing matrix elements \(H_{ij}\) of the Hermitian operator and return them in a form of a dictionary {(i, j) : H_ij}.

Parameters:
  • h – Hermitian operator (Hamiltonian) \(\hat H\) used to partition the space.

  • hs – Hilbert space to partition.

  • store_matrix_elements – Collect the non-vanishing matrix elements of h.

Returns:

A tuple containing the constructed SpacePartition object and a dictionary with the collected matrix elements (an empty dictionary when store_matrix_elements = False).

Mapped views of state vectors

class pycommute.loperator.MappedBasisViewR

This object is a view of a real state vector (one-dimensional NumPy array) that performs index translation according to a predefined map. It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

MappedBasisViewR can be used in situations where a linear operator is known to act only within a subspace of a full Hilbert space, and it is desirable to store vector components only within this particular subspace. The relevant components are then stored in a NumPy array, while the view object translates indices of basis states from the full Hilbert space to the smaller subspace.

__init__(*args, **kwargs)
class pycommute.loperator.MappedBasisViewC

This object is a view of a complex state vector (one-dimensional NumPy array) that performs index translation according to a predefined map. It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

MappedBasisViewC can be used in situations where a linear operator is known to act only within a subspace of a full Hilbert space, and it is desirable to store vector components only within this particular subspace. The relevant components are then stored in a NumPy array, while the view object translates indices of basis states from the full Hilbert space to the smaller subspace.

__init__(*args, **kwargs)
class pycommute.loperator.BasisMapper

Factory class for MappedBasisViewR and MappedBasisViewC objects

__call__(*args, **kwargs)

Overloaded function.

  1. __call__(self: pycommute.loperator.BasisMapper, sv: numpy.ndarray[numpy.float64]) -> pycommute.loperator.MappedBasisViewR

Make a basis mapping view of a real state vector (1-dimensional NumPy array).

Parameters:

sv – The state vector to make the view of.

  1. __call__(self: pycommute.loperator.BasisMapper, sv: numpy.ndarray[numpy.complex128]) -> pycommute.loperator.MappedBasisViewC

Make a basis mapping view of a complex state vector (1-dimensional NumPy array).

Parameters:

sv – The state vector to make the view of.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pycommute.loperator.BasisMapper, basis_state_indices: list[int]) -> None

Build a mapping from a list of basis state indices to their positions within the list.

Parameters:

basis_state_indices – List of the basis state indices.

  1. __init__(self: pycommute.loperator.BasisMapper, O: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace) -> None

Build a mapping from a set of all basis states contributing to \(\hat O|0\rangle\), where \(|0\rangle\) is the product basis state corresponding to zero index in each elementary space.

\[|0\rangle = |0\rangle_1 |0\rangle_2 |0\rangle_3 \ldots.\]
Parameters:
  • O – Real-valued linear operator \(\hat O\).

  • hs – Hilbert space \(\hat O\) acts in.

  1. __init__(self: pycommute.loperator.BasisMapper, O: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace) -> None

Build a mapping from a set of all basis states contributing to \(\hat O|0\rangle\), where \(|0\rangle\) is the product basis state corresponding to zero index in each elementary space.

\[|0\rangle = |0\rangle_1 |0\rangle_2 |0\rangle_3 \ldots.\]
Parameters:
  • O – Complex-valued linear operator \(\hat O\).

  • hs – Hilbert space \(\hat O\) acts in.

  1. __init__(self: pycommute.loperator.BasisMapper, O_list: list[pycommute.loperator.LOperatorR], hs: pycommute.loperator.HilbertSpace, N: int) -> None

Given a list of operators \(\{\hat O_1, \hat O_2, \hat O_3, \ldots, \hat O_M\}\), build a mapping including all basis states that contribute to all states \(\hat O_1^{n_1} \hat O_2^{n_2} \ldots \hat O_M^{n_M} |0\rangle\).

\(|0\rangle\) is the product basis state corresponding to zero index in each elementary space,

\[|\hat 0\rangle = |0\rangle_1 |0\rangle_2 |0\rangle_3 \ldots,\]

and the non-negative integers \(n_m\) satisfy \(\sum_{m=1}^M n_m = N\). Mapped values are assigned continuously but without any specific order.

Parameters:
  • O_list – List of real-valued linear operators \(\{\hat O_m\}\).

  • hs – Hilbert space operators \(\hat O_m\) act in.

  • N – Total power \(N\).

  1. __init__(self: pycommute.loperator.BasisMapper, O_list: list[pycommute.loperator.LOperatorC], hs: pycommute.loperator.HilbertSpace, N: int) -> None

Given a list of operators \(\{\hat O_1, \hat O_2, \hat O_3, \ldots, \hat O_M\}\), build a mapping including all basis states that contribute to all states \(\hat O_1^{n_1} \hat O_2^{n_2} \ldots \hat O_M^{n_M} |0\rangle\).

\(|0\rangle\) is the product basis state corresponding to zero index in each elementary space,

\[|\hat 0\rangle = |0\rangle_1 |0\rangle_2 |0\rangle_3 \ldots,\]

and the non-negative integers \(n_m\) satisfy \(\sum_{m=1}^M n_m = N\). Mapped values are assigned continuously but without any specific order.

Parameters:
  • O_list – List of complex-valued linear operators \(\{\hat O_m\}\).

  • hs – Hilbert space operators \(\hat O_m\) act in.

  • N – Total power \(N\).

__len__(self: pycommute.loperator.BasisMapper) int

Number of basis states in the mapping.

property inverse_map

Direct access to the inverse mapping as Dict[int, int]. (slow!)

property map

Direct access to the mapping as Dict[int, int].

N-fermion sector views of state vectors

loperator.n_fermion_sector_size(hs: pycommute.loperator.HilbertSpace, N: int) int

Compute size of a sector (subspace of a full Hilbert space) with a fixed number of fermions.

Parameters:
  • hs – Hilbert space.

  • N – Number of fermions in the sector.

loperator.n_fermion_sector_basis_states(hs: pycommute.loperator.HilbertSpace, N: int) list[int]

Return a list of basis states in a sector (subspace of a full Hilbert space) with a fixed number of fermions.

Parameters:
  • hs – Hilbert space.

  • N – Number of fermions in the sector.

class pycommute.loperator.NFermionSectorViewR

This object is a view of a real state vector (one-dimensional NumPy array) that performs basis state index translation from a full Hilbert space to its N-fermion subspace (sector). It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

NFermionSectorViewR can be used in situations where a linear operator is known to act only within the N-fermion sector, and it is desirable to store vector components only within this particular sector.

__init__(self: pycommute.loperator.NFermionSectorViewR, sv: numpy.ndarray[numpy.float64], hs: pycommute.loperator.HilbertSpace, N: int) None

Construct an N-fermion sector view of a state vector.

Parameters:
  • sv – The state vector to make the view of.

  • hs – Hilbert space.

  • N – Number of fermions in the sector.

map_index(self: pycommute.loperator.NFermionSectorViewR, index: int) int

Map a basis state index from the full Hilbert space to the sector.

Parameters:

index – The basis state index in the full Hilbert space.

class pycommute.loperator.NFermionSectorViewC

This object is a view of a complex state vector (one-dimensional NumPy array) that performs basis state index translation from a full Hilbert space to its N-fermion subspace (sector). It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

NFermionSectorViewC can be used in situations where a linear operator is known to act only within the N-fermion sector, and it is desirable to store vector components only within this particular sector.

__init__(self: pycommute.loperator.NFermionSectorViewC, sv: numpy.ndarray[numpy.complex128], hs: pycommute.loperator.HilbertSpace, N: int) None

Construct an N-fermion sector view of a state vector.

Parameters:
  • sv – The state vector to make the view of.

  • hs – Hilbert space.

  • N – Number of fermions in the sector.

map_index(self: pycommute.loperator.NFermionSectorViewC, index: int) int

Map a basis state index from the full Hilbert space to the sector.

Parameters:

index – The basis state index in the full Hilbert space.

loperator.n_fermion_multisector_size(hs: pycommute.loperator.HilbertSpace, sectors: list[tuple[list[list[int | str]], int]]) int

Compute size of a multisector (subspace of a full Hilbert space). A multisector is a set of all basis states, which have \(N_1\) particles within a subset of fermionic modes \(\{S_1\}\), \(N_2\) particles within another subset \(\{S_2\}\) and so on. There can be any number of individual pairs \((\{S_i\}, N_i)\) (sectors contributing to the multisector) as long as all subsets \(\{S_i\}\) are disjoint.

Parameters:
  • hs – Hilbert space.

  • sectors – List of sector descriptors. Each element of the list is a \((\{S_i\}, N_i)\) pair, where \(\{S_i\}\) is a set of index sequences corresponding to the relevant fermionic degrees of freedom.

loperator.n_fermion_multisector_basis_states(hs: pycommute.loperator.HilbertSpace, sectors: list[tuple[list[list[int | str]], int]]) list[int]

Return a list of basis states in a multisector (subspace of a full Hilbert space). A multisector is a set of all basis states, which have \(N_1\) particles within a subset of fermionic modes \(\{S_1\}\), \(N_2\) particles within another subset \(\{S_2\}\) and so on. There can be any number of individual pairs \((\{S_i\}, N_i)\) (sectors contributing to the multisector) as long as all subsets \(\{S_i\}\) are disjoint.

Parameters:
  • hs – Hilbert space.

  • sectors – List of sector descriptors. Each element of the list is a \((\{S_i\}, N_i)\) pair, where \(\{S_i\}\) is a set of index sequences corresponding to the relevant fermionic degrees of freedom.

class pycommute.loperator.NFermionMultiSectorViewR

This object is a view of a real state vector (one-dimensional NumPy array) that performs basis state index translation from a full Hilbert space to an N-fermion multisector. It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

A multisector is a set of all basis states, which have \(N_1\) particles within a subset of fermionic modes \(\{S_1\}\), \(N_2\) particles within another subset \(\{S_2\}\) and so on. There can be any number of individual pairs \((\{S_i\}, N_i)\) (sectors contributing to the multisector) as long as all subsets \(\{S_i\}\) are disjoint.

NFermionMultiSectorViewR can be used in situations where a linear operator is known to act only within the multisector, and it is desirable to store vector components only within this particular multisector.

__init__(self: pycommute.loperator.NFermionMultiSectorViewR, sv: numpy.ndarray[numpy.float64], hs: pycommute.loperator.HilbertSpace, sectors: list[tuple[list[list[int | str]], int]]) None

Construct an N-fermion multisector view of a state vector.

Parameters:
  • sv – The state vector to make the view of.

  • hs – Hilbert space.

  • sectors – List of sector descriptors. Each element of the list is a \((\{S_i\}, N_i)\) pair, where \(\{S_i\}\) is a set of index sequences corresponding to the relevant fermionic degrees of freedom.

map_index(self: pycommute.loperator.NFermionMultiSectorViewR, index: int) int

Map a basis state index from the full Hilbert space to the multisector.

Parameters:

index – The basis state index in the full Hilbert space.

class pycommute.loperator.NFermionMultiSectorViewC

This object is a view of a complex state vector (one-dimensional NumPy array) that performs basis state index translation from a full Hilbert space to an N-fermion multisector. It is accepted by methods of linear operator objects LOperatorR.__call__() and LOperatorC.__call__().

A multisector is a set of all basis states, which have \(N_1\) particles within a subset of fermionic modes \(\{S_1\}\), \(N_2\) particles within another subset \(\{S_2\}\) and so on. There can be any number of individual pairs \((\{S_i\}, N_i)\) (sectors contributing to the multisector) as long as all subsets \(\{S_i\}\) are disjoint.

NFermionMultiSectorViewC can be used in situations where a linear operator is known to act only within the multisector, and it is desirable to store vector components only within this particular multisector.

__init__(self: pycommute.loperator.NFermionMultiSectorViewC, sv: numpy.ndarray[numpy.complex128], hs: pycommute.loperator.HilbertSpace, sectors: list[tuple[list[list[int | str]], int]]) None

Construct an N-fermion multisector view of a state vector.

Parameters:
  • sv – The state vector to make the view of.

  • hs – Hilbert space.

  • sectors – List of sector descriptors. Each element of the list is a \((\{S_i\}, N_i)\) pair, where \(\{S_i\}\) is a set of index sequences corresponding to the relevant fermionic degrees of freedom.

map_index(self: pycommute.loperator.NFermionMultiSectorViewC, index: int) int

Map a basis state index from the full Hilbert space to the multisector.

Parameters:

index – The basis state index in the full Hilbert space.

Matrix representation of linear operators

loperator.make_matrix(*args, **kwargs)

Overloaded function.

  1. make_matrix(lop: pycommute.loperator.LOperatorR, hs: pycommute.loperator.HilbertSpace) -> numpy.ndarray[numpy.float64]

Make a matrix representation of a given real linear operator acting in a Hilbert space.

Parameters:
  • lop – Linear operator.

  • hs – Hilbert space.

Returns:

Matrix representation as a two-dimensional NumPy array.

  1. make_matrix(lop: pycommute.loperator.LOperatorR, basis_state_indices: list[int]) -> numpy.ndarray[numpy.float64]

Make a matrix representation of a given real linear operator acting in a subspace of a Hilbert space spanned by a list of basis states.

Parameters:
  • lop – Linear operator.

  • basis_state_indices – Indices of basis states spanning the subspace.

Returns:

Matrix representation as a two-dimensional NumPy array.

  1. make_matrix(lop: pycommute.loperator.LOperatorR, left_basis_state_indices: list[int], right_basis_state_indices: list[int]) -> numpy.ndarray[numpy.float64]

Make a matrix representation of a given real linear operator (mapping) transforming states from a subspace of a Hilbert space into states from its other subspace. Both subspaces are specified by lists of basis states spanning them.

Parameters:
  • lop – Linear operator.

  • left_basis_state_indices – Indices of basis states spanning the target subspace.

  • right_basis_state_indices – Indices of basis states spanning the domain.

Returns:

Matrix representation as a two-dimensional NumPy array.

  1. make_matrix(lop: pycommute.loperator.LOperatorC, hs: pycommute.loperator.HilbertSpace) -> numpy.ndarray[numpy.complex128]

Make a matrix representation of a given complex linear operator acting in a Hilbert space.

Parameters:
  • lop – Linear operator.

  • hs – Hilbert space.

Returns:

Matrix representation as a two-dimensional NumPy array.

  1. make_matrix(lop: pycommute.loperator.LOperatorC, basis_state_indices: list[int]) -> numpy.ndarray[numpy.complex128]

Make a matrix representation of a given complex linear operator acting in a subspace of a Hilbert space spanned by a list of basis states.

Parameters:
  • lop – Linear operator.

  • basis_state_indices – Indices of basis states spanning the subspace.

Returns:

Matrix representation as a two-dimensional NumPy array.

  1. make_matrix(lop: pycommute.loperator.LOperatorC, left_basis_state_indices: list[int], right_basis_state_indices: list[int]) -> numpy.ndarray[numpy.complex128]

Make a matrix representation of a given complex linear operator (mapping) transforming states from a subspace of a Hilbert space into states from its other subspace. Both subspaces are specified by lists of basis states spanning them.

Parameters:
  • lop – Linear operator.

  • left_basis_state_indices – Indices of basis states spanning the target subspace.

  • right_basis_state_indices – Indices of basis states spanning the domain.

Returns:

Matrix representation as a two-dimensional NumPy array.