In this exercise you will be guided through the steps to create, compile, and run the emulator of the hls4ml model you trained in part 2. The code in these steps should be executed from the command line on `lxplus` after doing `source setup.sh` from this `cms_mlatl1t_tutorial`.
When developing your own hls4ml NN emulators, you should compile and run your model emulator locally before delivering it to `cms-hls4ml`.
**Note** you need to run the steps described below in the terminal before going through the cells in this notebook!
## Prerequisite
You will need the HLS for the model of part 2.
## 1.
Copy the NN-specific part of the hls4ml project to the `cms-hls4ml` repo. We _don't_ copy `ap_types` since we'll reference them from the externals.
As of `hls4ml``0.8.1`, when run outside of Vivado HLS, the C++ code loads the weights from txt files. We need to force compilation of the weights from the header file instead.
This one liner will replace the `#define` that would cause the weights to be loaded from txt files with one that will load them from the header files when we compile instead.
If you don't do this, when you `cmsRun` you will see a runtime error like `ERROR: file w2.txt does not exist`
```shell
find $MLATL1T_DIR/part3/cms-hls4ml/L1TMLDemo/L1TMLDemo_v1/NN \(-type d -name .git -prune\)-o-type f -print0 | xargs -0sed-i's/#ifndef __SYNTHESIS__/#ifdef __HLS4ML_LOAD_TXT_WEIGHTS__/'
```
## 3.
`make` the hls4ml emulator interface shared object
*Note* when developing your own models, you may unfortunately run into segmentation violations while developing. The most common reason is that the input and output data type set in the producer mismatch the types used by the model emulator. In this emulator workflow, this causes a runtime error rather than a compile time error.
## 8.
Run the notebook part3.ipynb
# Notebook
Now we can read the predictions from our Nano AOD ntuple and check they make sense compared to part 1 and part 2.