Skip to content

Restore Kronecker discrepancy shapes when replications are omitted - #633

Open
sou-cheng-choi wants to merge 81 commits into
developfrom
issue_629_choi
Open

sou-cheng-choi wants to merge 81 commits into
developfrom
issue_629_choi

Conversation

@sou-cheng-choi

@sou-cheng-choi sou-cheng-choi commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #629. On lattice_kronecker, discrepancy helpers retained a singleton generating-vector axis even when replications=None. The patch removes that axis only for omitted replications and documents the resulting shapes. The regression test checks default and explicit-one-replication behavior against a direct periodic-kernel calculation.

AI Assistance

  • No substantive AI assistance was used for this PR.
  • AI assistance substantively affected this PR, and I describe that use below.

I used my QMCPy Development Copilot to come up with the fix.

  • Independent verification performed: re-ran the issue's exact repro, the full test file, and a boundary check (replications=None vs. replications=1) against the current checkout rather than trusting the issue's or the diff's claims at face value.

Checklist

  • I linked the relevant issue or explained why none was needed. -- Fixes #629 above.
  • I added or updated tests, docs, notebooks, or explained why they were not needed. -- test_kron_disc_wssd extended with shape assertions for both the default and replications=1 cases; two docstrings (periodic_discrepancy, wssd_discrepancy) updated to document both shapes.
  • I verified any equations, citations, benchmarks, numerical claims, or external references changed in this PR. -- the shape/value claims were independently re-derived against _direct_disc's pairwise definition, not just asserted.
  • I reviewed AI-assisted content for licensing, provenance, attribution, confidentiality, and security concerns.
  • I described any CI, dependency, notebook runtime, or generated artifact changes if applicable. -- none; this only changes a return shape and its docstrings/tests.

Anders Pride and others added 30 commits April 22, 2026 01:18
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Anders Pride and others added 15 commits August 31, 2026 21:49
- Kronecker search wssd now works for other kernels, added unit test case
- Lattice search doctest now checks invariant properties
- Lattice.wssd can now handle coord_weights longer than the dimension
- Lattice search minimum n_max value corrected
- Removed user interactive prompt in Kronecker search
- Fixed docstring formatting
- Updated demo notebook with more interesting Kronecker comparison
* Min Python version >= 3.9 for users & >= 3.10 for developers (#606)

* Min Python version

* Pass Python version to environment

* Pre-release tests

* Get more info

* Security Fix

* requires-python = ">= 3.9" in pyproject.toml

* Python 3.9 Compatibility

* Fix versions

* Fix windows test failures

* Installs the missing l3backend MiKTeX package

* Update demo notebook dependencies and initialization cells (#531)

* Update demo notebook initialization cells

* Notebooks have been moved

* Add Colab dependency install cells

* Fix Colab notebook install cells

* Fix spelling in Colab notebooks

* Remove unused os import from Colab cells

* Use capture for Colab install output

* Automating Colab/notebook consistency

* Update

* Update makefile

* Add make target for Colab bootstrap classification

* Debugged `harden_colab_notebook.py` and add unit tests for badge handling

* Add branch notebook execution script

* Skip Colab bootstrap during branch notebook execution

* Download Dakota Genz points in notebook

* Remove Dakota Genz generation fallback

* Use gdown for Dakota Genz data download

* Add local notebook execution script

* Comment out gdown in Dakota notebook

* Fix Windows notebook CI LaTeX setup

* Address Colab readiness review feedback

* Reconcile Colab tooling with develop

* Refresh safe Colab bootstrap cells

* Preserve notebook serialization during hardening

* Better Colab notebook handling:  more dependencies support and improved smoke tests

* Fix CodeQL check errors

* Add title to notebook and update kernel name and version

* Fix errors after manually testing in Google Colab

* Fix problems after manually running in Google Colab

* Minor enhancements

* Fix colab error

* Fix typo

* Simplify Colab smoke tests: drop dead PR scoping, fix diagnostics

* Add harden_colab_notebook to format target

* Add tools to open in Colab (for developers)

* Attempt to fix Colab errors

* Correct Colab notebook manifest and build process

* Fix unit test failure

---------

Co-authored-by: sou-cheng-choi <[email protected]>

* Remove unreferenced file

* Add notebook to documentation

* Remove trailing spaces

* Make LVS deterministic

* Optimized k_const computations. Reduce memory usage. Add custom kernel input to wssd method.

* Resolved  UnboundLocalError when calculating  WSSD for d_max = 1. Improved warning for missing sympy. Better format.

* Add unit tests

* Change ParameterWarngin to UserWarning

* Fix GitHub Action failures

* Another attempt to fix

* make harden_colab_notebook

* Fix windows test failure

---------

Co-authored-by: Joshua Herman <[email protected]>
Resolve notebook, Colab, CI, build, and Kronecker conflicts while preserving generator-search behavior. Align branch tests and API annotations with develop's validation rules.

Validation: 699 unit tests and 275 subtests; focused numerical doctests; Lattice/Kronecker and GBM notebooks; strict Colab and test-style checks; documentation baseline gate; focused MkDocs build.
try:
return _tg_radius_graph(x, r=r, batch=batch, loop=loop)
except (ImportError, AttributeError, RuntimeError, OSError):
_tg_radius_graph_ok = False # backend missing/broken -- use native from now on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this from LDData? If so, we should use our API to fetch it. Otherwise, it should be added to the manifest in pyproject.toml. I'll leave reviews to @fjhickernell and @AndersPride and @algo-hawk.

Copy link
Copy Markdown
Collaborator

Independently re-verified this fix in a scratch worktree against issue_629_choi, using the regression suite from #612/PR #635 (test/test_kronecker.py::TestKroneckerDiscrepancy).

Confirmed:

One remaining failure, test_squared_discrepancy_matches_direct_double_sum, is not caused by this PR — it's my own test's expectation, which happens to hard-code the pre-#612-fix formula's internal structure (evaluating the kernel at raw shifted sample points rather than pairwise differences). It passes on develop today only because both sides of the comparison share the same bug, and it will need to be rewritten once #612's fix lands. Tracking that in PR #635; no action needed here.

Good to merge from my side.

@JiangruiKang JiangruiKang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I verified that the #629 shape regression is fixed, and the focused test file passes (11 tests). I am requesting changes because Lattice.expected_squared_periodic_discrepancies() flattens the replication axis and wssd() silently returns the first generating vector’s result. A two-vector reproduction gives different WSSD values, 0.75099 and 0.72815, while the replicated call returns only 0.75099. Please preserve or explicitly define the replicated result and add a regression test.

lattice_vector_wssd_search() also changes the process-wide NumPy error settings without restoring them. Please use a local error-state context. Finally, please clarify the PR’s broader search-method and MPMC scope; the description currently presents this as only a shape fix. The MPMC fallback also appears to omit PyG’s default 32-neighbor limit, which needs a test or an explanation of the intended change.

This branch has not been deployed

No deployments
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.

Kronecker discrepancy helpers gain an extra leading axis on lattice_kronecker (regression vs develop shape)

8 participants