fulqrum.core.SubspaceHamiltonian

class SubspaceHamiltonian(*args, **kwargs)[source]

A SciPy LinearOperator that represents a Hamiltonian restricted to the given subspace.

Methods

diagonal_vector([disable_fast_mode])

Return diagonal vector of Hamiltonian in subspace

get_n_th_bitstring(n)

Return n-th bitstring in the SubspaceHamiltonian

interpret_vector(vec[, atol, sort, renormalize])

Convert solution vector into dict of counts and real or complex amplitudes

matvec(x)

Matrix-free implementation of SpMV for subspace Hamiltonian

minimum_diagonal_energy()

Return the minimum diagonal energy

to_csr_linearoperator()

Convert subspace Hamiltonian to a LinearOperator wrapping a CSR matrix

to_csr_linearoperator_fast()

Convert subspace Hamiltonian to a CSR LinearOperator faster but with a copy

update_subspace(subspace)

Replace the subspace used for projection with another.

Attributes

H

Hermitian adjoint.

T

Transpose.

num_groups

Number of off-diagonal groupings

ndim

diagonal_vector(disable_fast_mode=False)[source]

Return diagonal vector of Hamiltonian in subspace

Parameters:

disable_fast_mode (bool) – optional, disable fast computation for type=2 Hamiltonians, default=False

Returns:

Complex vector for diagonal of Hamiltonian

Return type:

ndarray

get_n_th_bitstring(n)[source]

Return n-th bitstring in the SubspaceHamiltonian

Parameters:

n (int) – Index of the expected bitstring.

Returns:

N-th bitstring in the subspace.

Return type:

str

Note

Both Python dictionaries and emhash8::HashMap retain insertion order.

Raises:

ValueError – If n is >= to the number of bit-strings in the subspace.

interpret_vector(vec, atol=1e-14, sort=False, renormalize=True)[source]

Convert solution vector into dict of counts and real or complex amplitudes

Parameters:
  • vec (ndarray) – Complex or real solution vector

  • atol (double) – Absolute tolerance for truncation, default=1e-14

  • sort (bool) – Sort output dict by integer representation, default=False.

  • renormalize (bool) – Renormalize values such that probabilities sum to one, default = True

Returns:

Dictionary with bit-string keys and complex values

Return type:

dict

Note

Truncation can be disabled by calling atol=0

matvec(x)[source]

Matrix-free implementation of SpMV for subspace Hamiltonian

Parameters:

x (ndarray) – Input array

Returns:

Output vector after SpMV on input vector

Return type:

ndarray

minimum_diagonal_energy()[source]

Return the minimum diagonal energy

Returns:

Lowest energy value

Return type:

double

property num_groups

Number of off-diagonal groupings

Returns:

Number of groups in operator

Return type:

int

to_csr_linearoperator()[source]

Convert subspace Hamiltonian to a LinearOperator wrapping a CSR matrix

Returns:

LinearOperator wrapping a CSR matrix.

Return type:

CSRLinearOperator

to_csr_linearoperator_fast()[source]

Convert subspace Hamiltonian to a CSR LinearOperator faster but with a copy

Returns:

LinearOperator wrapping a CSR matrix.

Return type:

CSRLinearOperator

update_subspace(subspace)[source]

Replace the subspace used for projection with another.

Notes

This does not update the current subspace in-place.