HamiltonianModel#

class HamiltonianModel(static_operator=None, operators=None, signals=None, rotating_frame=None, in_frame_basis=False, evaluation_mode='dense', 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 (Optional[Array]) – Time-independent term in the Hamiltonian.

  • operators (Optional[List[Operator]]) – 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[Operator, Array, 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.

  • evaluation_mode (str) – Evaluation mode to use. Supported options are 'dense' and 'sparse'. Call help(HamiltonianModel.evaluation_mode) for more details.

  • validate (bool) – If True check input operators are Hermitian.

Raises:

QiskitError – if operators are not Hermitian

Methods

copy()#

Return a copy of self.

evaluate(time)[source]#

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 an anti-Hermitian matrix.

Return type:

Array

Raises:

QiskitError – If model cannot be evaluated.

evaluate_rhs(time, y)[source]#

Evaluate -1j * H(t) @ y.

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

  • y (Array) – Array specifying system state.

Return type:

Array

Returns:

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

Raises:

QiskitError – If model cannot be evaluated.

Attributes

dim#

The matrix dimension.

evaluation_mode#

Numerical evaluation mode of the model.

Possible values:

  • "dense": Stores/evaluates operators using dense Arrays.

  • "sparse": Stores/evaluates operators using sparse matrices. If the default Array backend is JAX, implemented with JAX BCOO arrays, otherwise uses scipy csr_matrix sparse type. Note that JAX sparse mode is only recommended for use on CPU.

Raises:
  • NotImplementedError – If, when being set, new_mode is not one of the above supported

  • evaluation modes.

in_frame_basis#

Whether the model is represented in the basis that diagonalizes the frame operator.

operators#

The operators in the model.

rotating_frame#

The rotating frame.

This property can be set with a RotatingFrame instance, or any valid constructor argument to this class. It can either be Hermitian or anti-Hermitian, and in either case only the anti-Hermitian version \(F=-iH\) will be stored.

Setting this property updates the internal operator list to use the new 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.