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

Continuous Integration tests up and running #116

Merged
merged 87 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
c36269a
CI updated for GithubActions
JordiBolibar Apr 6, 2023
a30189a
Update Project.toml
JordiBolibar Apr 6, 2023
f63894a
CI updated with yml file
JordiBolibar Apr 12, 2023
b985250
Merge branch 'main' of https://github.com/JordiBolibar/ODINN.jl
JordiBolibar Apr 12, 2023
1015562
yml file path updated
JordiBolibar Apr 12, 2023
1233255
yaml file extension fixed
JordiBolibar Apr 12, 2023
3a148ee
PYTHON variable set to which python
JordiBolibar Apr 12, 2023
d408e49
PYTHON env fixed
JordiBolibar Apr 12, 2023
c3c11e3
PYTHON env fixed
JordiBolibar Apr 12, 2023
3487369
PYTHON env fixed
JordiBolibar Apr 12, 2023
6de2e81
PYTHON env fixed
JordiBolibar Apr 12, 2023
2008276
PYTHON env fixed
JordiBolibar Apr 12, 2023
c371c9e
PYTHON env fixed
JordiBolibar Apr 12, 2023
7ba30f5
PYTHON env fixed
JordiBolibar Apr 12, 2023
30d29b9
PYTHON env fixed
JordiBolibar Apr 12, 2023
0b2fcb2
PYTHON env fixed
JordiBolibar Apr 12, 2023
f5ed301
PYTHON env fixed
JordiBolibar Apr 12, 2023
0ec693d
PYTHON env fixed
JordiBolibar Apr 12, 2023
ea3adfd
PYTHON env fixed
JordiBolibar Apr 12, 2023
b3ccf63
PYTHON env fixed
JordiBolibar Apr 12, 2023
8af1d79
PYTHON env fixed
JordiBolibar Apr 12, 2023
15b670d
PYTHON env fixed
JordiBolibar Apr 12, 2023
0ca6c51
PYTHON env fixed
JordiBolibar Apr 12, 2023
b4ce880
CI updated
JordiBolibar Apr 25, 2023
e0e95b4
CI updated
JordiBolibar Apr 25, 2023
913a5ca
CI updated
JordiBolibar Apr 25, 2023
e80f27d
CI updated
JordiBolibar Apr 25, 2023
4e9ea39
CI updated
JordiBolibar May 3, 2023
1717a37
CI updated
JordiBolibar May 3, 2023
51b628d
CI updated
JordiBolibar May 3, 2023
654b909
CI updated
JordiBolibar May 3, 2023
48c77d4
CI updated
JordiBolibar May 3, 2023
e2e4d94
CI updated
JordiBolibar May 3, 2023
e3c06a6
CI updated
JordiBolibar May 3, 2023
8423d9a
CI updated
JordiBolibar May 3, 2023
ee12968
CI updated
JordiBolibar May 3, 2023
deed023
CI updated
JordiBolibar May 3, 2023
778678e
CI updated
JordiBolibar May 3, 2023
9d195b6
CI updated
JordiBolibar May 4, 2023
2bd0d0b
CI updated
JordiBolibar May 4, 2023
a905f47
CI updated
JordiBolibar May 4, 2023
2de7247
CI updated
JordiBolibar May 4, 2023
67523ee
[WIP] Investigating strange behaviour of SIA solver
JordiBolibar May 11, 2023
82ff799
solve problem with boundary condition for SIA PDE (no UDE)
facusapienza21 May 30, 2023
f661f55
restore old version of action
facusapienza21 May 30, 2023
1562e8b
[WIP] Mass balance fixed.
JordiBolibar May 30, 2023
a62043f
Merge conflict fixed
JordiBolibar May 30, 2023
d403066
Merge branch 'ODINN-SciML:boundary-condition' into boundary-condition
JordiBolibar May 30, 2023
f0995e1
Iceflow with fixed boundary conditions and MB
JordiBolibar May 31, 2023
2a33088
New CI and Python environment from Facu
JordiBolibar Jun 1, 2023
6c33712
Merge conflict fixed
JordiBolibar Jun 1, 2023
b96d67b
Merge conflict fixed
JordiBolibar Jun 1, 2023
4837dd1
Updated test reference files
JordiBolibar Jun 1, 2023
6a5a75f
Forcing intitialization of gdirs from scratch for CI
JordiBolibar Jun 1, 2023
5143425
CI and environment updated
JordiBolibar Jun 1, 2023
fff755e
CI and environment updated
JordiBolibar Jun 1, 2023
dbe65d3
Python env and tests fixed
JordiBolibar Jun 5, 2023
6722876
Update environment.yml
JordiBolibar Jun 5, 2023
19c1cba
Update environment.yml
JordiBolibar Jun 6, 2023
9bce53a
Update environment.yml
JordiBolibar Jun 6, 2023
a8e5b65
Update environment.yml
JordiBolibar Jun 6, 2023
25c3129
Update environment.yml
JordiBolibar Jun 6, 2023
a474422
Update CI.yml
JordiBolibar Jun 6, 2023
56887c9
Update CI.yml
JordiBolibar Jun 6, 2023
26cb4bd
Test update and environment.yml
JordiBolibar Jun 7, 2023
53c67c8
Merge conflict fixed
JordiBolibar Jun 7, 2023
a10d472
Update CI.yml
JordiBolibar Jun 7, 2023
f25e4cd
Update CI.yml with CA certificate setup
JordiBolibar Jun 7, 2023
abe537b
CA certificate
JordiBolibar Jun 7, 2023
b0643d9
Update CA variable assignment
JordiBolibar Jun 7, 2023
6684f73
Update CI.yml
JordiBolibar Jun 8, 2023
c91501b
Update CI.yml
JordiBolibar Jun 8, 2023
5479e76
Update CI.yml
JordiBolibar Jun 8, 2023
08d30d0
Update CI.yml
JordiBolibar Jun 8, 2023
bd07935
Update CI.yml
JordiBolibar Jun 9, 2023
b9d5191
SSL certificate added to tests
JordiBolibar Jun 9, 2023
b073552
Ref files for test updated
JordiBolibar Jun 9, 2023
ebf5765
Docs action removed + tests with less glaciers
JordiBolibar Jun 9, 2023
82d84f4
Using 2 workers for tests
JordiBolibar Jun 9, 2023
98c3dd5
Using 2 workers for tests (now for OGGM)
JordiBolibar Jun 9, 2023
73e1c7e
Update README with micromamba installation and other details
JordiBolibar Jun 9, 2023
0c10dfd
Fall back multiprocessing in CI for PDE solving
JordiBolibar Jun 9, 2023
8fecf4e
Merge branch 'main' of https://github.com/JordiBolibar/ODINN.jl
JordiBolibar Jun 9, 2023
eff9fe4
Multiprocessing for OGGM fixed
JordiBolibar Jun 9, 2023
329890e
Avoid downloading Millan22 velocities in CI
JordiBolibar Jun 9, 2023
4ded237
Correctly bypassing download of Millan22 velocities
JordiBolibar Jun 9, 2023
602bf85
Including missing catch on get_initial_status()
JordiBolibar Jun 9, 2023
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
Prev Previous commit
Next Next commit
Correctly bypassing download of Millan22 velocities
  • Loading branch information
JordiBolibar committed Jun 9, 2023
commit 4ded2378d7614e03c3cb14ee8c33ff0b32b4c1ad
9 changes: 5 additions & 4 deletions src/helpers/iceflow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end

Generate reference dataset based on the iceflow PDE
"""
function generate_ref_dataset(gdirs, tspan, mb_model; solver = RDPK3Sp35())
function generate_ref_dataset(gdirs, tspan, mb_model; solver = RDPK3Sp35(), velocities=true)
# Generate climate data if necessary
@timeit to "generate raw climate files" begin
pmap((gdir) -> generate_raw_climate_files(gdir, tspan), gdirs)
Expand All @@ -33,7 +33,7 @@ function generate_ref_dataset(gdirs, tspan, mb_model; solver = RDPK3Sp35())
println("Running forward PDE ice flow model...\n")
# Run batches in parallel
A_noises = randn(rng_seed(), length(gdirs)) .* noise_A_magnitude
refs = @showprogress pmap((gdir, A_noise) -> batch_iceflow_PDE(gdir, A_noise, tspan, solver, mb_model; run_spinup=false), gdirs, A_noises)
refs = @showprogress pmap((gdir, A_noise) -> batch_iceflow_PDE(gdir, A_noise, tspan, solver, mb_model; run_spinup=false, velocities=velocities), gdirs, A_noises)

# Gather information per gdir
gdir_refs = get_gdir_refs(refs, gdirs)
Expand All @@ -48,12 +48,13 @@ end

Solve the Shallow Ice Approximation iceflow PDE for a given temperature series batch
"""
function batch_iceflow_PDE(gdir, A_noise, tspan, solver, mb_model=nothing; run_spinup=false)
function batch_iceflow_PDE(gdir, A_noise, tspan, solver, mb_model=nothing; run_spinup=false, velocities=true)
println("Processing glacier: ", gdir.rgi_id)
# Callback
# Define stop times every one month
tstops, step = define_callback_steps(tspan)
context, H = build_PDE_context(gdir ,A_noise, tspan; run_spinup=run_spinup)
context, H = build_PDE_context(gdir ,A_noise, tspan;
run_spinup=run_spinup, velocities=velocities)
S = context[3]
S_coords = context[32]
MB_total = zeros(Float64, size(H))
Expand Down
46 changes: 27 additions & 19 deletions src/helpers/initial_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

Retrieves the initial glacier geometry (bedrock + ice thickness) for a glacier with other necessary data (e.g. grid size and ice surface velocities).
"""
function get_initial_geometry(gdir, run_spinup, smoothing=false)
function get_initial_geometry(gdir, run_spinup, smoothing=false; velocities=true)
# Load glacier gridded data
glacier_gd = xr.open_dataset(gdir.get_filepath("gridded_data"))
if run_spinup || !use_spinup[]
# println("Using $ice_thickness_source for initial state")
# Retrieve initial conditions from OGGM
# initial ice thickness conditions for forward model
if ice_thickness_source == "millan"
if ice_thickness_source == "millan" && velocities
H₀ = Float64.(ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_ice_thickness.data, 0.0))
elseif ice_thickness_source == "farinotti"
H₀ = Float64.(ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.consensus_ice_thickness.data, 0.0))
Expand Down Expand Up @@ -47,7 +47,7 @@ function get_initial_geometry(gdir, run_spinup, smoothing=false)
@assert found == true "Spin up glacier simulation not found for $(gdir.rgi_id)."

end
try
# try
# We filter glacier borders in high elevations to avoid overflow problems
dist_border = Float64.(glacier_gd.dis_from_border.data)
S::Matrix{Float64} = Float64.(glacier_gd.topo.data) # surface elevation
Expand All @@ -57,8 +57,12 @@ function get_initial_geometry(gdir, run_spinup, smoothing=false)
H::Matrix{Float64} = deepcopy(H₀)
B::Matrix{Float64} = Float64.(glacier_gd.topo.data) .- H₀ # bedrock
S_coords::PyObject = rioxarray.open_rasterio(gdir.get_filepath("dem"))
V::Matrix{Float64} = Float64.(ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_v.data, 0.0))
fillNaN!(V)
if velocities
V::Matrix{Float64} = Float64.(ifelse.(glacier_gd.glacier_mask.data .== 1, glacier_gd.millan_v.data, 0.0))
fillNaN!(V)
else
V = zeros(Float64, size(H))
end
nx = glacier_gd.y.size # glacier extent
ny = glacier_gd.x.size # really weird, but this is inversed
Δx = abs(gdir.grid.dx)
Expand All @@ -68,18 +72,20 @@ function get_initial_geometry(gdir, run_spinup, smoothing=false)
glacier_gd.close() # Release any resources linked to this object

return H₀, H, S, B, V, (nx,ny), (Δx,Δy), S_coords, dist_border, slope
catch
missing_glaciers = load(joinpath(ODINN.root_dir, "data/missing_glaciers.jld2"))["missing_glaciers"]
push!(missing_glaciers, gdir.rgi_id)
jldsave(joinpath(ODINN.root_dir, "data/missing_glaciers.jld2"); missing_glaciers)
glacier_gd.close() # Release any resources linked to this object
@warn "Glacier without data: $(gdir.rgi_id). Updating list of missing glaciers. Please try again."
end
# catch error
# @show error
# missing_glaciers = load(joinpath(ODINN.root_dir, "data/missing_glaciers.jld2"))["missing_glaciers"]
# push!(missing_glaciers, gdir.rgi_id)
# jldsave(joinpath(ODINN.root_dir, "data/missing_glaciers.jld2"); missing_glaciers)
# glacier_gd.close() # Release any resources linked to this object
# @warn "Glacier without data: $(gdir.rgi_id). Updating list of missing glaciers. Please try again."
# end
end

function build_PDE_context(gdir, A_noise, tspan; run_spinup=false)
function build_PDE_context(gdir, A_noise, tspan; run_spinup=false, velocities=true)
# Determine initial geometry conditions
H₀, H, S, B, V, nxy, Δxy, S_coords::PyObject, dist_border, slope = get_initial_geometry(gdir, run_spinup)
H₀, H, S, B, V, nxy, Δxy, S_coords::PyObject, dist_border, slope = get_initial_geometry(gdir, run_spinup;
velocities=velocities)

rgi_id = gdir.rgi_id
# Initialize all matrices for the solver
Expand All @@ -105,14 +111,15 @@ function build_PDE_context(gdir, A_noise, tspan; run_spinup=false)
return context, H
end

function get_UDE_context(gdirs, tspan; testmode=false)
context_batches = pmap((gdir) -> build_UDE_context(gdir, tspan, testmode; run_spinup=false), gdirs)
function get_UDE_context(gdirs, tspan; testmode=false, velocities=true)
context_batches = pmap((gdir) -> build_UDE_context(gdir, tspan, testmode; run_spinup=false, velocities=velocities), gdirs)

return context_batches
end

function build_UDE_context(gdir, tspan, testmode; run_spinup=false)
H₀, H, S, B, V, nxy, Δxy, S_coords, dist_border, slope = get_initial_geometry(gdir, run_spinup)
function build_UDE_context(gdir, tspan, testmode; run_spinup=false, velocities=true)
H₀, H, S, B, V, nxy, Δxy, S_coords, dist_border, slope = get_initial_geometry(gdir, run_spinup;
velocities=velocities)
simulation_years = collect(tspan[1]:tspan[2])
A = Ref{Float64}(2e-17)
nx, ny = nxy
Expand All @@ -124,7 +131,8 @@ end

# UDE context using Glathida for H
function build_UDE_context_inv(gdir, gdir_ref, tspan; run_spinup=false)
H₀, H₁, S, B, V, nxy, Δxy, S_coords, dist_border, slope = get_initial_geometry(gdir, run_spinup)
H₀, H₁, S, B, V, nxy, Δxy, S_coords, dist_border, slope = get_initial_geometry(gdir, run_spinup;
velocities=velocities)
rgi_id = gdir.rgi_id
# Get evolved tickness and surface
H = gdir_ref["H"]
Expand Down
5 changes: 3 additions & 2 deletions test/PDE_UDE_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function pde_solve_test(atol; MB=false, fast=true)

# Run the forward PDE simulation
mb_model = ODINN.TI_model_1(DDF=6.0/1000.0, acc_factor=1.2/1000.0) # in m.w.e.
PDE_preds = @time generate_ref_dataset(gdirs, tspan, solver=ODINN.RDPK3Sp35(), mb_model)
PDE_preds = @time generate_ref_dataset(gdirs, tspan, solver=ODINN.RDPK3Sp35(), mb_model;
velocities=false)

## /!\ Saves current run as reference values
# if MB
Expand All @@ -45,7 +46,7 @@ function pde_solve_test(atol; MB=false, fast=true)
θ = zeros(10) # dummy data for the NN
UA_f = zeros(10)
UDE_settings, train_settings = ODINN.get_default_training_settings!(gdirs)
context_batches = ODINN.get_UDE_context(gdirs, tspan; testmode=true)
context_batches = ODINN.get_UDE_context(gdirs, tspan; testmode=true, velocities=false)
H_V_preds = @time predict_iceflow(θ, UA_f, gdirs, context_batches, UDE_settings, mb_model) # Array{(H_pred, V̄x_pred, V̄y_pred, rgi_id)}

let PDE_refs=PDE_refs, H_V_preds=H_V_preds
Expand Down