Please read ALL the instructions carefully before you begin.
IMPORTANT: For this assignment I want you to write a program (A .py python code file that can be run at the command line). No JupyterLab Notebooks for this HW!
(0) Completion of Labs and Reading
If you did not yet complete the in-class work or the weekly reading, then you may want to finish that first.
(1) Checkout the repository:
Use this link to accept the assignment and create your repository on GitHub: https://classroom.github.com/a/Tm1cDdul
After you accept the assignment and the repository exists in your GitHub, clone the repository into your working area on Rivanna.
(2) Calculate π again but with NumPy arrays! (5 points)
As you saw last week, π can be easily calculated using Monte Carlo techniques. Write a program (mc_pi_numpy.py) that uses NumPy arrays to calculate π without loops. Benchmark the time it takes using NumPy arrays compared to Python lists, then add this comparison as a comment at the top of your mc_pi_numpy.py program.
Hint: There are many ways to do this. Do it however you like. In my program, I used some NumPy ufuncs that we haven't seen yet: np.sqrt, np.less, and np.count_zero. Look them up and play with them interactively! Use them, or do it another way, but no loops!
(3a) What is the uncertainty of the calculation? (4 points)
Now copy over mc_pi.py to mc_pi_error.py. In this program add functionality so that the user can input a second command-line argument:how many times they want you to do the MC estimate from part 2. For example, if the user may ask to use N_MC=10,000 random points, and do that N_ESTIMATE=100 times. Based on how long your program took in Part 1, is this a reasonable time? Use nested for loops to do your MC integration N_ESTIMATE times, each with N_MC random points. In your program calculate the average of the N_ESTIMATE answers for π and calculate the standard deviation of the N_ESTIMATE calculations.
The output of your program should read:
Using (N_MC*N_ESTIMATE) MC points, pi is estimated to be ??? with a standard deviation of ???.
(3b) Want to be an A student? Yes? Then, try this part! (1 point)
The standard deviation from 3a is an estimate of the uncertainty on a single measurement using N_MC=10,000. Redo 3a, but with only N_MC=1,000 points. How did the standard deviation increase when you decrease N_MC by a factor of 10? Estimate how many N_MC points you would hare to run to get a precision on your pi estimate of 1 part in 10,000 (0.01% precision → standard deviation of ~.0001)? To get credit, add a short discussion about this work and your conclusions to your README file.
(4) Push to GitHub
Add all of the files to your repository and push it to GitHub. mc_pi_numpy.py, and mc_pi_error.py, and the README file.