mrphy.sims

Simulation codes with explicit Jacobian operations.

mrphy.sims.blochsim(Mi: Tensor, Beff: Tensor, *, T1: Tensor | None = None, T2: Tensor | None = None, γ: Tensor = tensor(4257.6000, dtype=torch.float64), dt: Tensor = tensor(4.0000e-06, dtype=torch.float64)) Tensor

Bloch simulator with explicit Jacobian operation.

This function is only differentiable w.r.t. Mi and Beff.

Setting T1=T2=None to opt for simulation ignoring relaxation.

Usage:

Mo = blochsim(Mi, Beff, *, T1, T2, γ, dt) Mo = blochsim(Mi, Beff, *, T1=None, T2=None, γ, dt)

Inputs:
  • Mi: (N, *Nd, xyz), Magnetic spins, assumed equilibrium [[[0 0 1]]].

  • Beff: (N, *Nd, nT, xyz), “Gauss”, B-effective, magnetic field.

Optionals:
  • T1: ()(N ⊻ 1, *Nd ⊻ 1,), “Sec”, T1 relaxation.

  • T2: ()(N ⊻ 1, *Nd ⊻ 1,), “Sec”, T2 relaxation.

  • γ: ()(N ⊻ 1, *Nd ⊻ 1,), “Hz/Gauss”, gyro ratio.

  • dt: ()(N ⊻ 1,), “Sec”, dwell time.

Outputs:
  • Mo: (N, *Nd, xyz), Magetic spins after simulation.

Tip

For alternative implementation: Storing history for U, Φ and UtM0 etc., which are also used in backward, may avoid redundant computation, but comsumes more RAM.