Skip to content

Commit 698c7d5

Browse files
Alexis Montoisonamontoison
authored andcommitted
Support the new storage of ANL problems
1 parent c900300 commit 698c7d5

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

benchmarks/mastodonte.jl

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ using CompressedSensingIPM
1010

1111
function mastodonte(z0, mask; lambda::Float64=1.0, gpu::Bool=false, gpu_arch::String="cuda", rdft::Bool=false)
1212
nnz_missing = length(mask) - nnz(vec(mask) |> sparse)
13+
1314
# index_missing = Vector{CartesianIndex{3}}(undef, nnz_missing)
1415
index_missing = Vector{Int}(undef, nnz_missing)
1516

16-
DFTsize = size(z0) # problem dim
17+
DFTsize = size(mask) # problem dim
1718
DFTdim = length(DFTsize) # problem size
19+
1820
if gpu
1921
if gpu_arch == "cuda"
2022
AT = CuArray{Float64}
@@ -34,9 +36,9 @@ function mastodonte(z0, mask; lambda::Float64=1.0, gpu::Bool=false, gpu_arch::St
3436
end
3537

3638
pos = 0
37-
for i in 1:DFTsize[1]
39+
for k in 1:DFTsize[3]
3840
for j in 1:DFTsize[2]
39-
for k in 1:DFTsize[3]
41+
for i in 1:DFTsize[1]
4042
if mask[i,j,k] == 0
4143
pos += 1
4244
# index_missing[pos] = CartesianIndex{3}(i, j, k)
@@ -54,7 +56,7 @@ function mastodonte(z0, mask; lambda::Float64=1.0, gpu::Bool=false, gpu_arch::St
5456
t1 = time()
5557
solver = MadNLP.MadNLPSolver(
5658
nlp;
57-
max_iter=10000,
59+
max_iter=2000,
5860
kkt_system=FFTKKTSystem,
5961
nlp_scaling=false,
6062
print_level=MadNLP.INFO,
@@ -69,17 +71,30 @@ function mastodonte(z0, mask; lambda::Float64=1.0, gpu::Bool=false, gpu_arch::St
6971
return nlp, solver, results, t2-t1
7072
end
7173

74+
# Data
75+
# path_z0_h5 = "7_7_sec_ord_rings_800_800_200.h5"
76+
# z0_h5 = h5open(path_z0_h5, "r")
77+
# z0 = read(z0_h5["data"])
78+
79+
# path_mask_h5 = "mask_template_800_800_200.h5"
80+
# path_mask_h5 = "mask_template_f_n_s_800_800_200.h5"
81+
# mask_h5 = h5open(path_mask_h5, "r")
82+
# mask = read(mask_h5["data"])
83+
84+
# New storage
85+
path_h5 = "movo2_40_120K_slice_pm4.0xpm4.0xpm4.0_br0.20_sg123.nxs.h5"
86+
file_h5 = file_h5 = h5open(path_h5, "r")
87+
mask = read(file_h5["entry"]["data"]["weights"])
88+
z0 = read(file_h5["entry"]["data"]["signal"])
89+
90+
# Options for the solver
7291
gpu = true
73-
gpu_arch = "cuda" # "rocm"
92+
gpu_arch = "cuda"
93+
# gpu_arch = "rocm"
7494
rdft = true
75-
path_z0_h5 = "7_7_sec_ord_rings_800_800_200.h5"
76-
z0_h5 = h5open(path_z0_h5, "r")
77-
z0 = read(z0_h5["data"])
78-
# path_mask_h5 = "mask_template_800_800_200.h5"
79-
path_mask_h5 = "mask_template_f_n_s_800_800_200.h5"
80-
mask_h5 = h5open(path_mask_h5, "r")
81-
mask = read(mask_h5["data"])
8295
lambda = 1.0
96+
97+
# Solve the problem and recover the solution
8398
nlp, solver, results, timer = mastodonte(z0, mask; lambda, gpu, gpu_arch, rdft)
8499
N = length(results.solution) ÷ 2
85100
beta_MadNLP = results.solution[1:N]
@@ -90,12 +105,12 @@ println("Timer: $(timer)")
90105
# nlp.fft_timer[]
91106
# nlp.mapping_timer[]
92107

93-
dump_solution = true
108+
# Dump the solution in a file
109+
dump_solution = false
94110
if dump_solution
95-
v = beta_to_DFT(3, DFTsize, beta_MadNLP; rdft=rdft)
111+
DFTsize = size(mask)
112+
v = CompressedSensingIPM.beta_to_DFT(3, DFTsize, beta_MadNLP; rdft=rdft)
96113
x_recovered = ifft(v) .* sqrt(prod(DFTsize))
97-
x_recovered = Vector(x_recovered) |> real
98-
open("7_7_sec_ord_rings_800_800_200_solution.txt", "w") do io
99-
writedlm(io, x_recovered)
100-
end
114+
x_recovered = Array(x_recovered) |> real
115+
h5write("solution_movo2_40_120K.h5", "solution", x_recovered)
101116
end

0 commit comments

Comments
 (0)