Table Of ContentHigh Performance Computations in NMR
by
Wyndham Bolling Blanton
B.S. Chemistry (Carnegie Mellon University) 1998
B.S. Physics (Carnegie Mellon University) 1998
A dissertation submitted in partial satisfaction of the
requirements for the degree of
Doctor of Philosophy
in
Chemistry
in the
GRADUATE DIVISION
of the
UNIVERSITY OF CALIFORNIA, BERKELEY
Committee in charge:
Professor Alexander Pines, Chair
Professor Jeffrey A. Reimer
Professor Raymond Y. Chiao
David E. Wemmer
Fall 2002
The dissertation of Wyndham Bolling Blanton is approved:
Chair Date
Date
Date
Date
University of California, Berkeley
Fall 2002
High Performance Computations in NMR
Copyright (cid:13)c 2002
by
Wyndham Bolling Blanton
1
Abstract
High Performance Computations in NMR
by
Wyndham Bolling Blanton
Doctor of Philosophy in Chemistry
University of California, Berkeley
Professor Alexander Pines, Chair
As an analytic noninvasive technique to study molecules in their natural envi-
ronment, NMR has little equal. The advancement of the technique is beginning to enter
a new phase, where many body dynamics, complex control, and precise measurements of
many body spin properties preclude any exact theoretical treatment. Approximation meth-
ods and other reductions in the set of parameter spaces are currently used to obtain some
form of intuition about a simplified NMR system; however, to exactly profile a real system,
numerical simulation is required.
The scope of most NMR simulations is chiefly regulated to small spin systems,
where the dynamics are simplified enough to simulate efficiently. The cause is typically
based on a poor understanding of how to simulate an NMR situation effectively and effi-
ciently. This seems consistent with the fact that most NMR spectroscopists are not com-
puter scientists as well. The introduction of novel programming paradigms and numerical
techniques seems to have eluded the field. A complete simulation environment for NMR is
2
presented here marrying three fundamental aspects of simulations 1) numerical speed and
efficiency, 2) simplicity in implementation, and 3) NMR specific algorithmic developments.
ThemajorityofnumericalNMRisreducedtoasimplesimulationframework. The
framework allows for more complex simulations for explorations of both many body spin
dynamicsandcontrol. Aspecificlargescalesimulationisappliedtorecouplingsequencesin
solid–state NMR. Using simple permutations on base pulse sequences can result in control
enhancements on both the simple system and the many body system beyond a theoretical
approach. The sheer number of permutations required to solve the problem would have
certainly been impossible without the aid of this framework. This new framework now
opens other unexplored possibilities of using simulation as a development tool for the larger
problems of many body dynamics and control.
Professor Alexander Pines
Dissertation Committee Chair
i
To my Grandmother and Grandfather, Lucy and Wyndham Jr.
ii
Contents
List of Figures v
List of Tables viii
1 Introduction 1
2 Computer Mechanics 4
2.1 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 The Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2.1 Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Expression Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.1 Motivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3.2 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.3.3 An Array Object and Stacks . . . . . . . . . . . . . . . . . . . . . . 15
2.3.4 Expression Template Implementation . . . . . . . . . . . . . . . . . 19
2.4 Optimizing For Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4.1 Basic Computer Architecture . . . . . . . . . . . . . . . . . . . . . . 30
2.4.2 A Faster Matrix Multiplication . . . . . . . . . . . . . . . . . . . . . 37
3 NMR Forms 42
3.1 Classical Mechanics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.2 Bloch Equation Magnetic Fields . . . . . . . . . . . . . . . . . . . . . . . . 43
3.3 Quantum Mechanics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.3.1 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.3.2 Rotational Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.3.3 The Hamiltonians . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.4 NMR Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.4.1 Quantum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.4.2 Classical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4 NMR Algorithms 76
4.1 Classical Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.1.1 Eigenvalue Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
4.1.2 ODE solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
4.2 Quantum Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
iii
4.2.1 The Direct Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.2.2 Periodicity and Propagator Reduction . . . . . . . . . . . . . . . . . 83
4.2.3 Eigenspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.2.4 Periodicity and Eigen–Space methods . . . . . . . . . . . . . . . . . 95
4.2.5 Non-periodic Hamiltonians . . . . . . . . . . . . . . . . . . . . . . . 100
4.2.6 Powder Average Integration . . . . . . . . . . . . . . . . . . . . . . . 100
4.3 Conclusions and Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
5 BlochLib 105
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
5.2 The Abstract NMR Simulation . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.2.1 Experimental Evolutions (EE) . . . . . . . . . . . . . . . . . . . . . 106
5.2.2 Theoretical Evolutions (TE). . . . . . . . . . . . . . . . . . . . . . . 106
5.2.3 Existing NMR Tool Kits . . . . . . . . . . . . . . . . . . . . . . . . . 108
5.2.4 Why Create a new Tool Kit? . . . . . . . . . . . . . . . . . . . . . . 109
5.3 BlochLib Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
5.3.1 Existing Numerical Tool Kits . . . . . . . . . . . . . . . . . . . . . . 110
5.3.2 Experimental and Theoretical Evolutions for NMR simulations . . . 111
5.3.3 BlochLib Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5.3.4 Drawbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.4 Various Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.4.1 Solid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
5.4.2 Classical Program: Magnetic Field Calculators . . . . . . . . . . . . 129
5.4.3 Classical Programs: Bloch Simulations . . . . . . . . . . . . . . . . . 131
5.5 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
6 Massive Permutations of Rotor Synchronized Pulse Sequences 141
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
6.1.1 Rotor Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . 142
6.2 Background Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
6.2.1 Average Hamiltonian . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
6.2.2 Recoupling RSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
6.2.3 C7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6.2.4 Removable of Higher Order Terms . . . . . . . . . . . . . . . . . . . 151
6.3 Permutations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
6.3.1 The Sub–Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
6.3.2 The Measure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
6.3.3 Algorithmic Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
6.4 Data and Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
6.4.1 Sequence Measures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
6.4.2 Transfer Efficiencies . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
6.5 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
7 Future Expansions 201
7.1 Evolutionary Algorithms (EA) . . . . . . . . . . . . . . . . . . . . . . . . . 202
7.2 Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
7.3 Final Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
iv
Bibliography 213
A Auxillary code 225
A.1 General C++ code and examples . . . . . . . . . . . . . . . . . . . . . . . . 225
A.1.1 C++ Template code used to generate prime number at compilation 225
A.1.2 C++ Template meta-program to unroll a fixed length vector at com-
pilation time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
A.1.3 C++codeforperformingamatrixmultiplicationwithL2cacheblock-
ing and partial loop unrolling.. . . . . . . . . . . . . . . . . . . . . . 228
A.1.4 An MPI master/slave implimentation framework . . . . . . . . . . . 230
A.1.5 C++ class for a 1 hidden layer Fully
connected back–propagation Neural Network . . . . . . . . . . . . . 232
A.2 NMR algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
A.2.1 MathematicaPackagetogenerateWignerRotationmatricesandSpin
operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
A.2.2 Rational Reduction C++ Class . . . . . . . . . . . . . . . . . . . . . 244
A.2.3 Optimized static Hamiltonian FID propogation . . . . . . . . . . . . 252
A.2.4 γ −COMPUTE C++ Class . . . . . . . . . . . . . . . . . . . . . . 253
A.3 BlochLib Configurations and Sources . . . . . . . . . . . . . . . . . . . . . . 263
A.3.1 Solid configuration files . . . . . . . . . . . . . . . . . . . . . . . . . 263
A.3.2 Magnetic Field Calculator input file . . . . . . . . . . . . . . . . . . 266
A.3.3 Quantum Mechanical Single Pulse Simulations . . . . . . . . . . . . 267
A.3.4 Example Classical Simulation of the Bulk Susceptibility . . . . . . . 267
A.3.5 Example Classical Simulation of the Modulated Demagnetizing Field 274
v
List of Figures
2.1 A two state Turing machine . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 A simple stack tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 How the compiler unrolls an expression template set of operations. . . . . . 25
2.4 DAXPY speed tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.5 A pictorial representation for the matrix–matrix tensor multiplication . . . 28
2.6 Speed in MFLOPS of a matrix–matrix multiplication . . . . . . . . . . . . . 29
2.7 A generic computer data path. . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.8 Pipe lines and loop unrolling . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.9 A 128 bit SIMD registers made of 4–32 bit data values . . . . . . . . . . . . 35
2.10 Cache levels in modern Processors . . . . . . . . . . . . . . . . . . . . . . . 36
2.11 Speed comparison in MFLOPS of loop unrolling . . . . . . . . . . . . . . . 39
2.12 Speed comparison in MFLOPS of L2 cache blocking and loop unrolling . . 40
3.1 The magnitude of the dipole field . . . . . . . . . . . . . . . . . . . . . . . . 52
3.2 The magnetization of a sample inside a magneti field. . . . . . . . . . . . . 55
3.3 Magnetization in iso–surfaces versus the applied magnetic field, B , the tem-
o
perature T, and number of moles. . . . . . . . . . . . . . . . . . . . . . . . . 75
4.1 Various propagators needed for an arbitrary rational reduction. . . . . . . . 84
4.2 Effectiveness of the rational propagator reduction method. . . . . . . . . . . 89
4.3 Diagram of one Hamiltonian period and the propagator labels used for the
COMPUTE algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.4 Octants of equal volume of a sphere. . . . . . . . . . . . . . . . . . . . . . . 102
5.1 Experimental Evolutions and Theoretical Evolutions . . . . . . . . . . . . . 107
5.2 The basic design layout of the BlochLib NMR tool kit. . . . . . . . . . . . 113
5.3 C=A*B*adjoint(A) speed of BlochLib . . . . . . . . . . . . . . . . . . . . . 115
5.4 Solid vs. Simpson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.5 The design of the EE program Solid derived from the input syntax. . . . . 127
5.6 1D static and spinning 2 spin simulation . . . . . . . . . . . . . . . . . . . . 128
5.7 1D and 2D post-C7 simulation . . . . . . . . . . . . . . . . . . . . . . . . . 128
5.8 The basic design for the Field Calculator program. . . . . . . . . . . . . . 130
5.9 Magnetic field of a D–circle . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
5.10 A rough design for a classical Bloch simulation over various interactions. . 133