Skip to content

Commit

Permalink
Change arch_array to on_architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
glwagner committed Mar 16, 2024
1 parent 9fef51e commit db54028
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions examples/calibrate_zonally_averaged_baroclinic_adjustment.jl
Expand Up @@ -8,7 +8,7 @@ using Oceananigans.Models.HydrostaticFreeSurfaceModels: SliceEnsembleSize
using Oceananigans.TurbulenceClosures: FluxTapering
using LinearAlgebra, CairoMakie, DataDeps, JLD2

using Oceananigans.Architectures: arch_array
using Oceananigans.Architectures: on_architecture

# using ElectronDisplay

Expand Down Expand Up @@ -84,7 +84,7 @@ close(file)

gent_mcwilliams_diffusivity = IsopycnalSkewSymmetricDiffusivity(slope_limiter = FluxTapering(1e-2))

gm_closure_ensemble = arch_array(architecture, [deepcopy(gent_mcwilliams_diffusivity) for _ = 1:Nensemble])
gm_closure_ensemble = on_architecture(architecture, [deepcopy(gent_mcwilliams_diffusivity) for _ = 1:Nensemble])

closure_ensemble = (gm_closure_ensemble, closures[1], closures[2])

Expand Down
10 changes: 5 additions & 5 deletions examples/intro_to_inverse_problems.jl
Expand Up @@ -19,7 +19,7 @@
using ParameterEstimocean

using Oceananigans
using Oceananigans.Architectures: arch_array
using Oceananigans.Architectures: on_architecture
using Oceananigans.Units
using Oceananigans.Models.HydrostaticFreeSurfaceModels: ColumnEnsembleSize
using Oceananigans.TurbulenceClosures: ConvectiveAdjustmentVerticalDiffusivity
Expand Down Expand Up @@ -64,7 +64,7 @@ function extract_perfect_parameters(observations, Nensemble)
Qᵘ[:, j] .= obs.metadata.parameters.Qᵘ
Qᵇ[:, j] .= obs.metadata.parameters.Qᵇ
N²[:, j] .= obs.metadata.parameters.
f[:, j] .= obs.metadata.coriolis.f
f[:, j] .= obs.metadata.coriolis.f
end

file = jldopen(first(observations).path)
Expand All @@ -90,10 +90,10 @@ function build_ensemble_simulation(observations, arch=CPU(); Nensemble=1)
column_ensemble_size = ColumnEnsembleSize(Nz=Nz, ensemble=(Nensemble, Nbatch), Hz=Hz)
ensemble_grid = RectilinearGrid(arch, size = column_ensemble_size, topology = (Flat, Flat, Bounded), z = (-Lz, 0))

coriolis_ensemble = arch_array(arch, [FPlane(f=f[i, j]) for i = 1:Nensemble, j=1:Nbatch])
closure_ensemble = arch_array(arch, [deepcopy(closure) for i = 1:Nensemble, j=1:Nbatch])
coriolis_ensemble = on_architecture(arch, [FPlane(f=f[i, j]) for i = 1:Nensemble, j=1:Nbatch])
closure_ensemble = on_architecture(arch, [deepcopy(closure) for i = 1:Nensemble, j=1:Nbatch])

Qᵘ, Qᵇ, N² = Tuple(arch_array(arch, p) for p in (Qᵘ, Qᵇ, N²))
Qᵘ, Qᵇ, N² = Tuple(on_architecture(arch, p) for p in (Qᵘ, Qᵇ, N²))

u_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(Qᵘ))
b_bcs = FieldBoundaryConditions(top = FluxBoundaryCondition(Qᵇ), bottom = GradientBoundaryCondition(N²))
Expand Down
6 changes: 3 additions & 3 deletions src/EnsembleSimulations.jl
Expand Up @@ -9,7 +9,7 @@ using ..Observations: SyntheticObservations, batch, tupleit

using Oceananigans
using Oceananigans.Models.HydrostaticFreeSurfaceModels: ColumnEnsembleSize
using Oceananigans.Architectures: arch_array
using Oceananigans.Architectures: on_architecture

function ensemble_column_model_simulation(observations;
closure,
Expand Down Expand Up @@ -40,10 +40,10 @@ function ensemble_column_model_simulation(observations;
z = (-Lz, 0))

coriolis_ensemble = [FPlane(f=observations[j].metadata.coriolis.f) for i = 1:Nensemble, j=1:Nbatch]
coriolis_ensemble = arch_array(architecture, coriolis_ensemble)
coriolis_ensemble = on_architecture(architecture, coriolis_ensemble)

closure_ensemble = [deepcopy(closure) for i = 1:Nensemble, j=1:Nbatch]
closure_ensemble = arch_array(architecture, closure_ensemble)
closure_ensemble = on_architecture(architecture, closure_ensemble)

if isnothing(non_ensemble_closure)
closure = closure_ensemble
Expand Down
6 changes: 3 additions & 3 deletions src/Observations.jl
Expand Up @@ -15,7 +15,7 @@ using Oceananigans.Grids: pop_flat_elements, topology, halo_size, on_architectur
using Oceananigans.TimeSteppers: update_state!, reset!
using Oceananigans.Fields: indices
using Oceananigans.Utils: SpecifiedTimes, prettytime
using Oceananigans.Architectures: arch_array, architecture
using Oceananigans.Architectures: on_architecture, architecture
using Oceananigans.OutputWriters: WindowedTimeAverage, AveragedSpecifiedTimes

using JLD2
Expand Down Expand Up @@ -331,7 +331,7 @@ function set!(model, observations::BatchedSyntheticObservations, time_index=1)
observations_data = column_ensemble_interior(observations, field_name, time_index, model_field_size)

# Reshape `observations_data` to the size of `model_field`'s interior
reshaped_data = arch_array(architecture(model_field), reshape(observations_data, size(model_field)))
reshaped_data = on_architecture(architecture(model_field), reshape(observations_data, size(model_field)))

# Sets the interior of field `model_field` to values of `reshaped_data`
model_field .= reshaped_data
Expand Down Expand Up @@ -417,7 +417,7 @@ function (collector::FieldTimeSeriesCollector)(simulation)
field_time_series = collector.field_time_serieses[field_name]
if architecture(collector.grid) != architecture(simulation.model.grid)
arch = architecture(collector.grid)
device_collected_field_data = arch_array(arch, parent(collector.collected_fields[field_name]))
device_collected_field_data = on_architecture(arch, parent(collector.collected_fields[field_name]))
parent(field_time_series[time_index]) .= device_collected_field_data
else
set!(field_time_series[time_index], collector.collected_fields[field_name])
Expand Down
6 changes: 3 additions & 3 deletions src/Parameters.jl
Expand Up @@ -2,7 +2,7 @@ module Parameters

export FreeParameters, lognormal, ScaledLogitNormal

using Oceananigans.Architectures: CPU, arch_array, architecture
using Oceananigans.Architectures: CPU, on_architecture, architecture
using Oceananigans.Utils: prettysummary
using Oceananigans.TurbulenceClosures: AbstractTurbulenceClosure, ScalarDiffusivity
using Oceananigans.TurbulenceClosures: AbstractTimeDiscretization, ExplicitTimeDiscretization
Expand Down Expand Up @@ -590,13 +590,13 @@ the parameters for the any closure that is of type `AbstractArray`. The `arch`it
(`CPU()` or `GPU()`) defines whethere `Array` or `CuArray` is returned.
"""
function new_closure_ensemble(closures::AbstractArray, parameter_ensemble, arch)
cpu_closures = arch_array(CPU(), closures)
cpu_closures = on_architecture(CPU(), closures)

for (k, θₖ) in enumerate(parameter_ensemble)
update_closure_ensemble_member!(cpu_closures, k, θₖ)
end

return arch_array(arch, cpu_closures)
return on_architecture(arch, cpu_closures)
end

new_closure_ensemble(closures::Tuple, parameter_ensemble, arch) =
Expand Down

0 comments on commit db54028

Please sign in to comment.