ofex.hamiltonian_functions

ofex.hamiltonian_functions.hamiltonian_fourier_series(coeff: ndarray, freqs: ndarray, real_time_propagator: spmatrix | ndarray | None = None, normalized_pham: QubitOperator | ndarray | spmatrix | None = None, n_qubits: int | None = None, exact_sparse: bool = False) spmatrix | ndarray[source]

Computes a Fourier series representation of a function of the Hamiltonian, F(H) = \sum_{k=-N}^{N} c_k e^{i \omega_k t}.

This function calculates the Fourier series representation of a function of the Hamiltonian, using user-defined coefficients and frequencies. The representation can be constructed by directly using a precomputed real-time propagator or by providing the normalized Hamiltonian and system specifications.

Parameters:
  • coeff (np.ndarray) – Fourier series coefficients, where the middle element corresponds to the zero frequency.

  • freqs (np.ndarray) – Frequencies corresponding to the Fourier coefficients. Must be a 1-dimensional array with an odd number of equally spaced elements, and the middle value must be zero.

  • real_time_propagator (Optional[Union[spmatrix, np.ndarray]]) – Precomputed propagator for evolving the function of the Hamiltonian in real-time. If not provided, both normalized_pham and n_qubits must be specified.

  • normalized_pham (Optional[Union[QubitOperator, np.ndarray, spmatrix]]) – Normalized Hamiltonian with the spectral norm less than or equal to one to used to compute the propagator if real_time_propagator is not provided.

  • n_qubits (Optional[int]) – Number of qubits for the normalized Hamiltonian, required when real_time_propagator is not specified.

  • exact_sparse (bool) – Whether to use sparse matrix operations when building the propagator internally. Only used when real_time_propagator is not provided.

Returns:

The Fourier series representation of a function of the Hamiltonian, as either a sparse or dense matrix, depending on the input type of real_time_propagator.

Return type:

Union[spmatrix, np.ndarray]

Raises:
  • ValueError – If coeff and freqs have mismatched shapes, freqs is not 1D, freqs does not have equally spaced values, or its middle value is not zero.

  • OfexTypeError – If real_time_propagator is not a supported type (e.g., sparse matrix or dense ndarray).