Skip to content

Adding randomness into a compiled Reactant loop #1757

@jlk9

Description

@jlk9

I am running an Oceananigans.jl model, stepping it forward in a compiled loop. I want to update its boundary condition with some random noise each tilmestep, like this:

#
# Loop through our ocean model:
#
function my_loop!(model, u_wind_stress, random_field)

    Δt = model.clock.last_Δt
    @trace mincut = true track_numbers = false for i = 1:64
        # Get some new randomness:
        randn!(random_field)

        # Add our wind stress to the randomness:
        random_field .+= u_wind_stress

        # Modify the top BC so it's wind stress + new randomness:
        set!(model.velocities.u.boundary_conditions.top.condition, random_field)

        # Step the model forward:
        time_step!(model, Δt)
    end
    return nothing
end

Set up in this way so that the original boundary condition (u_wind_stress) is preserved. This produces the following error:

randn_err.txt

Maybe this is the wrong way to incorporate randomness into Reactant loops. Is there an alternative to randn! or a way to use it in this context?

@wsmoses

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions