Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR to update Julia folder #41

Merged
merged 23 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
39857cf
Removed the description and edited the examples section
Jun 5, 2024
6bcc582
Added 2 section headings
Jun 5, 2024
6209575
Removed the srun command and the export statement from the sbatch fil…
Jul 29, 2024
bedf73f
Updated the corresponding README
Jul 29, 2024
403d8c2
Matched it with what was on README, that is, for i in 3: 8 n = 10^i
Sep 20, 2024
0905fdd
Removed the results.dat file
Sep 20, 2024
09b5e6a
Deleted extra spaces
Sep 25, 2024
8a82306
Edited ode_test.jl to have @pyinclude, PyCall, & pyimport
Sep 25, 2024
bf8dc7f
Renamed to ode_test.jl
Sep 25, 2024
06dd1ba
Removed plt.style.use('seaborn-white')
Sep 25, 2024
fc7042e
Updated it with latest changes in run.sbatch, ode_test.jl, and figure.py
Sep 25, 2024
ec0789b
Reordered bits in README
Sep 25, 2024
336a38b
Added bits to install matplotlib and PyCall considerations
Sep 25, 2024
e3b2e4c
Updated the file with more ways to install a pkg and the notebook as …
Sep 30, 2024
3ede3b2
Notebook with Julia example
Sep 30, 2024
a438981
Added julia> Pkg.add(PyCall)
Sep 30, 2024
ad743f0
Removed the verbiage around package installation as that's mentioned …
Oct 1, 2024
8e843dd
Removed instructions on package installation and added a Reference se…
Oct 1, 2024
f37d66b
Fixed formatting
Oct 1, 2024
d534903
Fixed formatting
Oct 1, 2024
4f62064
Removed the instructions to install packages as they are in our user …
Oct 2, 2024
6e82f56
Moved the figure.png to the Images folder and updated the path in README
Oct 2, 2024
bfc1ee6
Removed boldfaced
Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions Languages/Julia/Example1/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
### Purpose:

This example illustrates the use of Julia on the Harvard University FAS cluster. Specifically, it evaluates PI via a Monte-Carlo method.
This example illustrates the use of Julia on the Harvard University
FAS cluster. Specifically, it evaluates PI via a Monte-Carlo method.


### Contents:

* <code>pi\_monte\_carlo.jl</code>: Julia source code
* <code>run.sbatch</code>: Batch-job submission script

### Julia code:

```julia
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Program: pi_monte_carlo.jl
Expand Down Expand Up @@ -39,7 +37,6 @@ end
```

### Example Batch-Job Submission Script:

```bash
#!/bin/bash
#SBATCH -J pi_monte_carlo
Expand All @@ -51,21 +48,16 @@ end
#SBATCH -t 0-00:30
#SBATCH --mem=2G

# Set up Julia and run the program
export PATH=$PATH:/n/holylabs/LABS/jharvard_lab/Users/jharvard/software/julia-1.9.3/bin
srun -n 1 -c 1 julia pi_monte_carlo.jl
# Run the program using Julia
julia pi_monte_carlo.jl
```

**NOTE:** Please remember to point the `PATH` environmental variable to the actual location of your Julia installation.

### Example Usage:

```bash
sbatch run.sbatch
```

### Example Output:

```bash
$ cat pi_monte_carlo.out
N = 1000: PI = 3.228
Expand Down
3 changes: 2 additions & 1 deletion Languages/Julia/Example1/pi_monte_carlo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function montepi(n::Int)
end

# Main program
for n in 10 .^(3: 8)
for i in 3: 8
n = 10^i
p = montepi(n)
println("N = $n: PI = $p")
end
6 changes: 0 additions & 6 deletions Languages/Julia/Example1/pi_monte_carlo.out

This file was deleted.

6 changes: 2 additions & 4 deletions Languages/Julia/Example1/run.sbatch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
#SBATCH -t 0-00:30
#SBATCH --mem=2G

# Set up Julia and run the program
export PATH=$PATH:/n/holylabs/LABS/jharvard_lab/Users/jharvard/software/julia-1.9.3/bin
srun -n 1 -c 1 julia pi_monte_carlo.jl

# Run the program using Julia
julia pi_monte_carlo.jl
118 changes: 58 additions & 60 deletions Languages/Julia/Example2/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
### Purpose:

This example illustrates solving differential equations numerically in Julia. Specifically, it solves an ODE after an example taken from [this](https://sam-dolan.sites.sheffield.ac.uk/mas212-course/sample-notebooks/ode_example) Python notebook, using [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/)
This example illustrates solving differential equations numerically in
Julia. Specifically, it solves an ODE after an example taken from
[this](https://sam-dolan.sites.sheffield.ac.uk/mas212-course/sample-notebooks/ode_example)
Python notebook, using
[DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/)


### Contents:

* <code>ode\_test.jl</code>: Julia source code
* <code>figure.py</code>: Python script for generating the figure
* <code>run.sbatch</code>: Batch-job submission script
* <code>results.dat</code>: Numeric results
* <code>figure.png</code>: Figure of ODE's solution
* <code>figure.py</code>: Python script for generating the figure

### Julia code:

```julia
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Program: ode_test.jl
Expand All @@ -22,6 +22,7 @@ using SimpleDiffEq
using Printf
using Plots
using Plots.PlotMeasures
using PyCall

# --- Define the problem ---
f(u, p, t) = t - u
Expand Down Expand Up @@ -52,19 +53,21 @@ for i = 1: size(sol.t)[1]
@printf(fo, "%8.4f %10.6f %10.6f\n", x, y, y_exact)
end
close(fo)
```

> **Note:** You may need to install the `DifferentialEquations`, `SimpleDiffEq` and `Plots` packages. Use the following command inside the Julia REPL:
pyimport("numpy")

```julia
julia> using Pkg
julia> Pkg.add("DifferentialEquations")
julia> Pkg.add("SimpleDiffEq")
julia> Pkg.add("Plots")
# --- Run the Python script to plot the result ---
@pyinclude("figure.py")
```

### Example Batch-Job Submission Script:
> **Note:** if not already installed, you will need to install the
`DifferentialEquations`, `SimpleDiffEq`, `Plots`, `PyCall`,
`Conda`, and `matplotlib` packages in order to run `ode_test.jl`
successfully. Follow [these
instructions](https://docs.rc.fas.harvard.edu/kb/julia/#Adding_packages_to_Julia)
to install the packages.

### Example Batch-Job Submission Script:
```bash
#!/bin/bash
#SBATCH -J ode_test
Expand All @@ -76,58 +79,16 @@ julia> Pkg.add("Plots")
#SBATCH -t 0-00:30
#SBATCH --mem=4G

# Set up Julia and run the program
export PATH=$PATH:/n/holylabs/LABS/jharvard_lab/Users/jharvard/software/julia-1.9.3/bin
srun -n 1 -c 1 julia ode_test.jl
# Run the program using Julia
julia ode_test.jl
```
**NOTE:** Please remember to point the `PATH` environmental variable to the actual location of your Julia installation.

### Example Usage:

```bash
sbatch run.sbatch
```

### Example Output:

```bash
$ cat results.dat
Time Numeric Exact
------------------------------
0.0000 1.000000 1.000000
0.2000 0.837462 0.837462
0.4000 0.740639 0.740640
0.6000 0.697624 0.697623
0.8000 0.698660 0.698658
1.0000 0.735763 0.735759
1.2000 0.802393 0.802388
1.4000 0.893198 0.893194
1.6000 1.003802 1.003793
1.8000 1.130613 1.130598
2.0000 1.270681 1.270671
2.2000 1.421625 1.421606
2.4000 1.581455 1.581436
2.6000 1.748569 1.748547
2.8000 1.921645 1.921620
3.0000 2.099603 2.099574
3.2000 2.281551 2.281524
3.4000 2.466785 2.466747
3.6000 2.654677 2.654647
3.8000 2.844781 2.844742
4.0000 3.036672 3.036631
4.2000 3.230027 3.229991
4.4000 3.424601 3.424555
4.6000 3.620150 3.620104
4.8000 3.816498 3.816459
5.0000 4.013510 4.013476
```

### Figure of Solution:

<img src="figure.png" alt="solution" width="500"/>

### Python script for generating the figure:

```python
"""
Program: figure.py
Expand All @@ -136,7 +97,6 @@ import os
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def rc_params():
Expand Down Expand Up @@ -195,6 +155,44 @@ plt.legend(fontsize=15, loc="upper left", shadow=True, fancybox=True)
plt.savefig(fig_path, format='png', dpi=100, bbox_inches='tight')
```

### Example Output:
```bash
$ cat results.dat
Time Numeric Exact
------------------------------
0.0000 1.000000 1.000000
0.2000 0.837462 0.837462
0.4000 0.740639 0.740640
0.6000 0.697624 0.697623
0.8000 0.698660 0.698658
1.0000 0.735763 0.735759
1.2000 0.802393 0.802388
1.4000 0.893198 0.893194
1.6000 1.003802 1.003793
1.8000 1.130613 1.130598
2.0000 1.270681 1.270671
2.2000 1.421625 1.421606
2.4000 1.581455 1.581436
2.6000 1.748569 1.748547
2.8000 1.921645 1.921620
3.0000 2.099603 2.099574
3.2000 2.281551 2.281524
3.4000 2.466785 2.466747
3.6000 2.654677 2.654647
3.8000 2.844781 2.844742
4.0000 3.036672 3.036631
4.2000 3.230027 3.229991
4.4000 3.424601 3.424555
4.6000 3.620150 3.620104
4.8000 3.816498 3.816459
5.0000 4.013510 4.013476
```

### Example of the figure of solution:
<img src="../Images/figure.png" alt="solution" width="500"/>

### References:

* [Official **DifferentialEquations.jl** Documentation](https://docs.sciml.ai/DiffEqDocs/stable/)
* [Official DifferentialEquations.jl Documentation](https://docs.sciml.ai/DiffEqDocs/stable/)
* [ODE Example](https://sam-dolan.sites.sheffield.ac.uk/mas212-course/sample-notebooks/ode_example)
* [Julia Programming Language](https://docs.rc.fas.harvard.edu/kb/julia/)
1 change: 0 additions & 1 deletion Languages/Julia/Example2/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')
from matplotlib.ticker import MultipleLocator, FormatStrFormatter

def rc_params():
Expand Down
5 changes: 5 additions & 0 deletions Languages/Julia/Example2/ode_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using SimpleDiffEq
using Printf
using Plots
using Plots.PlotMeasures
using PyCall

# --- Define the problem ---
f(u, p, t) = t - u
Expand Down Expand Up @@ -37,3 +38,7 @@ for i = 1: size(sol.t)[1]
end
close(fo)

pyimport("numpy")

# --- Run the Python script to plot the result ---
@pyinclude("figure.py")
28 changes: 0 additions & 28 deletions Languages/Julia/Example2/results.dat

This file was deleted.

6 changes: 2 additions & 4 deletions Languages/Julia/Example2/run.sbatch
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@
#SBATCH -t 0-00:30
#SBATCH --mem=4G

# Set up Julia and run the program
#export PATH=$PATH:/n/holylabs/LABS/jharvard_lab/Users/jharvard/software/julia-1.9.3/bin
export PATH=$PATH:/n/home06/pkrastev/holyscratch01/Work/Julia/julia-1.9.3/bin
srun -n 1 -c 1 julia ode_test.jl
# Run the program using Julia
julia ode_test.jl
Loading