qp.labs.trotter_error.HOState¶
- class HOState(modes, gridpoints, state)[source]¶
Bases:
TrotterStateRepresent 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
HOStatefrom 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
HOStatefrom ascipy.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)
Methods
dot(other)Return the dot product of two
HOStateobjects.initialize_parallel_job(backend)Set up required for parallel compatibility.
start_parallel_job(backend)Start perturbation error computation in parallel.
zero_state(modes, gridpoints)Construct an
HOStatewhose vector is zero.- dot(other)[source]¶
Return the dot product of two
HOStateobjects.- 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
- initialize_parallel_job(backend)¶
Set up required for parallel compatibility. This method is called in
perturbation_error()before the parallel computations are called. Any required setup for parallel jobs goes into this function.
- start_parallel_job(backend)¶
Start perturbation error computation in parallel. This method is the first operation called in each parallel job dispatched by
perturbation_error(). Anything necessary to start the parallel job (such as reading from disk memory) goes into this function.
- classmethod zero_state(modes, gridpoints)[source]¶
Construct an
HOStatewhose vector is zero.- Parameters:
modes (int) – the number of vibrational modes
gridpoints (int) – the number of gridpoints used to discretize the state
- Returns:
an
HOStaterepresenting the zero state- Return type:
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)>)