-
Notifications
You must be signed in to change notification settings - Fork 0
/
nimcsotutorial.tex
323 lines (269 loc) · 11.7 KB
/
nimcsotutorial.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
\chapter{\texttt{nimCSO} Basic Tutorial on Selecting Elements for High Entropy Alloy Modeling} \label{chap:nimcsotutorial}
The purpose of this guide is to demonstrate some common use cases of
\texttt{nimCSO} and go in a bit more into the details
of how it could be used, but it is not by any means extensive. If
something is not covered but you would like to see it here, please do
not hesitate to open an issue on GitHub and let use know!
\hypertarget{dataset-config-and-compilation}{%
\section{Dataset, Config, and
Compilation}\label{nimcsotutorial:dataset-config-and-compilation}}
To get started, let's first recap what we need to do to get
\texttt{nimCSO} up and running.
\textbf{1.} Install \texttt{nim} and dependencies, but \textbf{that's already
done for you if you are in the Codespace}. You can see what was run to
get the environment set up in the
\href{../.devcontainer/Dockerfile}{\texttt{Dockerfile}}.
\textbf{2.} Create the dataset. For now, let's just use the default one
(based on ULTERA Database) that comes with the package. Relative to this
notebook, the dataset is located at
\texttt{../dataList.txt}. Let's have a look at the
first few lines of the file to see what it looks like.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
!head -n 8 ../dataList.txt
\end{minted}
\begin{minted}[xleftmargin=3\parindent, fontsize=\small, bgcolor=subtlegray]{output}
Al,Co,Cr,Cu,Fe,Ni
Nb,Ta,Ti
Co,Cr,Ni
Al,Co,Cr,Fe,Mn,Ni
Al,Co,Fe,Mo,Ni
Hf,Nb,Ti,V
Co,Cr,Fe,Nb,Ni
Al,Co,Cr,Cu,Fe,Ni
\end{minted}
\textbf{3.} Now, we need to create task
\texttt{config.yaml} file that will describe what we
are doing and point to our data file. That was already done for you in
the \href{config.yaml}{\texttt{config.yaml}} file, but
you are more than welcome to play and modify it.
\textbf{4.} Finally, we can run the \texttt{nimCSO}
package to get the results. To do so, we will use one long command you
can see below. Let's break it down:
\begin{itemize}
\item
\texttt{nim} is the official Nim language compiler.
\item
\texttt{c} instructs \texttt{nim}
compiler to use \texttt{C} compiler to optimize and
compile intermediate code. You can also use
\texttt{cpp} to use \texttt{C++}
compiler or \texttt{objc} to use
\texttt{Objective-C} compiler. If you want, you can
also compile directly with LLVM using
\href{https://github.com/arnetheduck/nlvm}{\texttt{nlvm}},
but it isn't pre-installed for you here.
\item
\texttt{-f} is a flag to force the compiler to
compile everything, even if the code didn't change. We want this
because \texttt{config.yaml}, which tells
\texttt{nimCSO} how to write itself, is not tracked
by the compiler, but is critical to the compilation process (see two
point below).
\item
\texttt{-d:release} is a flag that tells the compiler
to optimize the code for release. You can also use
\texttt{-d:debug} to compile the code with better
debugging support, but it will be slower and it will not prevent bugs
from happening. There is also \texttt{-d:danger} that
will disable all runtime checks and run a bit faster, but you no
longer get memory safety guarantees.
\item
\texttt{-d:configPath=config.yaml} is a flag pointing
to \textbf{\texttt{config.yaml} that is read and
tells \texttt{nimCSO} (not the compiler!) how to
write itself \emph{before} the compilation starts.} That's the magic
metaprogramming sauce enabling us to write functions which
\texttt{C}/\texttt{C++} compiler can
then turn into single deterministically allocated and exectuted
machine code through
\href{https://en.wikipedia.org/wiki/Inline_expansion}{inlining}.
\item
\texttt{out:nimcso} is just telling the compiler to
output the compiled binary right here and name it
\texttt{nimcso}. You can name it whatever you want,
but it's a good idea to name it something that makes sense.
\item
\texttt{../src/nimcso} is pointing to the source code
of \texttt{nimCSO} package to compile, relative to
this notebook.
\end{itemize}
Let's run the command and see what happens! Shouldn't take more than a
few seconds.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
nim c -f -d:release -d:configPath=config.yaml --out:nimcso ../src/nimcso
\end{minted}
\begin{minted}[xleftmargin=3\parindent, fontsize=\small, bgcolor=subtlegray]{output}
...
config.yaml
CC: ../../../opt/conda/nim/lib/system/exceptions.nim
CC: ../../../opt/conda/nim/lib/std/private/digitsutils.nim
CC: ../../../opt/conda/nim/lib/std/assertions.nim
...
CC: nimcso/bitArrayAutoconfigured.nim
CC: nimcso.nim
Hint: orc; threads: on; opt: speed; options: -d:release
87026 lines; 7.635s; 257.383MiB peakmem; proj: /workspaces/nimCSO/src/nimcso;
out: /workspaces/nimCSO/examples/nimcso[SuccessX]
\end{minted}
Now, let's run \texttt{nimCSO} and see what happens!
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/1.png}
\end{figure}
You should have seen a neat \texttt{help} message that
tells you how to use \texttt{nimCSO}. Let's start with
a ``coverage'' benchmark to see how fast can we check how many
datapoints will be removed from the dataset if we remove the first 5
elements of \texttt{elementOrder}.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso -cb
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/2.png}
\end{figure}
\hypertarget{key-routines-and-brute-forcing}{
\section{Key Routines and Brute Forcing}\label{nimcsotutorial:key-routines-and-brute-forcing}}
And if you were able to run that, you are all set to start using
\texttt{nimCSO}!
Let's try the simplest routine \texttt{mostCommon} or
\emph{What are the most common elements in the dataset?}
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso --mostCommon
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/3.png}
\end{figure}
If you didn't modify anything, you should now see that elements like
\texttt{N}, \texttt{Y},
\texttt{C}, and \texttt{Re}, are not
very common in the dataset, while \texttt{Cr},
\texttt{Ti}, \texttt{Fe}, and
\texttt{Ni} are very common. When it comes to them, its
pretty obvious that removing the first group will be the first choice,
while the latter will be the last, if we want to keep the dataset as
extensive as possible.
The critical question here is, \emph{which of the intermediate elements
like \texttt{Hf}, \texttt{V},
\texttt{Ta}, or \texttt{Zr} should we
remove first?}
With a dataset spanning 19 elements, the solution space is around 0.5M,
so we can actually just brute force it in seconds :)
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso -bfi
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/4.png}
\end{figure}
Let's look at the result! As expected, \texttt{N},
\texttt{Y}, \texttt{C}, and
\texttt{Re} are removed first (0-4) and then the trend
follows for a bit to \texttt{Hf} \textbf{The first
break is \texttt{V}, you can notice that it's better to
remove either or both \texttt{Ta} or
\texttt{Zr} first, despite the fact that they are
nearly 50\% more common than \texttt{V}} That's
because they often coocur with \texttt{Re} and
\texttt{Hf}, which are not common.
We can test exactly how much more data we will have if we remove
\texttt{Ta} insead of \texttt{V} by
using the \texttt{--singleSolution} /
\texttt{-ss} routine.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso -ss Ta W Hf Si Re Y B C N -ss V W Hf Si Re Y B C N
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/5.png}
\end{figure}
Wow! Looking at the \texttt{--mostCommon} output from
earlier, we can see that \textbf{\texttt{Ta} is present
in 74 more datapoints than \texttt{V}, but after
removing \texttt{WHfSiReYBCN}, picking
\texttt{V} as one of 10 elements to model will result
in 67 \emph{more} datapoints.} Relative to a dataset without
interdependencies, that's a 141 datapoint difference!
And another case that breaks from the ordering is
\texttt{Mo}, which is better to keep than much more
common \texttt{Nb}, and after
\texttt{Nb} is removed, even better thank keeping the
\texttt{Ti}, which is the second most common element in
the dataset!
Similarly to what we did with \texttt{V}
vs.~\texttt{Ta}, we can test how much more data we will
have if we remove \texttt{Nb} instead of
\texttt{Mo} by using the
\texttt{--singleSolution} /
\texttt{-ss} routine.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small, breaklines]{shell}
./nimcso -ss Ta V W Zr Hf Nb Si Re Y B C N -ss Ta V W Zr Hf Mo Si Re Y B C N -ss Ta V W Zr Hf Ti Si Re Y B C N
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/6.png}
\end{figure}
We can see that \textbf{\texttt{Nb} is present in 121
more datapoints than \texttt{Mo}, but after removing
\texttt{TaVWZrHfSiReYBCN}, picking
\texttt{Mo} as one of 7 elements to model will result
in 76 \emph{more} datapoints.} Relative to a dataset without
interdependencies, that's a 197 datapoint difference, which is even more
than the \texttt{Ta} vs.~\texttt{V}
case! Additionally, we can see that \texttt{Ti} is only
3 datapoints better than \texttt{Mo}, despite being
present in 183 more datapoints than \texttt{Mo}.
\hypertarget{algorithm-search}{%
\section{Algorithm Search}\label{nimcsotutorial:algorithm-search}}
The
\texttt{--bruteForceInt}/\texttt{-bfi}
routine we used to find the solutions worked great for our 19-element
dataset and took only a few seconds on the low-performance Codespace
machine, but in many cases dimensionality of the problem will be too
high to brute force it.
Let's now try to use the
\texttt{--algorithmSearch}/\texttt{-as}
routine, which takes advantage of some assumptions known to be valid or
likely to be valid (see manuscript), to limit the search space and find
the solution in a reasonable time. Let's try it now!
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso -as
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/7.png}
\end{figure}
As you can see, \textbf{the algorithm reproduced the same results as the
brute force search around 100 times faster}, except for third-to-last
step because dataset had points with at least 3 elements breaking its
backtracking assumptions.
\hypertarget{genetic-search}{%
\section{Genetic Search}\label{nimcsotutorial:genetic-search}}
For cases where the dimensionality of the problem is too high to either
brute-force or use the algorithm search, we can still use the
\texttt{--geneticSearch}/\texttt{-gs}
routine to find the solution in a reasonable time. Let's try it now!
Please note that the results are stochastic, so you might get different
results than ones shown below if you run the command again.
\begin{minted}[xleftmargin=3\parindent, linenos=true, fontsize=\small]{shell}
./nimcso -gs
\end{minted}
\begin{figure}[H]
\centering
\includegraphics[width=0.97\textwidth]{nimcsotutorial/8.png}
\end{figure}
\label{nimcsotutorial:summary}
To summarize, now, you should be able to apply \texttt{nimCSO} to
your own dataset and get some valuable insights on how to model it!
If you are working in a Codespace, you can just do everything right in
this notebook by simply modifying the
\texttt{config.yaml} file and running the commands you
just learned about. The Codespace will be persisted until you explicitly
delete it, so you can come back to it later and continue your work by
clicking on the link in the \textbf{Open in Codespaces} badge in the README
of the repository and resuming your work.
%\printbibliography[heading=subbibintoc]