RotationPulse
A RotationPulse is defined by an angle and an axis. To create a rotation pulse the easiest way is to use the from_string method of NMRPulse class.
The str format for a rotation pulse is the angle followed by the axis.
The axis can be x, y or z. The angle can be any number and will be interpreted as an angle in degrees.
This pulse applies an instantaneous rotation.
from hqs_nmr.pulse_sequence import NMRPulse
rotation_pulse = NMRPulse.from_string("90y")
rotation_pulse2 = NMRPulse.from_string("-26.8x")
Pi expressions are not supported except for a few special cases: ±π, ±π/2 and ±π/4 which will be interpreted as radians.
from hqs_nmr.pulse_sequence import NMRPulse
# These two are equivalent
rotation_pulse = NMRPulse.from_string("90y")
rotation_pulse2 = NMRPulse.from_string("pi/2y")
Another feature is for a pulse to only act on specific spins. This can be done by adding a | after the angle and list the spins it should act on separated by commas.
from hqs_nmr.pulse_sequence import NMRPulse
# Apply pulse only to spins 0, 1, 3, and 5
rotation_pulse = NMRPulse.from_string("90y|0,1,3,5")
Methods
apply_pulse_operator
def apply_pulse_operator(
self,
density_mat: np.ndarray,
**kwargs: Any,
) -> np.ndarray:
"""Apply the pulse P on the density matrix.
Args:
density_mat (np.ndarray): The density matrix rho_0.
**kwargs: Additional arguments:
num_spins (int): Required. The number of spins in the system.
Returns:
np.ndarray: The transformed density matrix P @ rho_0 @ P†.
Raises:
ValueError: If num_spins is not provided.
ValueError: If active_sites contains indices >= num_spins.
"""
Example:
from hqs_nmr.pulse_sequence.pulses import RotationPulse
import numpy as np
pulse = RotationPulse(angle=90, axis="x")
density_mat = np.eye(4, dtype=complex) # Example density matrix for 2 spins
result = pulse.apply_pulse_operator(density_mat, num_spins=2)
get_pulse_operator
def get_pulse_operator(
self,
**kwargs: Any,
) -> np.ndarray:
"""Returns the total pulse operator for this rotation pulse.
Args:
**kwargs: Additional arguments:
num_spins (int): Required. The number of spins in the system.
Returns:
np.ndarray: The total pulse operator P as a (2^num_spins × 2^num_spins) matrix.
For pulses with active_sites specified, this is the product of all individual
site operators: P = P_site_n @ ... @ P_site_1 @ P_site_0
Raises:
ValueError: If num_spins is not provided.
ValueError: If active_sites contains indices >= num_spins.
"""
Example:
from hqs_nmr.pulse_sequence.pulses import RotationPulse
pulse = RotationPulse(angle=90, axis="y", active_sites=[0, 2])
P = pulse.get_pulse_operator(num_spins=4)
# P is the combined rotation operator for spins 0 and 2