Skip to content

Commit

Permalink
Adds extra normalization to make np.random.choice happy (#278)
Browse files Browse the repository at this point in the history
* Adds extra normalization to make np.random.choice happy

* updates numba

* updates numba and scipy versions

* Update setup.py

* force 64 bit

* udpate changelog

Co-authored-by: Josh Izaac <josh146@gmail.com>
  • Loading branch information
nquesada and josh146 authored Aug 27, 2021
1 parent 1542332 commit e75ade1
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
- image: circleci/python:3.6.12-stretch
environment:
CIBW_BUILD: 'cp37-* cp38-* cp39-*'
CIBW_ARCHS: 'x86_64'
CIBW_BEFORE_BUILD_LINUX: pip install numpy==1.19.5 scipy cython
CIBW_TEST_REQUIRES: numpy scipy pytest pytest-cov pytest-randomly
CIBW_TEST_COMMAND: python -m pytest --randomly-seed=137 {project}/thewalrus
Expand Down
6 changes: 6 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

### Bug fixes

* Updates the `samples.generate_torontonian_sample` function to ensure probabilities are normalized. [#250](https://github.com/XanaduAI/thewalrus/pull/250)

* Pins Numba to version `<0.54` to avoid binary imcompatibilities with the 1.21 release of NumPy. [#250](https://github.com/XanaduAI/thewalrus/pull/250)

### Breaking changes

### Contributors

This release contains contributions from (in alphabetical order):

Josh Izaac, Nicolas Quesada.

---

# Version 0.16.0
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ environment:
TEST_TIMEOUT: 1000
CIBW_BEFORE_BUILD: pip install numpy==1.19.5 scipy cython
CIBW_BUILD: 'cp37-* cp38-* cp39-*'
CIBW_ARCHS: 'AMD64'
CIBW_TEST_REQUIRES: "numpy scipy pytest pytest-cov pytest-randomly"
CIBW_TEST_COMMAND: "python -m pytest --randomly-seed=137 {project}/thewalrus"
CIBW_BUILD_VERBOSITY: 3
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy>=1.15
numpy>=1.19.2
scipy>=1.2.1
numba>=0.49.1
numba>=0.48.0
pytest>=5.4.1
sympy>=1.5.1
repoze.lru>=0.7
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_version():
"provides": ["thewalrus"],
"install_requires": [
"dask[delayed]",
"numba>=0.49.1",
"numba>=0.49.1,<0.54",
"scipy>=1.2.1",
"sympy>=1.5.1",
"repoze.lru>=0.7",
Expand Down
4 changes: 3 additions & 1 deletion thewalrus/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ def generate_torontonian_sample(cov, mu=None, hbar=2, max_photons=30):

probs = np.real_if_close(probs)
probs = np.maximum(probs, 0)
result = np.random.choice(range(2), p=probs / prev_prob)
local_p = probs / prev_prob
local_p /= np.sum(local_p)
result = np.random.choice(range(2), p=local_p)

results.append(result)
prev_prob = probs[result]
Expand Down

0 comments on commit e75ade1

Please sign in to comment.