Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions .github/workflows/copilot-setup-steps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,47 @@ name: "Copilot Setup Steps"
# Automatically run the setup steps when they are changed to allow for easy validation,
# and allow manual testing through the repository's "Actions" tab
on:
workflow_dispatch:
workflow_dispatch:
push:
paths:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- . github/workflows/copilot-setup-steps.yml

jobs:
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot
copilot-setup-steps:
copilot-setup-steps:
runs-on: ubuntu-latest

# Set the permissions to the lowest permissions possible needed for your steps
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Julia
uses: julia-actions/setup-julia@v2
with:
version: '1.11'

- name: Cache Julia packages
uses: julia-actions/cache@v2
with:
cache-name: julia-cache
cache-packages: true
cache-artifacts: true
cache-registries: true

- name: Install Fortran compiler (for Fortran dependencies)
run: |
sudo apt-get update
sudo apt-get install -y gfortran libopenblas-dev

- name: Build Julia project
run: julia --project="." -e "using Pkg; Pkg.build()"

- name: Instantiate Julia environment
run: julia --project="." -e "using Pkg; Pkg.instantiate()"
173 changes: 87 additions & 86 deletions benchmarks/DIIID_ideal_example/vacuum_accuracy_benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ using Pkg
using Plots
using LinearAlgebra

Pkg.activate("$(@__DIR__)/../.."); using JPEC
Pkg.activate("$(@__DIR__)/../..");
using JPEC

# this requires you to have run the DIIID-like_ideal_example first to generate the benchmark inputs
@load "$(@__DIR__)/../../examples/DIIID-like_ideal_example/benchmark_inputs.jld2" benchmark_inputs

(; wv_block, mpert, mtheta_eq, mthvac, complex_flag, kernelsign,
wall_flag, farwall_flag, grri, xzpts, ahg_file, dir_path,
vac_inputs, wall_settings,
n, ipert_n, psifac) = benchmark_inputs
wall_flag, farwall_flag, grri, xzpts, ahg_file, dir_path,
vac_inputs, wall_settings,
n, ipert_n, psifac) = benchmark_inputs

"""
Compute 0D accuracy metrics between two wv matrices
Expand All @@ -34,7 +35,7 @@ if benchmark_n
println("="^60)

# Define range of n values to test
n_values = range(1,15, step=1)
n_values = range(1, 15; step=1)
# Store results for Julia vs Fortran comparison
relative_errors_jf = Float64[]
max_errors_jf = Float64[]
Expand All @@ -46,13 +47,13 @@ if benchmark_n

# Compute Fortran solution
JPEC.Vacuum.set_surface_params(mtheta_eq, vac_inputs.mlow, vac_inputs.mhigh,
n_test, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)
n_test, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)

wv_block_fortran = copy(wv_block)
JPEC.Vacuum.mscvac(wv_block_fortran, mpert, mtheta_eq, mthvac,
complex_flag, kernelsign, wall_flag,
farwall_flag, grri, xzpts)
complex_flag, kernelsign, wall_flag,
farwall_flag, grri, xzpts)

JPEC.Vacuum.unset_surface_params()

Expand All @@ -74,21 +75,21 @@ if benchmark_n
println("Creating plots...")

# Plot 1: Julia vs Fortran comparison
p1 = plot(n_values, relative_errors_jf,
label="Relative Frobenius Error",
marker=:circle,
xlabel="n (toroidal mode number)",
ylabel="Relative Error",
title="Julia vs Fortran Accuracy",
legend=:topright,
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box)
plot!(p1, n_values, max_errors_jf,
label="Max Absolute Error",
marker=:square,
linewidth=2)
p1 = plot(n_values, relative_errors_jf;
label="Relative Frobenius Error",
marker=:circle,
xlabel="n (toroidal mode number)",
ylabel="Relative Error",
title="Julia vs Fortran Accuracy",
legend=:topright,
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box)
plot!(p1, n_values, max_errors_jf;
label="Max Absolute Error",
marker=:square,
linewidth=2)

figloc1 = joinpath(@__DIR__, "vacuum_accuracy_julia_vs_fortran_n_scan.pdf")
savefig(p1, figloc1)
Expand Down Expand Up @@ -125,13 +126,13 @@ if benchmark_m
# Fortran reference
mpert_ref = mhigh_reference - vac_inputs.mlow
JPEC.Vacuum.set_surface_params(mtheta_eq, vac_inputs.mlow, mhigh_reference,
1, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)
1, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)
wv_block_ref_fortran_m = zeros(ComplexF64, mpert_ref, mpert_ref)
grri_ref = zeros(Float64, 2 * (mthvac + 5), 2 * mpert_ref)
JPEC.Vacuum.mscvac(wv_block_ref_fortran_m, mpert_ref, mtheta_eq, mthvac,
complex_flag, kernelsign, wall_flag,
farwall_flag, grri_ref, xzpts, ahg_file, "$(@__DIR__)/../../examples/DIIID-like_ideal_example")
complex_flag, kernelsign, wall_flag,
farwall_flag, grri_ref, xzpts, ahg_file, "$(@__DIR__)/../../examples/DIIID-like_ideal_example")
JPEC.Vacuum.unset_surface_params()

println("Reference solutions computed.\n")
Expand All @@ -144,14 +145,14 @@ if benchmark_m

# Compute Fortran solution
JPEC.Vacuum.set_surface_params(mtheta_eq, vac_inputs.mlow, mhigh_test,
1, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)
1, vac_inputs.qa, vac_inputs.r,
vac_inputs.z, vac_inputs.delta)

wv_block_fortran_m = zeros(ComplexF64, mpert_test, mpert_test)
grri_test = zeros(Float64, 2 * (mthvac + 5), 2 * mpert_test)
JPEC.Vacuum.mscvac(wv_block_fortran_m, mpert_test, mtheta_eq, mthvac,
complex_flag, kernelsign, wall_flag,
farwall_flag, grri_test, xzpts, ahg_file, "$(@__DIR__)/../../examples/DIIID-like_ideal_example")
complex_flag, kernelsign, wall_flag,
farwall_flag, grri_test, xzpts, ahg_file, "$(@__DIR__)/../../examples/DIIID-like_ideal_example")

JPEC.Vacuum.unset_surface_params()

Expand Down Expand Up @@ -193,72 +194,72 @@ if benchmark_m
fortran_conv_plot = [x == 0.0 ? eps_plot : x for x in relative_errors_fortran_conv_m]

# Plot: Convergence for each implementation (mhigh scan)
p4 = plot(mhigh_values, julia_conv_plot,
label="Julia (vs mhigh=$mhigh_reference)",
marker=:circle,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Error vs High-Res Reference",
title="Convergence Analysis (mhigh scan)",
legend=:topright,
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box)
plot!(p4, mhigh_values, fortran_conv_plot,
label="Fortran (vs mhigh=$mhigh_reference)",
marker=:square,
linewidth=2)
p4 = plot(mhigh_values, julia_conv_plot;
label="Julia (vs mhigh=$mhigh_reference)",
marker=:circle,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Error vs High-Res Reference",
title="Convergence Analysis (mhigh scan)",
legend=:topright,
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box)
plot!(p4, mhigh_values, fortran_conv_plot;
label="Fortran (vs mhigh=$mhigh_reference)",
marker=:square,
linewidth=2)

figloc4 = joinpath(@__DIR__, "vacuum_accuracy_convergence_mhigh.pdf")
savefig(p4, figloc4)
@info "Saved mhigh convergence plot to $figloc4"

# Combined plot for mhigh
p5 = plot(mhigh_values, relative_errors_jf_m,
label="Julia vs Fortran",
marker=:diamond,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Frobenius Error",
title="Julia vs Fortran Accuracy (mhigh scan)",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)
p5 = plot(mhigh_values, relative_errors_jf_m;
label="Julia vs Fortran",
marker=:diamond,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Frobenius Error",
title="Julia vs Fortran Accuracy (mhigh scan)",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)

figloc5 = joinpath(@__DIR__, "vacuum_accuracy_julia_vs_fortran_mhigh.pdf")
savefig(p5, figloc5)
@info "Saved Julia vs Fortran mhigh comparison to $figloc5"

# Combined plot with both metrics for mhigh scan
p6 = plot(layout=(2,1), size=(800, 800))

plot!(p6[1], mhigh_values, relative_errors_jf_m,
label="Julia vs Fortran",
marker=:diamond,
ylabel="Relative Frobenius Error",
title="Julia vs Fortran Agreement (mhigh scan)",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)

plot!(p6[2], mhigh_values, julia_conv_plot,
label="Julia (vs mhigh=$mhigh_reference)",
marker=:circle,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Error vs High-Res",
title="Convergence to High Resolution",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)
plot!(p6[2], mhigh_values, fortran_conv_plot,
label="Fortran (vs mhigh=$mhigh_reference)",
marker=:square,
linewidth=2)
p6 = plot(; layout=(2, 1), size=(800, 800))

plot!(p6[1], mhigh_values, relative_errors_jf_m;
label="Julia vs Fortran",
marker=:diamond,
ylabel="Relative Frobenius Error",
title="Julia vs Fortran Agreement (mhigh scan)",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)

plot!(p6[2], mhigh_values, julia_conv_plot;
label="Julia (vs mhigh=$mhigh_reference)",
marker=:circle,
xlabel="mhigh (maximum poloidal mode)",
ylabel="Relative Error vs High-Res",
title="Convergence to High Resolution",
linewidth=2,
yscale=:log10,
minorgrid=true,
framestyle=:box,
legend=:topright)
plot!(p6[2], mhigh_values, fortran_conv_plot;
label="Fortran (vs mhigh=$mhigh_reference)",
marker=:square,
linewidth=2)

figloc6 = joinpath(@__DIR__, "vacuum_accuracy_combined_mhigh.pdf")
savefig(p6, figloc6)
Expand Down
Loading
Loading