Skip to content

Commit

Permalink
Add Pluto notebook (#6)
Browse files Browse the repository at this point in the history
* Add pluto tutorial

* Update README.md

* Mention extensions in README.md

* Recommend instantiate as it is not slow

* Minor change in elixir
  • Loading branch information
Arpit-Babbar authored Nov 28, 2024
1 parent df8b6f7 commit 8c58830
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 2024-11-28__VSCode_SSH/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.4"
manifest_format = "2.0"
project_hash = "19409765dc6c1c312c0cbcbd693c228514d80184"
project_hash = "88176804a35075d514258022eb51a9122a925959"

[[deps.ADTypes]]
git-tree-sha1 = "016833eb52ba2d6bea9fcb50ca295980e728ee24"
Expand Down
1 change: 1 addition & 0 deletions 2024-11-28__VSCode_SSH/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand Down
36 changes: 21 additions & 15 deletions 2024-11-28__VSCode_SSH/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,28 @@ julia> Pkg.activate(".")
```
We now install the required dependencies for the packages by the following command. It takes some time, but is only needed once
```julia
julia> # Pkg.instantiate() (Skipped for the tutorial. Don't run this!)
julia> Pkg.instantiate()
```
For the tutorial, we skip this command and instead use the following command to activate an environment where I have already installed the packaged

We can now run the codes in this directory. You can open the codes "my_run.jl", "elixir_advection_basic.jl", "run_blast.jl" by using file explorer. You can access the file explorer with the hotkey `ctrl`/`cmd` + `shift` + `e` or by choosing the top icon in the left side bar. Once you open these files in VS code, you can run them by pressing the play button at top right of the window, or by using the hotkeys below

## Running Pluto over SSH

Run the following in `julia` on the server `apollo`. Replace the port number with a unique port during the live tutorial.
```julia
julia> Pkg.activate("/local/home/julia24/arpit/2024-11-28__VSCode_SSH")
julia> using Pluto
julia> Pluto.run(port=1235)
```
We can now run the codes in this directory. You can open the codes "my_run.jl", "elixir_advection_basic.jl", "run_blast.jl" by using file explorer. You can access the file explorer with the hotkey `ctrl`/`cmd` + `shift` + `e` or by choosing the top icon in the left side bar. Once you open these files in VS code, you can run them by pressing the play button at top right of the window, or by using the hotkeys below
This command will show you a link like `http://localhost:1235/?secret=....`. Keep that link and do not close this julia session. Open another terminal tab on your local computer. You can access the pluto notebook session that we started on `apollo` by running the following on your terminal
```shell
ssh -L 1235:localhost:1235 [email protected]
```
Now, you can access the link that you saved earlier.

## Other VS Code extensions useful in this tutorial

1. HTML Preview. Used to preview HTML files. https://marketplace.visualstudio.com/items?itemName=tht13.html-preview-vscode
2. vscode-pdf. Used to display PDF files in VS Code. https://marketplace.visualstudio.com/items?itemName=tomoki1207.pdf

## Useful VS Code hotkeys

Expand All @@ -49,15 +64,6 @@ We can now run the codes in this directory. You can open the codes "my_run.jl",
6. `ctrl`/`cmd` + 1/2/3 = change focus to active window number 1/2/3
7. `ctrl`/`cmd` + `shift` + `f` = global search in the active folder

## Running Pluto over SSH
## Running Persistent (resumable) VS code session (Experimental feature)

Run the following in `julia` on the server `apollo`.
```julia
julia> using Pluto
julia> Pluto.run(port=1235)
```
This command will show you a link like `http://localhost:1235/?secret=....`. Keep that link and do not close this julia session. Open another terminal tab on your local computer. You can access the pluto notebook session that we started on `apollo` by running the following on your terminal
```shell
ssh -L 1235:localhost:1235 [email protected]
```
Now, you can access the link that you saved earlier.
The documentation explains it [here](https://www.julia-vscode.org/docs/stable/userguide/remote/#Persistent-server-sessions). However, the feature is experimental. Further, you can currently only have one persistent session which is pretty limiting.
1 change: 0 additions & 1 deletion 2024-11-28__VSCode_SSH/elixir_advection_basic.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using OrdinaryDiffEq
using Trixi
using Plots
gr()

###############################################################################
# semidiscretization of the linear advection equation
Expand Down
130 changes: 130 additions & 0 deletions 2024-11-28__VSCode_SSH/pluto_tutorial.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
### A Pluto.jl notebook ###
# v0.20.3

using Markdown
using InteractiveUtils

# ╔═╡ b0f6a076-ace9-11ef-2134-31b8a2d573b5
begin
import Pkg
Pkg.activate(".")
Pkg.instantiate()
using Plots
end

# ╔═╡ de231021-e1de-438c-bee8-765c06cb9e12
using DelimitedFiles

# ╔═╡ 21cc7f77-23e7-4d10-8682-400154aa8f28
using GZip

# ╔═╡ deb410dd-4427-48da-9d88-1b45d890d9b5
using Tenkai

# ╔═╡ a2bc3d92-2651-473e-b314-40b6ee9287a2
begin
exact_data_raw = joinpath(Tenkai.data_dir, "blast.dat.gz");
exact_data = GZip.open(exact_data_raw);
exact_blast = readdlm(exact_data);
end;

# ╔═╡ 35a4a72d-4803-4d05-87dd-a84c06d86e0a
let
# Submodules
Eq = Tenkai.EqEuler1D

#------------------------------------------------------------------------------
xmin, xmax = 0.0, 1.0

boundary_condition = (reflect, reflect)
γ = 1.4
final_time = 0.038

initial_value = Eq.blast
exact_solution = Eq.exact_blast # dummy function
boundary_value = Eq.exact_blast # dummy function

degree = 4
solver = "lwfr"
solution_points = "gl"
correction_function = "radau"
numerical_flux = Eq.rusanov
bound_limit = "yes"
bflux = evaluate

nx = 400
cfl = 0.0
bounds = ([-Inf], [Inf]) # Not used in Euler
tvbM = 300.0
save_iter_interval = 0
save_time_interval = 0.0 * final_time
animate = true # Factor on save_iter_interval or save_time_interval
compute_error_interval = 0

# blend parameters
indicator_model = "gassner"
debug_blend = false
cfl_safety_factor = 0.95
pure_fv = false
#------------------------------------------------------------------------------
grid_size = nx
domain = [xmin, xmax]
problem = Problem(domain, initial_value, boundary_value,
boundary_condition, final_time, exact_solution)
equation = Eq.get_equation(γ)
limiter = setup_limiter_blend(blend_type = mh_blend(equation),
indicating_variables = Eq.rho_p_indicator!,
reconstruction_variables = conservative_reconstruction,
indicator_model = indicator_model,
debug_blend = debug_blend,
pure_fv = pure_fv,
numflux = Eq.rusanov)
scheme = Scheme(solver, degree, solution_points, correction_function,
numerical_flux, bound_limit, limiter, bflux)
param = Parameters(grid_size, cfl, bounds, save_iter_interval,
save_time_interval, compute_error_interval;
animate = animate, cfl_safety_factor = cfl_safety_factor,
time_scheme = "SSPRK33")
#------------------------------------------------------------------------------
sol = Tenkai.solve(equation, problem, scheme, param);

global x, u = sol["grid"].xc, sol["ua"][1,1:end-1]

sol["plot_data"].p_ua

end

# ╔═╡ f22301bb-1c37-4e8b-9964-2ac6e846da7d
plot(x, u, label = "Tenkai.jl")

# ╔═╡ 2e50bc03-76ac-41f5-bc63-ffe3824690d8
let
plotlyjs()
global p = scatter(x, u, label = "Tenkai.jl")
plot!(exact_blast[:,1], exact_blast[:,2], label = "Reference")
end

# ╔═╡ 3e58a59c-5267-43f5-bd6b-90626d022135
let
anim = Animation()
a, b = 230, 380
x_res = x[a:b]
p_ = scatter(x_res, u[a:b], label = "Tenkai.jl")
for i in 1:10
y = u[a-5*i:b-5*i]
p_[1][1][:y] .= y # [subplot_index][curve_index][y_series]
frame(anim, p_)
end
gif(anim, "soln.mp4", fps = 1)
end

# ╔═╡ Cell order:
# ╠═b0f6a076-ace9-11ef-2134-31b8a2d573b5
# ╠═de231021-e1de-438c-bee8-765c06cb9e12
# ╠═21cc7f77-23e7-4d10-8682-400154aa8f28
# ╠═deb410dd-4427-48da-9d88-1b45d890d9b5
# ╠═a2bc3d92-2651-473e-b314-40b6ee9287a2
# ╠═35a4a72d-4803-4d05-87dd-a84c06d86e0a
# ╠═f22301bb-1c37-4e8b-9964-2ac6e846da7d
# ╠═2e50bc03-76ac-41f5-bc63-ffe3824690d8
# ╠═3e58a59c-5267-43f5-bd6b-90626d022135

0 comments on commit 8c58830

Please sign in to comment.