qml.labs.trotter_error.HOState

class HOState(modes, gridpoints, state)[source]

Bases: object

Represent a wavefunction in the harmonic oscillator basis.

Parameters:
  • modes (int) – the number of vibrational modes

  • gridpoints (int) – the number of gridpoints used to discretize the state

  • state – (Union[scipy.sparse.csr_array, Dict[Tuple[int], float]]): a sparse state vector for the full wavefunction or a dictionary containing the interacting modes and their non-zero coefficients

Examples

Building an HOState from a dictionary

>>> from pennylane.labs.trotter_error import HOState
>>> n_modes = 3
>>> gridpoints = 5
>>> state_dict = {(1, 2, 3): 1, (0, 3, 2): 1}
>>> HOState(n_modes, gridpoints, state_dict)
HOState(modes=3, gridpoints=5, <Compressed Sparse Row sparse array of dtype 'int64'
    with 2 stored elements and shape (125, 1)>
  Coords    Values
  (17, 0)   1
  (38, 0)   1)

Building an HOState from a scipy.sparse.csr_array

>>> from scipy.sparse import csr_array
>>> import numpy as np
>>> gridpoints = 2
>>> n_modes = 2
>>> state_vector = csr_array(np.array([0, 1, 0, 0]))
>>> HOState(n_modes, gridpoints, state_vector)
HOState(modes=2, gridpoints=2, <COOrdinate sparse array of dtype 'int64'
    with 1 stored elements and shape (4, 1)>
  Coords    Values
  (1, 0)    1)

dot(other)

Return the dot product of two HOState objects.

zero_state(modes, gridpoints)

Construct an HOState whose vector is zero.

dot(other)[source]

Return the dot product of two HOState objects.

Parameters:

other (HOState) – the state to take the dot product with

Returns:

the dot product of the two states

Return type:

float

Example

>>> from pennylane.labs.trotter_error import HOState
>>> n_modes = 3
>>> gridpoints = 5
>>> state_dict = {(1, 2, 3): 1, (0, 3, 2): 1}
>>> state1 = HOState(n_modes, gridpoints, state_dict)
>>> state1.dot(state1)
2
classmethod zero_state(modes, gridpoints)[source]

Construct an HOState whose vector is zero.

Parameters:
  • modes (int) – the number of vibrational modes

  • gridpoints (int) – the number of gridpoints used to discretize the state

Returns:

an HOState representing the zero state

Return type:

HOState

Example

>>> from pennylane.labs.trotter_error import HOState
>>> HOState.zero_state(5, 10)
HOState(modes=5, gridpoints=10, <Compressed Sparse Row sparse array of dtype 'float64'
    with 0 stored elements and shape (100000, 1)>)