Skip to content

Lattice kronecker - #556

Open
AndersPride wants to merge 80 commits into
developfrom
lattice_kronecker
Open

AndersPride wants to merge 80 commits into
developfrom
lattice_kronecker

Conversation

@AndersPride

Copy link
Copy Markdown
Collaborator

Adds search methods for generators for lattice and kronecker sequences. Also adds and updates methods for finding discrepancies and weighted sum of squared discrepancies for arbitrary sample size, dimension, and coordinate weights. Currently the search methods live in their respective folders in discrete_distribution, but they may belong elsewhere. There is a new demo illustrating these features. Right now, this is not integrated into the kernel class, but that can be future work.

Anders Pride and others added 30 commits April 22, 2026 01:18
Co-authored-by: Copilot Autofix powered by AI <[email protected]>

@sou-cheng-choi sou-cheng-choi left a comment •

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.

@AndersPride

  1. There is a doc test failure associated with qmcpy.discrete_distribution.lattice.lattice_vector_wssd_search.lattice_vector_wssd_search . Please fix it.

  2. Please merge develop branch into this branch and resolve any conflicts if necessary.

@sou-cheng-choi sou-cheng-choi left a comment •

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.

@AndersPride

I have the following six comments and would appreciate your follow-up.

  1. Help us debug the following case in which computed wssd is negative. Add a fast unit test case after fixing the issue.
    k = lambda x: 3 * (x * (x - 1) + 1 / 6)  
    _, wssd, _, _ = kronecker_vector_search_mobius_transform(8, 3, 3, kernel=k, coord_weights=np.ones(3))    # -1.57909 
  1. The doctest in lines 35 to 36 ofqmcpy/discrete_distribution/lattice/lattice_vector_wssd_search.py failed in my Mac machine, even though it passes in GitHub Actions. The documentation mentions that the results are sensitive to platforms. Could we create doctest that check invariant properties or change the algorithm to a deterministic one?
>>> bernoulli6 = lambda x: x * (x * (-1/2 + x * (x * (5/2 + x * (-3 + x))))) + 1/42
>>> lattice_vector_wssd_search(n_max=2**15, d_max=10, coord_weights=None, 
... kernel=bernoulli6)
array([    1, 15963, 13939,   483, 14713,  6423, 12021,   521,  2283,
        1177])
  1. How to understand the following error?
>>> Lattice(2, randomize=False).wssd(8, sample_weights=np.ones(9))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    Lattice(2, randomize=False).wssd(8, sample_weights=np.ones(9))
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/terrya/Documents/ProgramData/QMCSoftware_local/qmcpy/discrete_distribution/lattice/lattice.py", line 479, in wssd
    wssd = np.dot(sample_weights, discs)
ValueError: shapes (9,) and (8,) not aligned: 9 (dim 0) != 8 (dim 0)
  1. The folloiwng example also failed with an exception. Please debug.
>>> kvs, lvs = kronecker_vector_search_mobius_transform, lattice_vector_wssd_search
>>> lvs(3,3)
/Users/terrya/Documents/ProgramData/QMCSoftware_local/qmcpy/discrete_distribution/lattice/lattice_vector_wssd_search.py:175: RuntimeWarning: invalid value encountered in subtract
  best_indices = np.where(np.abs(wssd - min_wssd) <= rtol * np.abs(min_wssd))[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    lvs(3,3)
    ~~~^^^^^
  File "/Users/terrya/Documents/ProgramData/QMCSoftware_local/qmcpy/discrete_distribution/lattice/lattice_vector_wssd_search.py", line 176, in lattice_vector_wssd_search
    bestIdx = int(best_indices[0])
  1. Please replace the user interactive prompt lines 58 to 63 in qmcpy/discrete_distribution/kronecker/kronecker_search_methods.py with has_sympy = False. The current implementation fails in non-interactive environments (CI/pytest) because the use of input() when sympy is missing causes an EOFError or hangs.

  2. Add an empty line before Args:, Returns:, Note:, etc. in the docstrings in your Python files.

- 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
@AndersPride

AndersPride commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

@sou-cheng-choi
The last commit should address most of your points.

On point 1, there was a single line of code that had not been updated to use a general kernel.

On point 2, I'm still working on improving the stability of the algorithm. For now I've used your suggestion to check easier invariants in the doctest.

On point 3, I have now ensured that the dimensions agree for the dot product

On point 4, that example will still fail, but it throws the proper error as the minimum allowed value of n_max has been corrected.

@sou-cheng-choi

sou-cheng-choi commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

@AndersPride

Thank you for the quick turn around. We should be close to finishing.

I have merged a PR into this branch where I resolved merged conflicts, test failures and address some of the issues more fully. Please review.

sou-cheng-choi

This comment was marked as outdated.

* 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]>
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
@fjhickernell

Copy link
Copy Markdown
Member

@AndersPride, could you please update this branch with your latest work and the current develop branch? Since #616 was merged, please also review those changes and resolve the remaining merge conflicts. Then let us know the current status, including anything still unfinished or needing discussion. When it is ready, please re-request reviews from @alegresor and me.

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.

Copy link
Copy Markdown
Collaborator

Independently re-verified this fixes #612: checked out lattice_kronecker in a scratch worktree and ran the expected-failure regression suite from #612/PR #635 (test/test_kronecker.py::TestKroneckerDiscrepancy) against it.

All 4 tests pinning the NaN / shift-dependence bug now report unexpected success:

  • test_periodic_discrepancy_is_finite_when_shifted
  • test_shifted_squared_discrepancy_matches_pairwise_definition
  • test_squared_discrepancy_is_invariant_to_the_random_shift
  • test_squared_discrepancy_is_nonnegative_when_shifted

No other regressions observed against this branch alone (the separate shape issue in #629 was specific to the state at the time and is being handled in PR #633). Good to merge from my side.

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.

8 participants