Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

TimeEvolutionPulse

A TimeEvolutionPulse is defined by a time. To create a time evolution pulse the easiest way is to use the from_string method of NMRPulse class.

The str format for a time evolution pulse is the time preceeded by the letter t.

The time can be any number. The hamiltonian used for the time evolution should be provided when calling the apply_pulse_operator method.

This pulse applies the time evolution of the provided hamiltonian for a period of time t.

from hqs_nmr.pulse_sequence import NMRPulse

rotation_pulse = NMRPulse.from_string("t2")
rotation_pulse2 = NMRPulse.from_string("t0.0001")
rotation_pulse2 = NMRPulse.from_string("t-0.01")

One can also use this pulse to gather the expectation values during the time evolution. The default timestep is 0.01 and can be selected with the following pattern.

from hqs_nmr.pulse_sequence import NMRPulse

rotation_pulse = NMRPulse.from_string("t2s0.001")

Methods

apply_pulse_operator

def apply_pulse_operator(
    self,
    density_mat: np.ndarray,
    **kwargs: Any,
) -> np.ndarray:
    """Applies the time evolution pulse P = exp(-i*H*t) on the density matrix.

    Args:
        density_mat (np.ndarray): The initial density matrix rho_0.
        **kwargs: Additional arguments (one of the following is required):
            hamiltonian (np.ndarray): The Hamiltonian matrix H. The time evolution 
                operator is computed as P = exp(-i * t * H) using matrix exponential.
                If a Hamiltonian was provided when creating the pulse, it takes
                precedence.
            eigen_hamiltonian (Tuple[np.ndarray, np.ndarray]): Alternative to hamiltonian.
                A tuple of (eigenvalues, eigenvectors) of the Hamiltonian. This provides
                more efficient time evolution using: P = V @ diag(exp(-i * t * λ)) @ V†
                where λ are the eigenvalues and V are the eigenvectors.

    Returns:
        np.ndarray: The evolved density matrix P @ rho_0 @ P†.
        
    Raises:
        ValueError: If neither hamiltonian nor eigen_hamiltonian is provided.
    """

Example:

from hqs_nmr.pulse_sequence.pulses import TimeEvolutionPulse
import numpy as np

pulse = TimeEvolutionPulse(t=5.0, timestep=0.01)
hamiltonian = np.array([[1.0, 0.1], [0.1, -1.0]], dtype=complex)
density_mat = np.eye(2, dtype=complex) / 2

# Apply time evolution
result = pulse.apply_pulse_operator(density_mat, hamiltonian=hamiltonian)

# Or use eigendecomposition for efficiency
eigenvalues, eigenvectors = np.linalg.eigh(hamiltonian)
result = pulse.apply_pulse_operator(
    density_mat, 
    eigen_hamiltonian=(eigenvalues, eigenvectors)
)

apply_time_evolution

def apply_time_evolution(
    self,
    density_mat: np.ndarray,
    measurement_operator: Union[np.ndarray, List[np.ndarray]],
    t_0: float = 0,
    correlation_operator: Optional[np.ndarray] = None,
    **kwargs,
) -> Tuple[Union[List[complex], list[List[complex]]], np.ndarray, List[float]]:
    """Applies the time evolution and collects expectation values at each timestep.

    This method evolves the density matrix under the Hamiltonian for the specified time,
    recording the expectation value of the measurement operator at each timestep interval.
    The timesteps are determined by the `timestep` attribute of the pulse.

    Args:
        density_mat (np.ndarray): The initial density matrix.
        measurement_operator (Union[np.ndarray, List[np.ndarray]]): The operator(s) whose
            expectation value ⟨M⟩ = Tr(M @ rho(t)) is recorded at each timestep.
        t_0: Time at the start of the pulse
        correlation_operator: Operator whose expectation value is recorded
        kwargs: Additional arguments (one of the following is required):
            hamiltonian (np.ndarray): The Hamiltonian matrix. If a Hamiltonian was
                provided when creating the pulse, it takes precedence.
            eigen_hamiltonian (Tuple[np.ndarray, np.ndarray]): Alternative to hamiltonian.

    Returns:
        Tuple[Union[List[complex], list[List[complex]]], np.ndarray, List[float]]: A tuple containing:
            - Union[List[complex], list[List[complex]]]: Expectation values at each timestep
              from t=t_0 to t=t_0+self.t in intervals of self.timestep.
            - np.ndarray: The final density matrix after full time evolution.
            - List[float]: The times of each timestep
    """

Example:

from hqs_nmr.pulse_sequence.pulses import TimeEvolutionPulse
import numpy as np

pulse = TimeEvolutionPulse(t=10.0, timestep=0.1)  # 10 seconds, 0.1s steps
hamiltonian = np.array([[1.0, 0.1], [0.1, -1.0]], dtype=complex)
density_mat = np.eye(2, dtype=complex) / 2
measurement_op = np.array([[1, 0], [0, -1]], dtype=complex)  # Sz

# Collect expectation values during evolution
expectation_values, final_density, times = pulse.apply_time_evolution(
    density_mat, measurement_op, hamiltonian=hamiltonian
)
# expectation_values contains 101 values (t=0, 0.1, 0.2, ..., 10.0)

get_pulse_operator

def get_pulse_operator(
    self,
    **kwargs: Any,
) -> np.ndarray:
    """Returns the time evolution operator P = exp(-i*H*t).

    Args:
        **kwargs: Additional arguments (one of the following is required):
            hamiltonian (np.ndarray): The Hamiltonian matrix H. The time evolution 
                operator is computed as P = exp(-i * t * H) using matrix exponential.
                If a Hamiltonian was provided when creating the pulse, it takes
                precedence.
            eigen_hamiltonian (Tuple[np.ndarray, np.ndarray]): Alternative to hamiltonian.
                A tuple of (eigenvalues, eigenvectors) of the Hamiltonian. This provides
                more efficient computation using: P = V @ diag(exp(-i * t * λ)) @ V†

    Returns:
        np.ndarray: The time evolution operator P.
        
    Raises:
        ValueError: If neither hamiltonian nor eigen_hamiltonian is provided.
    """

Example:

from hqs_nmr.pulse_sequence.pulses import TimeEvolutionPulse
import numpy as np

pulse = TimeEvolutionPulse(t=5.0)
hamiltonian = np.array([[1.0, 0.1], [0.1, -1.0]], dtype=complex)

# Get the propagator
P = pulse.get_pulse_operator(hamiltonian=hamiltonian)

# Apply to any state or density matrix
state = np.array([1, 0], dtype=complex)
evolved_state = P @ state