Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

🐛[BUG]: Darcy2D permeability: all Fourier coefficients of a sample share one random value (bare wp.tid() in rand_init)

Closed Beginner friendly
#2,035 1 comment 0 reactions 1 assignee View on GitHub

Maintainers usually reply within 2 days

@coreyjadams is already working on this.

Since Oct 5, 2026.

  • #2048 by @coreyjadams — merged

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in physicsnemo/datapipes/benchmarks/kernels/initialization.py, reading init_uniform_random_4d and init_uniform_random_2d, then inspect how Darcy2D uses the generated coefficients. Run the provided Darcy2D reproducer on CPU and verify the coefficient and permeability-field uniqueness counts. Done means each sample has distinct Fourier coefficients and the expected permeability fields are no longer duplicated.

Written by the indexing model from the issue text.

Description

Version

2.1.1, and current main (eb8f9589)

Describe the bug

init_uniform_random_4d in physicsnemo/datapipes/benchmarks/kernels/initialization.py seeds each thread with

b, i, j, k = wp.tid()
state = wp.rand_init(external_seed, wp.tid())

In a multi-dimensional launch, the bare wp.tid() inside rand_init gives only the first index, b. Every thread of a sample therefore gets the same random state. As a result, all 4 * nr_permeability_freq**2 Fourier coefficients of a sample have the same value. Darcy2D uses this kernel for its permeability, so each sample is built from a single random scalar instead of a random Fourier series. init_uniform_random_2d has the same pattern.

Minimum reproducible example
import numpy as np
from physicsnemo.datapipes.benchmarks.darcy import Darcy2D

np.random.seed(0)
dp = Darcy2D(resolution=32, batch_size=4, nr_permeability_freq=5, max_iterations=2000,
             iterations_per_convergence_check=1000, device="cpu")
fields = []
for _ in range(8):
    dp.initialize_batch()
    f = dp.rand_fourier.numpy()
    print([len(np.unique(f[b])) for b in range(len(f))])   # [1, 1, 1, 1]: one value per sample
    fields += [k.tobytes() for k in dp.permeability.numpy()]
print(len(set(fields)), "distinct permeability fields of", len(fields))  # 8 of 32

Expected: 100 distinct coefficients per sample, and 32 distinct permeability fields.

(Warp 1.16.0, CPU. A plain kernel that writes wp.tid() into a 4-D array also shows the value depends only on b.)

Suggested fix

Give each element its own offset, for example:

b, i, j, k = wp.tid()
offset = ((b * array.shape[1] + i) * array.shape[2] + j) * array.shape[3] + k
state = wp.rand_init(external_seed, offset)

The same applies to init_uniform_random_2d, using i * array.shape[1] + j. I'm happy to open a PR.

Impact

Examples that train on Darcy2D (darcy_fno, darcy_nested_fnos, mhd_pino, darcy_transolver) see a much less varied permeability distribution than the docstring describes. This came up while checking generated operator-learning data against the Darcy equation (with duplicate and outlier checks).

Dominant language
Python
Stars
3.4k
Forks
824
Avg merge
3d 4h
Merged PRs (30d)
70

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/physicsnemo

All issues in NVIDIA/physicsnemo

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.