Skip to content

Commit

Permalink
Set explicit random number generator for stoachastic PDEs
Browse files Browse the repository at this point in the history
  • Loading branch information
david-zwicker committed Sep 23, 2023
1 parent 6504a79 commit 5a937ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/pdes/test_diffusion_pdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def test_diffusion_time_dependent_bcs(backend):


@pytest.mark.parametrize("backend", ["numpy", "numba"])
def test_diffusion_sde(backend):
def test_diffusion_sde(backend, rng):
"""test scaling of noise using a stochastic diffusion equation"""
# we disable diffusivity to have a simple analytical solution
var_local, t_range = 0.35, 0.1
eq = DiffusionPDE(diffusivity=0, noise=var_local)
eq = DiffusionPDE(diffusivity=0, noise=var_local, rng=rng)
grid = CartesianGrid([[0, 1000]], 3700)
field = ScalarField(grid)
sol = eq.solve(field, t_range=t_range, dt=1e-4, backend=backend, tracker=None)
Expand Down
6 changes: 3 additions & 3 deletions tests/pdes/test_pde_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@ def op(arr, out):


@pytest.mark.parametrize("backend", ["numpy", "numba"])
def test_pde_noise(backend):
def test_pde_noise(backend, rng):
"""test noise operator on PDE class"""
grid = grids.UnitGrid([128, 128])
state = FieldCollection([ScalarField(grid), ScalarField(grid)])

var_local = 0.5
eq = PDE({"a": 0, "b": 0}, noise=var_local)
eq = PDE({"a": 0, "b": 0}, noise=var_local, rng=rng)
res = eq.solve(state, t_range=1, backend=backend, dt=1, tracker=None)
dist = stats.norm(scale=np.sqrt(var_local)).cdf
assert stats.kstest(np.ravel(res.data), dist).pvalue > 0.001

eq = PDE({"a": 0, "b": 0}, noise=[0.01, 2.0])
eq = PDE({"a": 0, "b": 0}, noise=[0.01, 2.0], rng=rng)
res = eq.solve(state, t_range=1, backend=backend, dt=1, tracker=None)

dist_a = stats.norm(scale=np.sqrt(0.01)).cdf
Expand Down

0 comments on commit 5a937ad

Please sign in to comment.