Skip to content

Add sobol sampler as well as tests and demonstrating notebook - #325

Open
Samuel-Vangu wants to merge 2 commits into
theochem:masterfrom
Samuel-Vangu:feature/add-sobol-sampler
Open

Add sobol sampler as well as tests and demonstrating notebook#325
Samuel-Vangu wants to merge 2 commits into
theochem:masterfrom
Samuel-Vangu:feature/add-sobol-sampler

Conversation

@Samuel-Vangu

Copy link
Copy Markdown

Adds a Sobol sampling class for integration on (hyper)cubic grids,
following up on the discussion in #322.

What's included

  • src/grid/sobol.py: Sobol(n_points, dimension, seed=None, randomize=True, origin=None, axes=None). Wraps scipy.stats.qmc.Sobol (already a grid
    dependency), generating points via random_base2 for the balance
    properties of the digital-net construction; n_points must therefore be a
    power of 2. randomize=False gives the deterministic, unscrambled
    sequence (whose first point is always the origin); randomize=True
    applies Owen scrambling. Supports mapping onto an arbitrary parallelepiped
    via origin/axes.
  • src/grid/tests/test_sobol.py: tests covering validation, weights, domain
    mapping, integration accuracy, reproducibility, and properties specific to
    Sobol' sequences (origin as first point when unrandomized, the nesting
    property between an N-point and a 2N-point design).
image
  • An example notebook in examples/: compares Sobol against baselines
    already in grid (plain Monte Carlo, Tensor1DGrids/Trapezoidal) on two
    chemistry-motivated integrands -- a product of Gaussian-type functions
    (smooth) and a spherical interaction-cutoff indicator (discontinuous) --
    to show honestly where Sobol's low-discrepancy advantage holds and where
    it doesn't.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Moderate correctness, performance, validation-order, and notebook comparison issues remain unresolved.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds Sobol sampling for equal-weight integration over hypercubes and parallelepipeds.

Changes:

  • Implements and exports the Sobol grid.
  • Adds validation, mapping, integration, and reproducibility tests.
  • Adds a comparative example notebook.
File summaries
File Description
src/grid/sobol.py Implements Sobol sampling and affine domain mapping.
src/grid/tests/test_sobol.py Tests Sobol behavior, mapping, and integration.
src/grid/__init__.py Exports the new Sobol class.
Review details

Suppressed comments (1)

src/grid/tests/test_sobol.py:210

  • The test comment attributes the changed first point to Owen scrambling, but the wrapped SciPy sampler uses LMS+shift. Please keep the behavioral explanation aligned with the actual sampler.
        With randomize=True, Owen scrambling is applied and even the first
  • Files reviewed: 3/4 changed files
  • Comments generated: 6
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread examples/sobol.ipynb
" sobol_err_cut.append(np.mean(trial_sobol_cut))\n",
" mc_err_cut.append(np.mean(trial_mc_cut))\n",
"\n",
" m_tensor = int(round(N ** (1 / DIM)))\n",
Comment thread src/grid/sobol.py
Comment on lines +98 to +99
# Generate Sobol points in the unit cube [0, 1)^d
points_unit = self._generate_sobol_points(n_points, dimension, seed, randomize)
Comment thread src/grid/sobol.py
Comment on lines +121 to +124
points = origin + points_unit @ axes

# Volume of the parallelepiped
volume = np.abs(np.linalg.det(axes))
Comment thread src/grid/sobol.py
Comment on lines +170 to +171
if isinstance(index, int):
return Grid(np.array([self.points[index]]), np.array([self.weights[index]]))
Comment thread examples/sobol.ipynb
"id": "9be9ecff",
"metadata": {},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/theochem/grid/blob/master/examples/Sobol.ipynb)"
Comment thread src/grid/sobol.py
Comment on lines +74 to +76
randomize : bool, optional
If True (default), applies Owen scrambling to the sequence. If
False, generates the unscrambled (deterministic) Sobol' sequence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants