HamiltonianModel#

class HamiltonianModel(static_operator=None, operators=None, signals=None, rotating_frame=None, in_frame_basis=False, array_library=None, validate=True)[source]#

Bases: GeneratorModel

A model of a Hamiltonian for the Schrodinger equation.

This class represents a Hamiltonian as a time-dependent decomposition the form:

\[H(t) = H_d + \sum_j s_j(t) H_j,\]

where \(H_j\) are Hermitian operators, \(H_d\) is the static component, and the \(s_j(t)\) are either Signal objects or numerical constants. Constructing a HamiltonianModel requires specifying the above decomposition, e.g.:

hamiltonian = HamiltonianModel(
    static_operator=static_operator,
    operators=operators,
    signals=signals
)

This class inherits most functionality from GeneratorModel, with the following modifications:

  • The operators \(H_d\) and \(H_j\) are assumed and verified to be Hermitian.

  • Rotating frames are dealt with assuming the structure of the Schrodinger equation. I.e. Evaluating the Hamiltonian \(H(t)\) in a frame \(F = -iH_0\), evaluates the expression \(e^{-tF}H(t)e^{tF} - H_0\).

Initialize, ensuring that the operators are Hermitian.

Parameters:
  • static_operator (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list, None]) – Time-independent term in the Hamiltonian.

  • operators (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list, None]) – List of Operator objects.

  • signals (Union[SignalList, List[Signal], None]) – List of coefficients \(s_i(t)\). Not required at instantiation, but necessary for evaluation of the model.

  • rotating_frame (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list, RotatingFrame, None]) – Rotating frame operator. If specified with a 1d array, it is interpreted as the diagonal of a diagonal matrix. Assumed to store the antihermitian matrix F = -iH.

  • in_frame_basis (bool) – Whether to represent the model in the basis in which the rotating frame operator is diagonalized.

  • array_library (Optional[str]) – Array library with which to represent the operators in the model, and to evaluate the model. See the list of supported array libraries in the arraylias submodule API documentation. If None, the arrays will be handled by general dispatching rules.

  • validate (bool) – If True check input operators are Hermitian. Note that this is incompatible with JAX transformations.

Raises:

QiskitError – if operators are not Hermitian

Methods

evaluate(time)#

Evaluate the model in array format as a matrix, independent of state.

Parameters:

time (float) – The time to evaluate the model at.

Returns:

The evaluated model as a matrix.

Return type:

ArrayLike

Raises:

QiskitError – If model cannot be evaluated.

evaluate_rhs(time, y)#

Evaluate G(t) @ y.

Parameters:
  • time (float) – The time to evaluate the model at .

  • y (Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]) – Array specifying system state.

Return type:

Union[ndarray, number, int, float, complex, Tracer, Array, Array, spmatrix, BCOO, list]

Returns:

Array defined by \(G(t) \times y\).

Raises:

QiskitError – If model cannot be evaluated.

Attributes

array_library#

Array library with which to represent the operators in the model, and to evaluate the model.

See the list of supported array libraries in the arraylias submodule API documentation.

dim#

The matrix dimension.

in_frame_basis#

Whether or not the model is evaluated in the basis in which the frame is diagonalized.

operators#

The operators in the model.

rotating_frame#

The rotating frame.

signals#

The signals in the model.

Raises:

QiskitError – If set to None when operators exist, or when set to a number of signals different then the number of operators.

static_operator#

The static operator.