EnzymeAD / EnzymeAD/Reactant.jl

Adding randomness into a compiled Reactant loop

Open
#1,757 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
370
Forks
74
Avg merge
18h 47m
Merged PRs (30d)
30

Description

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](https://github.com/user-attachments/files/22937611/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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.